View previous topic :: View next topic |
Author |
Message |
hyphen Advanced Cheater Reputation: 0
Joined: 12 Sep 2008 Posts: 84 Location: Not Having Fun
|
Posted: Tue Jun 30, 2009 9:19 pm Post subject: [Binary..]Basic Console Game |
|
|
I'm sorry this isn't in the Binaries section.
Unfortunately, I'm like 30 short of the 100 posts requirement >.<
Mmmmmmm I hope this thread duzzn't get deleted.
Anyways was just bored today, decided to spend 3 quarter hours making this useless 2P console game.
I designed to randomly select between two people. (Say you have an extra whatever and can only share it with one of two friends..)
Mediafire Link: http://www.mediafire.com/download.php?mtmymgzy0nm
Code: | //Some random console application game
//Made by Hyphen
//Took approx. 45 mins
//8:50 added sleeptimes to stop everything from happening so fast
//My Includes (some useless)
#include<iostream.h> // Input/Output
#include<windows.h> // for Sleep()
#include<cmath> // for math
#include<cstdio> // for math
#include<cstdlib>
#include<conio.h> // for "press any key to continue"
//these macros didn't work... why? DX
#define player1 Bob
#define player2 UberBob
//randomizer functions prototypes
int zero2ten();
int zero2twenty();
//global stuffz
unsigned short p1hp = 100, p2hp = 100; //l15
enum act {attack,smash,heal};
act action;
int damage;
int main()
{
cout << "The battle between player1 and player2 has started!" << endl;
cout << "player1 has " << p1hp << "/100 hp." << endl;
cout << "player2 has " << p2hp << "/100 hp." << endl;
int starter = rand()%2;
if (starter == 1)
{
}
//l30
for(;p1hp > 0 && p1hp < 125 && p2hp > 0 && p2hp < 125 ;)
{
//player1 turn
cout << "player1" << "'s turn." << endl << "A: Attack S: Smash Attack D: Cast Heal" << endl;
for(;p1hp > 0 && p1hp < 125 && p2hp > 0 && p2hp < 125 ;)
{
if(GetAsyncKeyState(0x41))
{action = attack; break;}
if(GetAsyncKeyState(0x53))
{action = smash; break;}
if(GetAsyncKeyState(0x44))
{action = heal; break;}
}
Sleep(100);
//player1 actions l45
if (action == attack)
{
damage = zero2ten();
p2hp = p2hp - damage;
cout << "player1 dealed " << damage << " damage to player2. ";
Sleep(500);
cout << "player2 has " << p2hp << "/100 hp." << endl;
Sleep(800);
if (p2hp > 124 || p2hp <1)
break;
}
if (action == smash)
{
damage = zero2twenty();
if (damage < 11)
cout << "player1" << "'s smash attack missed!" << endl;
else
{
p2hp = p2hp - damage;
cout << "player1 dealed " << damage << " damage to player2.";
Sleep(500);
cout << "player2 has " << p2hp << "/100 hp." << endl; //l65
}
Sleep(800);
if (p2hp > 124 || p2hp <1)
break;
}
if (action == heal)
{
damage = zero2ten();
if (damage = 10)
{
p2hp = p2hp + 10;
cout << "player1 accidentely healed player2 for 10 hp!";
}
else
{
p1hp = p1hp + damage;
cout << "player1 healed himself for " << damage << "hp";
}
Sleep(500);
if (p1hp > 100 && p1hp < 125)
p1hp = 100;
cout << "player1 has " << p1hp << "/100 hp." << endl;
Sleep(800);
}
//player2 turn
cout << "player2" << "'s turn." << endl << "NUM_1: Attack NUM_2: Smash Attack NUM_3: Cast Heal" << endl;
for(;p1hp > 0 && p1hp < 125 && p2hp > 0 && p2hp < 125 ;)
{
if(GetAsyncKeyState(VK_NUMPAD1))
{action = attack; break;}
if(GetAsyncKeyState(VK_NUMPAD2))
{action = smash; break;}
if(GetAsyncKeyState(VK_NUMPAD3))
{action = heal; break;}
}
Sleep(100);
//player2 actions
if (action == attack)
{
damage = zero2ten();
p1hp = p1hp - damage;
cout << "player2 dealed " << damage << " damage to player1. ";
Sleep(500);
cout << "player1 has " << p1hp << "/100 hp." << endl;
Sleep(800);
if (p1hp > 124 || p1hp <1)
break;
}
if (action == smash)
{
damage = zero2twenty();
if (damage < 11)
cout << "player2" << "'s smash attack missed!" << endl;
else
{
p1hp = p1hp - damage;
cout << "player2 dealed " << damage << " damage to player1.";
Sleep(500);
cout << "player1 has " << p1hp << "/100 hp." << endl;
}
Sleep(800);
if (p1hp > 124 || p1hp <1)
break;
}
if (action == heal)
{
damage = zero2ten();
if (damage = 10)
{
p1hp = p1hp + 10;
cout << "player2 accidentely healed player1 for 10 hp!";
}
else
{
p2hp = p2hp + damage;
cout << "player2 healed himself for " << damage << "hp";
}
Sleep(500);
if (p2hp > 100 && p2hp < 125)
p2hp = 100;
cout << "player2 has " << p2hp << "/100 hp." << endl;
Sleep(800);
}
}
if (p1hp > 124 || p1hp <1)
cout << "player2 wins! player1 is ***" << endl;
else
cout << "player1 wins! player2 is ***" << endl;
Sleep(5000);
system("pause");
return 0;
}
//randomizers
int zero2ten()
{
int retNumber1 = rand()%11; //0 to 10
return retNumber1;
}
int zero2twenty()
{
int retNumber2 = rand()%21; //0 to 20
return retNumber2;
} |
Nothing special in there just thought I may as well post it somewhere.
Begs mods to move this into the right section be4 I get bannned.
|
|
Back to top |
|
|
HomerSexual Grandmaster Cheater Supreme Reputation: 5
Joined: 03 Feb 2007 Posts: 1657
|
Posted: Tue Jun 30, 2009 9:22 pm Post subject: |
|
|
since you posted code, you are fine. Binaries is for finished projects w/o code
_________________
|
|
Back to top |
|
|
hyphen Advanced Cheater Reputation: 0
Joined: 12 Sep 2008 Posts: 84 Location: Not Having Fun
|
Posted: Tue Jun 30, 2009 9:35 pm Post subject: |
|
|
blankrider wrote: | since you posted code, you are fine. Binaries is for finished projects w/o code |
Ah alright then. Thanks for enlightening me.
|
|
Back to top |
|
|
hcavolsdsadgadsg I'm a spammer Reputation: 26
Joined: 11 Jun 2007 Posts: 5801
|
Posted: Wed Jul 01, 2009 12:02 am Post subject: Re: [Binary..]Basic Console Game |
|
|
hyphen wrote: | Begs mods to move this into the right section be4 I get bannned. |
why would you get banned for such a simple mistake?
blankrider wrote: | since you posted code, you are fine. Binaries is for finished projects w/o code |
you're plenty welcome to post code in binaries.
|
|
Back to top |
|
|
Jani Grandmaster Cheater Reputation: 2
Joined: 29 Dec 2006 Posts: 804
|
Posted: Sun Aug 09, 2009 9:01 am Post subject: |
|
|
If you're writing in C++, why not to do OO?
Also, why: Code: | for(;p1hp > 0 && p1hp < 125 && p2hp > 0 && p2hp < 125 ;) | instead of Code: | while(p1hp > 0 && p1hp < 125 && p2hp > 0 && p2hp < 125) |
Kinda buggy, eg:
|
|
Back to top |
|
|
|