Bug in my barely-started text-based game program

This is a discussion on Bug in my barely-started text-based game program within the C++ Programming forums, part of the General Programming Boards category; How would I let my program be able to "delete" a character (that is, the save files for your in-game ...

  1. #16
    Registered User
    Join Date
    Aug 2005
    Posts
    91
    How would I let my program be able to "delete" a character (that is, the save files for your in-game player)? Is there a keyword "delete" or something?

  2. #17
    Banned
    Join Date
    Jun 2005
    Posts
    594
    if you have a file that containsa single character and you want to
    remove it, you can either use remove("file path");

    or you can open the file only ios:ut and it will erase the contents
    of the file but keep the actual file.

  3. #18
    Registered User
    Join Date
    Aug 2005
    Posts
    91
    No, I want to actually delete the file itself.

  4. #19
    Registered User
    Join Date
    Aug 2005
    Posts
    91
    Actually, delete("") worked perfectly. Now I have a new, unrelated bug, though... My monst() function (it randomly pulls up a monster and loads the opponent's struct with the enemy info) isn't reloading the enemy stats every time I start a "quick battle". Also, when I run away from a battle (this problem seems to be in battle() ), I still gain exp and money even though I don't want it to. Here are the two functions (and the function that calls them):

    monst()
    Code:
    void monst() {
         int rando = 1+rand()%500;
         if (player.lev >= 1 && player.lev <= 3)
         {
                if (rando <= 50 && rando >= 0)
                {
                        opponent.nam = "Bug";
                        opponent.lev = 1;
                        opponent.att = 3;
                        opponent.def = 2;
                        opponent.agi = 2;
                        opponent.mon = 10;
                        opponent.sta = 10;
                        opponent.exp = 5;
                }
                else if (rando > 50)
                {
                     opponent.nam = "Rabbit";
                     opponent.lev = 1;
                     opponent.att = 3;
                     opponent.def = 3;
                     opponent.agi = 3;
                     opponent.mon = 5;
                     opponent.sta = 15;
                     opponent.exp = 10;
                }
         }
    }
    battle() -- which calls monst()
    Code:
    void battle() {
         string sel;
         
         monst();
         while (player.tempsta > 0 || opponent.sta > 0)
         {
               cout << player.nam << ": Level " << player.lev << "; Stamina: " << player.tempsta << endl;
               cout << opponent.nam << ": Level " << opponent.lev << "; Stamina: " << opponent.sta << endl << endl;
               cout << "Attack (press a)\n";
               cout << "Defend (press d)\n";
               cout << "Run (press r)\n\n";
               cin >> sel;
               if (sel == "a" || sel == "A")
               {
                       attack();
                       if (opponent.sta < 1)
                       {
                               break;
                       }
                       else if (player.tempsta < 1)
                       {
                            break;
                       }
                       else if (player.tempsta > 0 && opponent.sta > 0)
                       {
                       }
                       else
                       {
                            cout << "Error\n\n";
                            break;
                       }
               }
               else if (sel == "d" || sel == "D")
               {
                    defend();
                    if (opponent.sta < 1)
                    {
                            break;
                    }
                    else if (player.tempsta < 1)
                    {
                         break;
                    }
                    else if (player.tempsta > 0 && opponent.sta > 0)
                    {
                    }
                    else
                    {
                        cout << "Error\n\n";
                        break;
                    }
               }
               else if (sel == "r" || sel == "R")
               {
               break;
               }
               else
               {
                   cout << "Error\n\n";
                   break;
               }
         }
         if (player.tempsta > 0 && opponent.sta <= 0)
         {
                 player.exp += opponent.exp;
                 player.mon += opponent.mon;
                 player.tempsta = player.sta;
                 cout << "You gained " << opponent.mon << " money and " << opponent.exp << " experience points.\n";
                 exp();
         }
         else if (player.tempsta <=0 && opponent.sta > 0)
         {
              cout << "You lost the battle!\n";
         }
         else if (player.tempsta > 0 && opponent.sta > 0)
         {
              cout << "You escaped from the enemy.\n";
         }
    }
    gamemenu() -- which calls battle()
    Code:
    void gamemenu() {
         string opti;
    
         while (opti != "e" || opti != "E")
         {
               cout << "Story Mode (press s)\nQuick Battle (press q)\nCharacter Info (press i)\nExit (press e)\n";
               cin.ignore(100,'\n');
               cin >> opti;
               if (opti == "i" || opti == "I")
               {
                        cout << "\nName: " << player.nam << "\nLevel: " << player.lev << "\nAttack: ";
                        cout << player.att << "\nDefense: " << player.def << "\nAgility: ";
                        cout << player.agi << "\nStamina: " << player.sta << "\nMoney: ";
                        cout << player.mon << "\nExperience: " << player.exp << "\n\n";
               }
               else if (opti == "q" || opti == "Q")
               {
                    cout << endl;
                    battle();
                    cout << endl;
               }
               else if (opti == "e" || opti == "E")
               {
                    cout << endl;
                    break;
               }
               else if (opti == "s" || opti == "S")
               {
                    game();
               }
         }
    }
    EDIT: Oh, I forgot to post the struct containing the "player." and "opponent." variables. Here it is:

    Code:
    struct statistics {
           string nam; //Name
           int lev; //Level
           int att; //Attack
           int def; //Defense
           int tempdef; //To heighten defense for a turn.
           int agi; //Agility (not currrently used in the program)
           int mon; //Money
           int sta; //Stamina
           int tempsta; //To keep track of player health while regenerating it after battle.
           float gloc; //To keep track of your location in Story Mode.
           float exp; //Experience (for leveling up, not currently used)
    };
    Last edited by linkofazeroth; 08-30-2005 at 02:35 AM.

Page 2 of 2 FirstFirst 12
Popular pages Recent additions subscribe to a feed

Similar Threads

  1. Replies: 19
    Last Post: 05-30-2007, 06:47 PM
  2. PC Game project requires c++ programmers
    By drallstars in forum Projects and Job Recruitment
    Replies: 2
    Last Post: 02-22-2006, 12:23 AM
  3. making a text based game
    By MisterSako in forum C++ Programming
    Replies: 1
    Last Post: 12-05-2004, 01:20 PM
  4. Creating Shell based game..Few questions
    By Saintdog in forum Game Programming
    Replies: 1
    Last Post: 12-01-2004, 08:14 PM
  5. My Memory Game
    By jazy921 in forum C Programming
    Replies: 0
    Last Post: 05-05-2003, 06:13 PM

1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21