Turn based battle demo

This is a discussion on Turn based battle demo within the Game Programming forums, part of the General Programming Boards category; Code: #include <conio.h> #include <iostream> #include <stdlib.h> #include <ctime> int RandInt(int a,int b) { return a + rand() % (b ...

  1. #1
    Registered User Kirdra's Avatar
    Join Date
    Aug 2002
    Posts
    105

    Turn based battle demo

    Code:
    #include <conio.h>
    #include <iostream>
    #include <stdlib.h>
    #include <ctime> 
    
        int RandInt(int a,int b)            
    {
       return a + rand() % (b - a + 1);
    }
    
    int User_Health = 400, User_Max_Health = 400, User_Level = 1, User_Potions = 10;
    int User_Weapon = 1, User_Exp = 0, Next_Level = 300, User_Gold = 0, User_Attack;
    
        
        int Q = 0;
        int USE_POTION;
        
        int Imp_Health = 200, Imp_Max_Health = 200, Imp_Gold = 60;
        int Imp_Exp = 60;
    int main()
    
    {   
    do 
    {
    system("cls");
    if(User_Exp >= Next_Level)
    {
    Next_Level = Next_Level * 2;
    User_Max_Health = User_Max_Health + 20;
    User_Level = User_Level++;
    User_Health = User_Max_Health;
    }
    
    srand(time(NULL));                   
    int Imp_Attack = RandInt(12,20);
    
    srand(time(NULL));                   
    int User_Attack = RandInt(15,42);
    
    srand(time(NULL));                   
    int Potion_Heal = RandInt(70,160);
    
    srand(time(NULL));                   
    int Imp_Potions = RandInt(1,5);
    
    srand(time(NULL));                   
    int Weapon_Upgrade = RandInt(1,15);
    
    srand(time(NULL));                   
    int Imp_Exp = RandInt(30,90);
    
    srand(time(NULL));                   
    int Imp_Gold = RandInt(30,120);
    
    
    
    User_Attack = ((User_Attack + User_Weapon) * User_Level) * 2;
    
    cout << "--------------------------------------------\n";
    cout << "Health: "<<User_Health<<"/"<<User_Max_Health<<"\n";
    cout << "--------------------------------------------\n";
    cout << "Level: "<<User_Level<<"\tWeapon: "<<User_Weapon<<"\n";
    cout << "--------------------------------------------\n";
    cout << "Exp: "<<User_Exp<<"\tExp to next level: "<<Next_Level<<"\n";
    cout << "--------------------------------------------\n";
    cout << "Gold: "<<User_Gold<<"\tPotions: "<<User_Potions<<"\n";  
    cout << "--------------------------------------------\n";       
    
    cout << "\nYou are in a dark room, monsters are flooding in from\n";
    cout << "both exits, you have no choice but to fight. Perhaps you\n";
    cout << "could get out if you destroy enough of the monsters\n\n";
    
    system("pause");
    
    cout << "Imp attacks, does "<<Imp_Attack<<" Damage.\n";
    
    User_Health = User_Health - Imp_Attack;
    
    if(User_Health <= 0)
    {
    User_Health = 0;
        cout << "\nYou have died.\n";
        system("pause");
        return 0;
    }
    cout << "\nYou attack, you do "<<User_Attack<<" damage.\n\n";
    
    Imp_Health = Imp_Health - User_Attack;
    
    if(Imp_Health <= 0)
    {
        cout << "\nYou have defeated an Imp.\n";
        cout << "You gain "<<Imp_Exp<< " Exp and "<<Imp_Gold<<" Gold.\n";
        
    User_Exp = User_Exp + Imp_Exp;
    User_Gold = User_Gold + Imp_Gold;
    Imp_Health = Imp_Max_Health;
    
    if(Weapon_Upgrade == 1)
    {
    User_Weapon = User_Weapon++;
    }
    
    if(Imp_Potions == 1)
    {
    User_Potions = User_Potions++;
    cout << "You found a potion\n";   
    }
        
        cout << "\nDo you wish to use a potion?\n1)Yes 2)No\n";  
        cin >> USE_POTION;
    
    if(USE_POTION == 1 & User_Potions >= 1)
    {
        system("cls");
        cout << "You have been healed for "<<Potion_Heal<<"\n";
        
        User_Potions = User_Potions--;
        
        User_Health = User_Health + Potion_Heal;
        if(User_Health >= User_Max_Health)
        {
        User_Health = User_Max_Health;
        }
    }        //End if
    else if (USE_POTION == 2)
    {
    }
    }        //End if
    system("pause");
    }        //End Do
    
    while(Q != 1); 
        return 0;
    }
    My latest work, any sugguestions how I could branch it out i.e. walking to different rooms and areas.
    Last edited by Kirdra; 09-14-2002 at 01:53 PM.

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. Turn Based Stradegy System Methods
    By TylerMoyer in forum Game Programming
    Replies: 2
    Last Post: 07-30-2007, 11:45 PM
  2. Forming RTS Demo Team Sixth Extinction
    By SteelRain4eva in forum Projects and Job Recruitment
    Replies: 0
    Last Post: 06-08-2006, 09:47 PM
  3. Looping Text based battle
    By pujuman in forum C++ Programming
    Replies: 7
    Last Post: 12-18-2004, 05:24 AM
  4. Battle of the Knight V1.0 Demo!
    By Blizzarddog in forum Game Programming
    Replies: 9
    Last Post: 03-07-2003, 10:33 AM
  5. Second MoA Demo Tomorrow
    By harryP in forum A Brief History of Cprogramming.com
    Replies: 1
    Last Post: 09-30-2002, 08:22 PM

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