simple game XD

Posts 1–4 of 4 · Page 1 of 1
simple game XD
I dont know if someone has done this before, but i made this simple game (is quite stupid it wont exit itself ), i wanted to do something bigger ( like a storyline ) but i thought that i was wasting my time cause i need to make a game with graphics or something, but im a looooong way now...

P.S. im starting at c++ but i found that rand thingy while surfing the library and thought of this idead XD and the You Win!, You Lose! text i made it with an Ascci ( i think ) text generator ^_^

Code:
/*
  Name: Mini Turn Based RPG
  Copyright: No copyright you can use it has you wish, 
  but if you paste it somewere else give credit ;D ( and to yourself for finding it XD )
  Author: mpruisu
  Date: 13/05/11 23:13
  Description: The Mini turn based RPG, can be found at cplusplus.com, mpgh.net
*/



#include <iostream>
#include <stdio.h>
#include <stdlib.h>
#include <time.h>
using namespace std;

int pattack, eattack, pdefend, edefend, php, ehp, atk, atk2, hps, x;
void patchk ();
void eatchk ();
void menu ();
void exit ();

int main ()
{
    cout << "Please enter the HP for both you and your opponent: ";
    cin >> hps;
    ehp = hps;
    php = hps;
    cout << "\n\nEnter a Value for bot you and your opponents damage\n(Damage for both will be random from 1 to the number you pick): ";
    cin >> x;
    cout << "Now i will clear a bit the screen press enter";
    cin.get();
    cin.get();
    cout << "\n\n\n\n\n\n\n\n";
    menu ();
}

void patchk (){
    pattack = rand() % x + 1;
    edefend = rand() % x + 1;
    if (pattack >= edefend){
                ehp = ehp - pattack;
                cout << "\n\nYou dealt " << pattack;
                }
                else{
                     cout << "\n\nEnemy defended your attack";
                     }
}

void eatchk (){
    eattack = rand() % x + 1;
    pdefend = rand() % x + 1;
    if (eattack >= pdefend){
                php = php - eattack;
                cout << "\n\nEnemy dealt " << eattack;
                }
                else{
                     cout << "\n\nYou defended your attack";
                     }
}

void menu (){
    cout << "\n\nYour HP: " << php << "\nEnemy HP: " << ehp;
    cout << "\n\nWould you like to attack? (say 1 to atk or 2 to skip)";
    cin >> atk;
    if (atk == 1){
            patchk ();
            exit ();
            eatchk ();
            exit ();
            menu ();
            }
    else if (atk == 2){
         cout << "\n\nWarning!: If you really skip your turn the enemy will try and hit you are you sure? (say 1 for yes or 2 for no)";
         cin >> atk2;
         switch (atk2){
                case 1:
                     eatchk ();
                     exit ();
                     menu ();
                     break;
                case 2:
                     exit ();
                     menu ();
                     break;
                     }
         }
    else 
    {
         cout << "\n\nYou must say 1 for attack or 2 to skip";
         exit ();
         menu ();
    }
}

void exit ()
{
     if (ehp <= 0)
     {
            cout << "\n\n ##    ##  #######  ##     ##    ##      ## #### ##    ## #### \n";
             cout << "##  ##  ##     ## ##     ##    ##  ##  ##  ##  ###   ## #### \n";
             cout << "####   ##     ## ##     ##    ##  ##  ##  ##  ####  ## #### \n";
             cout << "##    ##     ## ##     ##    ##  ##  ##  ##  ## ## ##  ##  \n";
             cout << "##    ##     ## ##     ##    ##  ##  ##  ##  ##  ####      \n";
             cout << "##    ##     ## ##     ##    ##  ##  ##  ##  ##   ### #### \n";
             cout << "##     #######   #######      ###  ###  #### ##    ## #### \n";
             cout << "You are a true master at typing 1 and enter, (enter to exit): ";
             cin.ignore();
             cin.get();
    }
    else if (php <= 0)
    {
          cout << "\n\n ##    ##  #######  ##     ##    ##        #######   ######  ######## #### \n";
          cout << "##  ##  ##     ## ##     ##    ##       ##     ## ##    ## ##       #### \n";
          cout << "####   ##     ## ##     ##    ##       ##     ## ##       ##       #### \n";
          cout << "##    ##     ## ##     ##    ##       ##     ##  ######  ######    ##  \n";
          cout << "##    ##     ## ##     ##    ##       ##     ##       ## ##            \n";
          cout << "##    ##     ## ##     ##    ##       ##     ## ##    ## ##       #### \n";
          cout << "##     #######   #######     ########  #######   ######  ######## #### \n";
          cout << "Don't lose faith, (enter to exit...): ";
          cin.ignore();
          cin.get();
    }
}
Nice release. Only games I've made was a guessing game and a mathematical game involving sqroot() and so on

EDIT: Mate, you don't need to let the game stop when the player has lost or won, you can let it return back to the start
ohh right, i forgot about that ^_^ hehe maybe ill edit it and post it later because i have to go far from home XD
Quote Originally Posted by ruisu View Post
ohh right, i forgot about that ^_^ hehe maybe ill edit it and post it later because i have to go far from home XD
You can also make a infinite loop, and if() the user inputs "Start" it will start the game, and that loop will obviously run forever and ever much easier
Posts 1–4 of 4 · Page 1 of 1

Post a Reply

Tags for this Thread

None

Talk with us