• Content count

  • Joined

  • Last visited

Community Reputation

132 Neutral

About armitroner

  • Rank
  1. 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 '[i]C++ Programming for the Absolute Beginner' [/i]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 [i]should [/i]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.
  2. C++ - Is Goto a Good Practice?

    [quote name='rip-off' timestamp='1352715500' post='5000174'] [quote] I only used goto in one small section, since I don't have much need for it elsewhere. [/quote] You are essentially abusing goto to create a loop. Instead, use an explicit loop: [code] ... [/code] 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: [code] ... [/code] 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. [img][/img] Anyhow, thanks for the advice, and I'll be working on improving my code once my compiler gets fixed... [img][/img]
  3. C++ - Is Goto a Good Practice?

    [quote name='TheChubu' timestamp='1352681646' post='5000061'] You could implement your battlemenu separately and make a call to it when you need it instead of using goto. The thing about goto is that you basically get rid of every pre/post condition that a block of code should have. When you have an if else block that, besides having the two normal possible outcomes (if branch or else branch), jumps to another place with a goto in the middle, then nothing is safe anymore. You stomp over every "safety" that basic control structures should give to you when using goto to reach some place in the code. Its like having a carefully designed brake system in a car, only to go and smash it against a wall because you think you can stop the car faster by doing so. [/quote] [quote name='superman3275' timestamp='1352681863' post='5000063'] Goto can also make spaghetti code. A lot of times what ends up happening is that your code is jumping from place to place, making it extremely hard for other people to understand what you're doing. It also makes it hard for you. (Example: Code an awesome enemy system. A month later you need to extend it. Go to look at it and it keeps on jumping to a bunch of places, and you don't understand it, so you scrap all your code.). Now, GoTo isn't always evil. There's an application for everything. However generally using Goto is frowned upon, and the problem you're solving with it can be solved by using object oriented programming. [/quote] 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?
  4. 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 ( < 0 || == 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]
  5. C++ - Is Goto a Good Practice?

    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?
  6. Need C++ Roguelike Tutorial

    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. 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..?
  8. I see. What would be the latest C/C++ equivalent?
  9. 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: [CODE] 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. [/CODE] I'm using the latest Eclipse for Mac OS X. Here's the program's code: [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; } [/CODE]