Jump to content
  • Advertisement

armitroner

Member
  • Content Count

    9
  • Joined

  • Last visited

Everything posted by armitroner

  1. I've made a simple little text-based game that implements an extremely primitive menu. For it, I have designed a small option menu for attacks. Before, it used to automatically move on to the opponent's attack if you happened to use the gun attack if you were out of ammo, so I fixed that by adding a goto function that reverts back to the option menu before the enemy initiates it's attack. I've read in some places that goto is unreliable, and indeed, shouldn't be used in most cases. I was just curious as to specifically why this is, and what alternative could I use?
  2. armitroner

    beginning C++ game programming

    IMHO, beginning with getting a firm grasp of the basics of C will help you in the long run when delving into C++. As for where to begin learning C++, I think that it's best to go for just a general knowledge of C++, then going to a specific area of programming style, such as game programming. If you want a mixture of good knowledge of C++ as well as the basics for game programming, I'd recommend the book 'C++ Programming for the Absolute Beginner' by Mark Lee. It teaches you how C++ works just like a normal book would, but using game analogies and examples to teach you, so it's like hitting two birds with one stone. However, it still stands that you should learn some C before C++. I started off messing around with C, in which I developed my first text-based game (which I got rid of last year). After that, I read the aforementioned book, and used the net to learn C++, and I'm in the process of making another text-based (soon to be 2D grapical! ) game. But still, you should just do what suits you best. All we can offer are pointers and advice.
  3. armitroner

    C++ - Is Goto a Good Practice?

    You are essentially abusing goto to create a loop. Instead, use an explicit loop: ... Note that this automatically handles the case where the user types an invalid option by looping around, though it is generally nicer to print a specific message in this case. Another potential improvement is to dynamically remove invalid options from the menu. Something like this: ... I'm not sure if you are familiar with std::vector or function pointers. Feel free to ask a question if you don't understand what this code is doing. [/quote] From what I can see in the second example, it's working sort of like an array. It appears to be creating a single, erm, (for lack of a better term) method that carries the other functions in it, kinda like how a class works? Then it grabs how many functions are underneath CombatChoice and displays them, dependent upon wether or not they meet the conditions given when using the push_back function. (not sure what push_back is) Finally, when choosing the option, the reason you created that variable when creating the menu was to add an extra bumper in case the player chose the number of an option that wasn't even there. I'll do a bit of reading on std::vector, since this is the first time I've come across the term. This was actually my first serious C++ project, so I had to hunt down tons of stuff on the net. Anyhow, thanks for the advice, and I'll be working on improving my code once my compiler gets fixed...
  4. armitroner

    C++ - Is Goto a Good Practice?

    I see. So basically, goto is really only a last-ditch alternative for when you don't need to go back and extend it all that much. The better thing to do would be to create a separate class specifically for the battle menu? Crap, another class I have to make... Anyhow, thanks! I'll see how I can change it to a class, though I'm still not entirely sure how to split all the options into a class, so maybe I could get a couple pointers here?
  5. armitroner

    C++ - Is Goto a Good Practice?

    Oh, yeah, sorry! I only used goto in one small section, since I don't have much need for it elsewhere. [source lang="cpp"]void Combat::combatChoice(Character& C) { if (C.health < 0 || C.health == 0) { cout << "----------------- You died... ------------------" << endl; cout << "Oh dear, it seems you have died... Game Over." << endl; } else { battlemenu: cout << "----------------- Battle Options ------------------" << endl; C.Display(); cout << "What do you want to do? \n" << "Type the number of the action and press enter. \n" << "[1] Melee Attack \n" << "[2] Gun Attack \n" << "[3] Health Potion" << endl; short choice; cin >> choice; switch (choice) { case 1: cout << "\n----------------- Battle Results ------------------" << endl; C.meleeAttack(M); break; case 2: cout << "\n----------------- Battle Results ------------------" << endl; if(C.ammo == 0) { cout << "You're out of ammo! \n" << endl; goto battlemenu; } else { C.gunAttack(M); } break; case 3: cout << "\n----------------- Battle Results ------------------" << endl; if(C.potions == 0) { cout << "You're out of potions! \n" << endl; goto battlemenu; } else { C.useHP(C); } break; } } }[/source]
  6. Despite my hunting the internets, my bounty hunter visor fails to locate any C++ tutorials for simple roguelikes. Can anyone point me to a good roguelike tutorial for C++? Thanks!
  7. I was starting on programming my first game ever, a roguelike. I typed out the bare essentials, and I even have the help of a small tutorial, but when I tried to compile this, it gave errors such as: Symbol 'console' could not be resolved. Symbol 'true' could not be resolved. Method 'Clear' could not be resolved. Method 'Position' could not be resolved. Program 'make' is not found in PATH. I'm using the latest Eclipse for Mac OS X. Here's the program's code: #include <conio.h> #include "Console.h" int main( void ) { console.Clear(); int nPlayerX=40, nPlayerY=12; while( true ) { //Output phase console.Position( nPlayerX, nPlayerY ); console << '@'; //Input phase char nKey = getch(); //Processing phase switch( nKey ) { //Move down case 's': nPlayerY++; break; //Move left case 'a': nPlayerX--; break; //Move right case 'd': nPlayerX++; break; //Move up case "w": nPlayerY--; break; //Quit case 'q': return 0; break; } } return 0; }
  8. Thanks! I'll be researching ncurses and fixing my code. Rep for you! Edit: Quick thing more... how do I fix my code for ncurses..?
  9. I see. What would be the latest C/C++ equivalent?
  • Advertisement
×

Important Information

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

We are the game development community.

Whether you are an indie, hobbyist, AAA developer, or just trying to learn, GameDev.net is the place for you to learn, share, and connect with the games industry. Learn more About Us or sign up!

Sign me up!