Hello Guest, please login or register.
Did you miss your activation email?
Login with username, password and session length.

Pages: [1]   Go Down

Author Topic: A very basic console RPG battle Version 1 beta source code...exe in first post  (Read 873 times)

0 Members and 1 Guest are viewing this topic.
A very basic console RPG battle Version 1 beta s...
« on: March 18, 2008, 05:05:51 am »
  • *
  • Reputation: +12/-2
  • Offline Offline
  • Gender: Male
  • Posts: 4849
Code: [Select]
#include <cstdlib>
#include <iostream>
#include <ctime>

using namespace std;

int main(int argc, char *argv[])
{
    //The following are the variables for the player and monster stats
    int playerhealth = 100;
    int monsterhealth = 30;
    int playerattack = 16;
    int playerdefense = 13;
    int monsterattack = 8;
    int monsterdefense = 11;
    int randomNumber = rand(); //generates random number
    int die;
   
   
    //The variable for the player's choice
    int playerchoice;
   
    cout << "During your travels, you have been attacked by a monster." << endl;
   
    do
    {
         cout << "What will you do?" << endl;
         cout << "1. Attack" << endl;
         cout << "2. Defend" << endl;
         cin >> playerchoice;//Grabs the user's choice to attack or defend
         
         if (playerchoice = 1)
         {
            cout << "You lunge at the monster with your sword!" << endl;
            //Random die role to add to player attack
            die = (randomNumber % 6) + 1 ;
            //Display the attack so the user knows how much damage they caused
            cout << "You have done " << (die + playerattack) - monsterdefense << " damage to the monster!" << endl;
            monsterhealth = (monsterhealth - (die + playerattack));//Reset the monster after the attack
            if (monsterhealth > 0)
            {
                cout << "The monster attacks you!" << endl;
                die = (randomNumber % 6) + 1 ;
                if ( ((die + monsterattack) - playerdefense) > 0 )
                {
                     cout << "The monster caused " << ( (die + monsterattack) - playerdefense)
                     << " damage against you!" << endl;
                     playerhealth = playerhealth - ( (die + monsterhealth) - playerdefense);
                     cout << "You know have " << playerhealth << "HP..." << endl;
                     }
                else if ( ( (die + monsterattack) - playerdefense) <= 0 )
                {
                     cout << "The monster failed to cause you any harm with his attack!" << endl;
                     }
             }
Basically, it just contains what happens when the player attacks.  This code is unfinished.
I just want to make sure that I don't have any mistakes or am doing any bad habits.
I am relearning c++ and I wanted to give myself a challenge seeing as no one else has...lol


Left to finish:
What happens if the player chooses to defend rather than attack.
Finish the Do {} While ()  [I haven't done the While part yet].


Things to add later:
Maximum player and monster health.
Add items.
Add spells.
Add the ability to run away for both player and monster.
Add experience and leveling system.
Have more than one monster.
Implement this with my text adventure I once programmed to have a "random battle" effect.


EDIT:Damnit, there is already a problem....It lies in the randomNumber...!@#$%...

SECOND EDIT:Error fixed
« Last Edit: March 19, 2008, 01:35:58 am by Theforeshadower »
Logged
  • Super Fan Gamers!
Re: A very basic console RPG battle(WIP)
« Reply #1 on: March 19, 2008, 01:32:50 am »
  • *
  • Reputation: +12/-2
  • Offline Offline
  • Gender: Male
  • Posts: 4849
Code: [Select]
#include <cstdlib>
#include <iostream>
#include <ctime>

using namespace std;

int main(int argc, char *argv[])
{
    //The following are the variables for the player and monster stats
    int playerhealth = 100;
    int monsterhealth = 30;
    int playerattack = 16;
    int playerdefense = 13;
    int monsterattack = 8;
    int monsterdefense = 11;
    int randomNumber = rand();//generate random number
    int die;
   
   
    //The variable for the player's choice
    int playerchoice;
   
    cout << "During your travels, you have been attacked by a monster." << endl;
   
    do
    {
         cout << "What will you do?" << endl;
         cout << "1. Attack" << endl;
         cout << "2. Defend" << endl;
         cin >> playerchoice;//Grabs the user's choice to attack or defend
         randomNumber = rand();//regenerate a random number each time.
         
         if (playerchoice = 1)
         {
            cout << "You lunge at the monster with your sword!" << endl;
            //Random die role to add to player attack
            die = (randomNumber % 6) + 1 ;
            //Display the attack so the user knows how much damage they caused
            cout << "You have done " << (die + playerattack) - monsterdefense << " damage to the monster!" << endl;
            monsterhealth = (monsterhealth - (die + playerattack));//Reset the monster after the attack
            system("PAUSE");
           
            if (monsterhealth > 0)
            {
                cout << "The monster attacks you!" << endl;
                die = (randomNumber % 6) + 1 ;
                if ( ((die + monsterattack) - playerdefense) > 0 )
                {
                     cout << "The monster caused " << ( (die + monsterattack) - playerdefense)
                     << " damage against you!" << endl;
                     playerhealth = playerhealth - ( (die + monsterhealth) - playerdefense);
                     cout << "You know have " << playerhealth << "HP..." << endl;
                     }
                else if ( ( (die + monsterattack) - playerdefense) <= 0 )
                {
                     cout << "The monster failed to cause you any harm with his attack!" << endl;
                     }
             }
             
             }
         if (playerchoice = 2)
         {
              cout << "You choose to defend the attack!" << endl;                     
              cout << "The monster attacks you!" << endl;
                die = (randomNumber % 6) + 1 ;
                if ( ((die + monsterattack) - (playerdefense + 3) ) > 0 )
                {
                     cout << "The monster caused " << ( (die + monsterattack) - playerdefense)
                     << " damage against you!" << endl;
                     playerhealth = playerhealth - ( (die + monsterhealth) - playerdefense);
                     cout << "You know have " << playerhealth << "HP..." << endl;
                     }
                else if ( ( (die + monsterattack) - (playerdefense + 3) ) <= 0 )
                {
                     cout << "The monster failed to cause you any harm with his attack!" << endl;
                     }
         }
         
    }//end of the do
        while ( monsterhealth > 0 );
        cout << "You have vanquished the monster!" << endl;
        cout << "This ends the basic rpg console battle..." << endl;                   
                                       
   
    system("PAUSE");
    return EXIT_SUCCESS;
}
Version 1 beta... very buggy.
I would appreciate it if someone could help me figure out these bugs of skipping your turn and forcing you to defend on second turn and negating the monster's attack for the second round.
Logged
  • Super Fan Gamers!
Pages: [1]   Go Up

 


Contact Us | Legal | Advertise Here
2013 © ZFGC, All Rights Reserved



Page created in 0.171 seconds with 41 queries.