Jump to content
  • Advertisement


  • Content Count

  • Joined

  • Last visited

Community Reputation

100 Neutral

About 3lement

  • Rank
  1. A whole lot of very informative methods in here. Thank you all very much, I'm currently having a lot of fun trudging through it all with reference material side-by-side.
  2. Thanks for the quick reply, but I still have a number of questions: - By #defining outside of local scope, won't that change all instances of the aforementioned int values regardless of whether I loaded the game or not? - How can you define int names to an array? As far as I know, you can only do something like array[ ] = {1, 2, 3}, which won't work if you use named values instead. - How does one save/load the values of the array one by one, as opposed to saving to the whole array at once? This is probably the most mind-boggling problem I've encountered thus far. Your help is very much appreciated.
  3. [color=#1C2837][size=2]Im still not very clear on what the different numbers youre reading in are supposed to mean [/quote] Basically, I'm going to have a header file where I store int definitions, such as HavePickaxe. If HavePickaxe = 1, line 1 of the .txt file will be "1", meaning the player currently owns the Pickaxe item. If the player does not have it, it will of course be 0. This way, when they player's going along in his adventure and comes across a Pickaxe, my game will make HavePickaxe = 1, which will then be written to line 1 of the .txt file. This file can be written (Save) or read (Load), and by using #define I can change values such as Gold to P1Gold and go from there. The values in the current .txt are just placeholders to see if I can assign (and read) 6 values to the array. If it helps, just ignore the code I have above. It's very patchwork; I'd be willing to scrap it if I can find a more efficient way of doing what I've just explained.
  4. Hey all, Progress is coming along on my game. I'm currently trying to work out how to save/load files using fstream. The idea is pretty self-explanatory; store values for whether gear exists or not in the player's inventory, and give the player the ability to save these values to a profile, or load them from a different profile. Here's what I have so far (pieced together from various tutorials online): int DoLoad() { ifstream Profile1; Profile1.open("Profile1F.txt"); string Profile1V[6]; while (!Profile1.eof()) { Profile1 >> Profile1V[5]; } cout<<Profile1V[5]; Profile1.close(); return 0; } And the contents of my Profile1F.txt file: 5 6 7 8 9 0 I don't understand arrays very well, so this is probably a bad method to be using. The cout is only to test whether my values were stored; what I'd like is to take the values from each individual line and store it into a new int. For example, if line 1 == '1', then HavePickaxe = 1. I think this would be a fairly effective patchwork save/load system. I'm not concerned with security measures; if someone really wants to cheat at my game by modifying the .txt file, let them. This is more for the learning experience. So, almighty devs, how would one go about accomplishing the text -> integer conversion? *disclaimer: As of yet, cout will only produce the value of '0'. I managed to get it to output 567890 with a couple changes, but I still have no way of separating those numbers and storing each individual one in an int.
  5. Works perfectly... live and learn. By the by, is it bothersome that I keep posting in the same thread? I figure it'd be bad etiquette to make a new one for every little problem I run into. Thanks again for being so helpful, guys. I definitely feel the love.
  6. Hello again, O masters of all things code-y. Ran into another problem. I've essentially got my menu system up and running, with a slight error. My program will take input from the user, convert the input to a number which is then assigned to a Menu integer. The Menu header reads this integer, and writes the menu to the screen when called. However, for some reason, the menu is stuck on "Command List". I've tried switching the sent integer value to Menu = 7; and doing MenuDisplay(Menu), but that doesn't seem to work either. commands.h: void CmdSel() { if (Command=="M"||Command=="m") Menu = 0; else if (Command=="N"||Command=="n") Menu = 1; else if (Command=="L"||Command=="l") Menu = 2; else if (Command=="C"||Command=="c") Menu = 3; else if (Command=="/i") Menu = 7; else if (Command=="/c") Menu = 8; else { sType("\tInvalid key selection. Please choose again.\n"); CmdPrompt(); } switch(Menu){ case 0: Splash(); break; case 1: Beginning(); break; case 2: LoadGame(); break; case 3: Credits(); break; case 7: Inventory(); case 8: CmdMenu(); break; } _getch(); } void CmdPrompt() { cout << "\tFor help with commands, type /c" << endl; sType("\n\t> "); cin >> Command; CmdSel(); } void CmdMenu() { MenuDisplay(8); sType("\n\t\t(M)\t\t\tMain Menu"); sType("\n\n\t\t(/c)\t\t\tCommand List"); sType("\n\n\t\t(/r)\t\t\tResource Menu"); sType("\n\n\t\t(/i)\t\t\tInventory Menu"); sType("\n\n\t\t(/b)\t\t\tBuilding Menu"); sType("\n\n\t\t(/m)\t\t\tMining Actions"); sType("\n\n\t\t(N)\t\t\tNew Game (Main Menu only)"); sType("\n\n\t\t(L)\t\t\tLoad Game"); sType("\n\n\t\t(S)\t\t\tSave Game"); cout << "\n\t-------------------------------------------------------" << endl; sType("\n\t Please select a command:"); sType("\n\t> "); cin >> Command; CmdSel(); } the MenuDisplay() function: string MenuHead; void MenuDisplay(int Menu) { switch(Menu) { case 1: MenuHead = "Menu - New Game"; case 7: MenuHead = "Menu - Inventory"; case 8: MenuHead = "Menu - Command list"; } system("cls"); cout << "\n\t " << MenuHead << endl; cout << "\t-------------------------------------------------------" << endl; } And finally, the call to menu printing function: void Inventory() { MenuDisplay(7); sType("\n\n\t\tPickaxe:\t\t[") ; if (HavePickaxe==1) sType("x]"); else sType(" ]"); _getch(); } So, as mentioned above, when the user gets to the Splash() page, they can input "/i" to access the Inventory screen. The command does indeed lead to the right screen, but the menu Header is stuck on "Menu - Command List". Any idea why this is happening?
  7. I seem to have a big problem with operators, huh? Thanks for the quick response, it's always frustrating to struggle with something for a whole day and find out it has such a simple solution.
  8. Much obliged, I actually have something similar running now. Another update: work is coming along splendidly, and my interest/motivation for completing this project are quite high. I'm currently stuck on this problem however: I'm trying to pass the value of the int Profile to the function NewGame(). The idea is that while Profile = 0 (new savegame), the NewGame() function will open up a Savegame menu, and as soon as it's done, will return a value of Profile = 1, allowing the function to progress. void Intro() { int Profile; Profile = 0; system("cls"); cout << "\n\t\t\t\t\t\t"; Sleep(3500); sType("...Where the fuck am I?"); Sleep(5000); system("cls"); cout << "\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\t"; sType("Does it really matter?"); Sleep(3500); sType("\n\n\tThis place can be whatever you want it to be."); Sleep(6000); system("cls"); cout << "\n\n\n\n\n\n\n\n\n\n\t\t\t\t"; Sleep(3500); Gears(); NewGame(Profile); } void NewGame(int Profile) { while (Profile = 0) { void NewSaveScreen(); NewSaveScreen(); } system("cls"); cout << "\n\n\t"; Sleep(3500); sType("> Welcome to Gears. Would you like to read the tutorial?"); cin >> TutReq; if (TutReq=="Y"||TutReq=="y") { Tutorial(); } else Beginning(); } You might see something I don't here; for some reason, the program will jump over the "while" statement (tried using if/else as well) and go straight to system("cls") in the NewGame() function. I tried using cout to determine the value of Profile both before and after being passed off from the first function to the second, and both values are 0 as they should be. Any ideas?
  9. Heh, the devil's in the details. Thanks again for your help.
  10. Hi guys, quick bump on this, here's the code for my main menu, with custom commands: commands.h #include "stdafx.h" #include <string> #include "statUI.h" string Command; void CmdPrompt(); void NewGame(); void Credits(); int Menu; void CmdPrompt() { if (Command=="/r") Menu = 0; if (Command=="N"||"n") Menu = 1; if (Command=="C"||"c") Menu = 3; switch(Menu){ case 0: statUI(); break; case 1: NewGame(); break; case 3: Credits(); break; } _getch(); } And here are the contents of StatUI, #included above: #include <iostream> #include <conio.h> using namespace std; int Gold; void statUI() { system("cls"); cout << "\n\tGold: " << Gold << "\t\t\t\t\tWinter, Year 1" << endl; cout << "\t-------------------------------------------------------" << endl; _getch(); } And finally, the main .cpp file with all the #includes: // builder.cpp : Defines the entry point for the console application. // #include "stdafx.h" #include "commands.h" #include <dos.h> #include <stdio.h> #include <conio.h> #include <cstdlib> #include <iostream> #include <string> #include <Windows.h> #include "sType.h" #include "intro.h" #include "NewGame.h" #include "Credits.h" void Splash(); int main() { Splash(); _getch(); return 0; } I know the code is messy, I'm sorry. It's basically all patchwork. I'm more concerned with actually building something, and figuring it out as I go. So the problem here is, when I run the program, everything launches fine, except no matter what I choose, it always executes the Credits(); function. This happened after implementing the switch(Main) function in commands.h. Previously, I had been using an if/else statement, but it also had the problem of only executing the NewGame(); function. Any assistance would be greatly appreciated.
  11. Ahh, that must be the 'thinking outside the box' people keep raving on and on about. Worked perfectly with a forward declaration. Thanks so very much. And if it's alright with your community, I might periodically show the work on my game for suggestions on optimization. ^^
  12. Hi everyone, first time poster here. Just wanted to say that it seems like you have a great community going here. I'm a complete rookie in C++, and I've been trying to find some good tutorials to practice with. So far, I'm in way over my head, but day by day it gets less confusing, and that's a good thing. I decided, though, that the best way to go about learning is to try my hand at making a text-based game from scratch, using only reference sites. I recently stumbled across this forum post describing how to print out a string, character by character, using iterators. Full disclosure: I haven't reached iterators in my tutorials yet. Code follows: // builder.cpp : Defines the entry point for the console application. // #include "stdafx.h" #include <cstdlib> #include <iostream> #include <string> #include <windows.h> int main() { typedef std::string::const_iterator iter; std::string msg ( "This is a message" ); iter begin = msg.begin(); iter end = msg.end(); for ( iter it = begin; it != end; ++it ) { std::cout.put ( *it ); Sleep (75); } std::cout<<std::endl; } This is perfect. Exactly the right speed, exactly what I wanted it to do. The only problem is that it uses a static value for the string ("This is a message"), whereas I'd like my entire (text-based) game to be displayed with this scrolling effect. The idea is that I include the above code in a separate header file, and call to the function whenever text needs to be displayed, thereby creating the desired effect for all the text in the game (except menus, which will have their own header file). I'm having a really hard time trying to convert the function from static input to dynamic input; any ideas how I might get this done? Thanks in advance for the patience, I still don't quite know my elbow from my ass.
  • Advertisement

Important Information

By using GameDev.net, you agree to our community Guidelines, Terms of Use, and Privacy Policy.

GameDev.net is your game development community. Create an account for your GameDev Portfolio and participate in the largest developer community in the games industry.

Sign me up!