Thread: what do you think of my game?

  1. #1
    Registered User
    Join Date
    Mar 2012

    what do you think of my game?

    Hello, I have just made my first game in C++ it is text based please tell me what you think.Also please note that it is not finished.

    #include <iostream>
    #include <cstdlib>
    #include <time.h>
    using namespace std;
    int main()
        //charicter variables
        string action;
        int lose;
        int battle;
        int player_health;
        int player_attack;
        int Player_weapon;
        int monster_attack;
        int monster_health;
        //variables for random number limit
        int player_attack_low;
        int player_attack_high;
        int monster_attack_low;
        int monster_attack_high;
        //item variables
        string item_use;
        //iventory variables
        int potion_health_ammount;
        int potion_poison_ammount;
        Player_weapon= 1;
        battle = 1;
        lose = 0;
        potion_health_ammount = 1;
        potion_poison_ammount = 1;
        //code for random numbers used for attack
        time_t seconds;
        srand((unsigned int) seconds);
        cout<<"round one! player V zombie \n";
        //setting attck limit variables
        if(Player_weapon = 1){ //fist
        player_attack_low = 0;
        player_attack_high = 3;
        else if(Player_weapon = 2){ //sword
        player_attack_low = 6;
        player_attack_high = 8;
        else if(Player_weapon = 3){ //axe
        player_attack_low = 0;
        player_attack_high = 11;
        monster_attack_low = 0;
        monster_attack_high = 2;
        player_health = 20;
        monster_health = 15;
        cout<<"your health is "<<player_health<<"\n";
        cout<<"the zombies health is "<<monster_health<<"\n";
        while(battle == 1){
        cout<<"\n\n\nattack, item or pass? \n";
          if(action == "attack"){
              player_attack = rand() % (player_attack_high - player_attack_low + 1) + player_attack_low;
              monster_health = monster_health - player_attack;
              cout<<"you do "<<player_attack<<" damage.\nThe zombie's health is "<<monster_health<<"\n";
              monster_attack = rand() % (monster_attack_high - monster_attack_low + 1) + monster_attack_low;
              player_health = player_health - monster_attack;
              cout<<"\nyou take "<<monster_attack<<" damage \nYour health is now "<<player_health;
          if(player_health < 1){
          cout<<"you lose";
          else if(monster_health < 1){
          cout<<"\n\n\nyou won this round well done!";
          battle = 0;
          cout<<"\n\n next turn \n\n";
        else if(action == "pass"){
                      monster_attack = rand() % (monster_attack_high - monster_attack_low + 1) + monster_attack_low;
              player_health = player_health - monster_attack;
              cout<<"\nyou take "<<monster_attack<<" damage \nYour health is now "<<player_health;
        else if(action == "item"){
        cout<<"you have\n"<<potion_health_ammount<<" healing potion(potion)\n"<<potion_poison_ammount<<" posion(poison)\n\n";
        cout<<"item to use: ";
        if(item_use == "potion"){
        player_health = player_health + 5;
        cout<<"you have healed by 5\n";
        else if(item_use == "poison"){
        monster_health = monster_health - 5;
        cout<<"5 damage given to zombie\n";
        monster_attack = rand() % (monster_attack_high - monster_attack_low + 1) + monster_attack_low;
        player_health = player_health - monster_attack;
        cout<<"\nyou take "<<monster_attack<<" damage \nYour health is now "<<player_health;
        return 0;

  2. #2
    and the hat of int overfl Salem's Avatar
    Join Date
    Aug 2001
    The edge of the known universe
    > if(Player_weapon = 1)
    You're probably wanting to use == here.

    Your indentation could be a lot better. Indentation - cpwiki
    If you dance barefoot on the broken glass of undefined behaviour, you've got to expect the occasional cut.
    If at first you don't succeed, try writing your phone number on the exam paper.

  3. #3
    Registered User
    Join Date
    Dec 2011
    Don't use magic numbers. If you're needing to compare against a constant, and add a comment to clarify, you definitely need a #define in there.

    There's a lot of stuff that can be shortened, for example:
    could replace the three lines you have.

    Not sure about C++, but in C you can't compare strings with ==.

  4. #4
    Programming Wraith GReaper's Avatar
    Join Date
    Apr 2009
    Quote Originally Posted by memcpy View Post
    Not sure about C++, but in C you can't compare strings with ==.
    Firstly, does this look like C?!

    Secondly, of course you can, if one of the operands is a std::string ( speaking about C++, of course ):
    string action;
    Devoted my life to programming...

  5. #5
    C++ Enthusiast M.Richard Tober's Avatar
    Join Date
    May 2011
    Hi Aaron and welcome to's Game Area! It looks like you've decided to program games in C++! Excellent!

    - Get in the habit of using the string type from the <string> library
    and use <ctime> instead of <time.h> (C++'s "namespace" friendly versions of standard libraries)

    - After fixing the =/== problems in the comparisons at Line 47, 52, and 57 - and running Code::blocks Astyle addon to knock some of the formatting into shape - it ran very nicely!

    On the up side, the fault tolerance was high! I threw decimals and misspelled words at the prompt and it handled everything fine. On the downside, there's not "quit" option to end a game early, and typing full words for responses seemed tedious. Let me suggest a clear menu with single letter choices:

    Keep up the good effort and you'll be producing what do you think of my game?-azb-gif 2.0 in no time!

    Font generated at:
    Cool Text: Logo and Graphics Generator
    Last edited by M.Richard Tober; 03-28-2012 at 06:24 AM. Reason: Giving credit where credit is due.
    Eventually, I decided that thinking was not getting me very far and it was time to try building.
    Rob Pike, "The Text Editor sam"

  6. #6
    Registered User
    Join Date
    Mar 2012
    thanks for the feed back i have notced a few flaws my self including you have unlimited potions potion_....._ammount just gose into the minuses, lol XD

    As soon as I get the next working version I will post it in the post your game here thread.
    Last edited by Aaron Hance; 03-28-2012 at 08:44 AM.

  7. #7
    Registered User ~Kyo~'s Avatar
    Join Date
    Jun 2004
    I remember writing a game very similar to this back in the day I made players fight my professors, but only the ones I liked that said crazy things to put in the pre combat dialogues.

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. Replies: 5
    Last Post: 05-18-2010, 09:42 PM
  2. Should I use a game engine in making a RPG game?
    By m3rk in forum Game Programming
    Replies: 6
    Last Post: 01-26-2009, 04:58 AM
  3. Guessing game: how to quit the game?
    By hzr in forum C Programming
    Replies: 5
    Last Post: 12-18-2008, 10:53 AM
  4. craps game & dice game..
    By cgurl05 in forum C Programming
    Replies: 3
    Last Post: 03-25-2006, 07:58 PM
  5. Game Designer vs Game Programmer
    By the dead tree in forum Game Programming
    Replies: 8
    Last Post: 04-28-2005, 09:17 PM