rendered paste body#include <iostream>
#include <string>
#include <sstream>
using namespace std;
// DOS WARS!!!! (REAL MEN VS. MENSA KIDS)
// THIS IS MY FIRST GAME USING CLASSES/REFERENCES/POINTERS/ETC.
// TELL ME IF IT IS DONE WELL (CONSIDER THAT I AM NEW TO C++ THOUGH,
// ALSO, I AM WRITING IN ALL CAPS, BECAUSE I CAN, AND IT MAKES ME FEEL BIG.
//--------------------------------- Function Prototypes
void newlines();
void getinfo();
void getp1stamina();
void getp2stamina();
void p1attacklogic();
void p1defendlist();
void p1attacklist();
void p2attacklogic();
void p2attacklist();
void p2defendlist();
void turnstates();
void start();
void p1success();
void p2success();
void victory();
//---------------------------------- Class bullshit.
class Player //
{
public:
string GetMyWeapon();
void SetMyWeapon(string Weapon);
string GetMyName();
void SetMyName(string Name);
int GetMyStamina();
void SetMyStamina(int Stamina);
private:
string MyWeapon;
string MyName;
int MyStamina;
};
// --------------------------------------------- Player Class stuff.
void Player::SetMyWeapon (string Weapon)
{ MyWeapon = Weapon; }
string Player::GetMyWeapon ()
{ return MyWeapon; }
void Player::SetMyName (string Name)
{ MyName = Name; }
string Player::GetMyName()
{ return (MyName); }
void Player::SetMyStamina (int Stamina)
{ MyStamina = Stamina; }
int Player::GetMyStamina ()
{ return (MyStamina); }
//---------------------------------- Player Declarations (Global) with pointers (global)
Player PlayerOne;
Player * PPlayerOne = &PlayerOne;
Player PlayerTwo;
Player * PPlayerTwo = &PlayerTwo;
// ---------------------------------- Player Selections.
int p1attackselection;
int p1defendselection;
int p2attackselection;
int p2defendselection;
int *pp1attackselection = &p1attackselection;
int *pp2attackselection = &p2attackselection;
int *pp1defendselection = &p1defendselection;
int *pp2defendselection = &p2defendselection;
int p1hitswitch;
int *pp1hitswitch = &p1hitswitch;
int p2hitswitch;
int *pp2hitswitch = &p2hitswitch;
//---------------------------------- Player Staminas (global) with pointers (global)
int p1stamina = 100;
int *pp1stamina = &p1stamina;
int p2stamina = 100;
int *pp2stamina = &p1stamina;
int turnstate = 1;
int *pturnstate = &turnstate;
int main () //---------------------- The Program Begins
{
getinfo();
p1attacklogic();
if (*pp1stamina < 0)
{
cout << PlayerOne.GetMyName() << " has lost the game.\n";
return 0;
}
else if (*pp2stamina < 1)
{
cout << PlayerTwo.GetMyName() << " has lost the game.\n";
return 0;
}
return 0;
}
void getinfo ()
{
string p1name;
string *pp1name = &p1name;
string p1weapon;
string *pp1weapon = &p1weapon;
string p2name;
string *pp2name = &p2name;
string p2weapon;
string *pp2weapon = &p2weapon;
cout << "You are a real man, tell me your name.\n";
getline (cin, *pp1name);
cout << "Thank you, " << p1name << ". And what weapon do you bring?\n";
getline (cin, *pp1weapon);
cout << "And you, Mensa Kid, what is your name?\n";
getline (cin, *pp2name);
cout << "And your weapon?\n";
getline (cin, *pp2weapon);
cout << "Then, shall we begin? I suppose " << *pp1name << " should go first.\n";
PlayerOne.SetMyName(*pp1name = *pp1name);
PlayerOne.SetMyWeapon(*pp1weapon = *pp1weapon);
PlayerTwo.SetMyName(*pp2name = *pp2name);
PlayerTwo.SetMyWeapon(*pp2weapon = *pp2weapon);
}
// -------------------------------------------- Base Stamina (defaulted at 100).
void setp1stamina ()
{
PlayerOne.SetMyStamina (*pp1stamina = *pp1stamina);
}
void setp2stamina ()
{
PlayerTwo.SetMyStamina (*pp2stamina = *pp2stamina);
}
// -------------------------------------------- Attack Logic.
void p1attacklogic ()
{
if (*pp1stamina <= 1 && *pp2stamina >= 1)
{
cout << PlayerOne.GetMyName() << " has killed " << PlayerTwo.GetMyName() << ".\n";
}
else if (*pp2stamina <= 1 && *pp1stamina >= 1)
{
cout << PlayerTwo.GetMyName() << "has killed " << PlayerOne.GetMyName() << ".\n";
}
else if (*pp1stamina <= 0 && pp2stamina <= 0)
{
cout << "Both players have died!\n";
}
cout << "***************** ATTACK MENU *****************\n";
cout << "1. STAB\n";
cout << "2. SHIELD BASH\n";
cout << "3. THRUST\n";
cout << "4. HARD THRUST\n";
cout << "5. SLASH\n";
cout << "6. HARD SLASH\n";
cout << PlayerOne.GetMyName() << ", make a selection.\n";
cin >> *pp1attackselection;
if (*pp1attackselection == 1 || *pp1attackselection == 2)
{
newlines();
cout << PlayerOne.GetMyName() << " steps quickly towards you."
<< PlayerTwo.GetMyName() << ", what will you do?\n";
goto ifend1;
}
else if (*pp1attackselection == 3 || *pp1attackselection == 4)
{
newlines();
cout << PlayerOne.GetMyName() << " lowers his stance and draws his "
<< "weapon behind him.\n";
cout << PlayerTwo.GetMyName() << ", how do you respond?\n";
goto ifend1;
}
else if (*pp1attackselection == 5 || *pp1attackselection == 6)
{
newlines();
cout << PlayerOne.GetMyName() << " steps back.\n";
cout << PlayerTwo.GetMyName() << ", how do you respond?\n";
goto ifend1;
}
ifend1:
p2defendlist();
}
void p2attacklogic ()
{
if (*pp1stamina <= 1 && *pp2stamina >= 1)
{
cout << PlayerOne.GetMyName() << " has killed " << PlayerTwo.GetMyName() << ".\n";
}
else if (*pp2stamina <= 1 && *pp1stamina >= 1)
{
cout << PlayerTwo.GetMyName() << "has killed " << PlayerOne.GetMyName() << ".\n";
}
else if (*pp1stamina <= 0 && pp2stamina <= 0)
{
cout << "Both players have died!\n";
}
cout << "***************** ATTACK MENU *****************\n";
cout << "1. STAB\n";
cout << "2. SHIELD BASH\n";
cout << "3. THRUST\n";
cout << "4. HARD THRUST\n";
cout << "5. SLASH\n";
cout << "6. HARD SLASH\n";
cout << PlayerTwo.GetMyName() << ", make a selection.\n";
cin >> *pp2attackselection;
if (*pp2attackselection == 1 || *pp2attackselection == 2)
{
newlines();
cout << PlayerTwo.GetMyName() << " steps quickly towards you."
<< PlayerOne.GetMyName() << ", what will you do?\n";
goto ifend2;
}
if (*pp2attackselection == 3 || *pp2attackselection == 4)
{
newlines();
cout << PlayerTwo.GetMyName() << " lowers his stance and draws his "
<< "weapon behind him.\n";
cout << PlayerOne.GetMyName() << ", how do you respond?\n";
goto ifend2;
}
if (*pp2attackselection == 5 || *pp2attackselection == 6)
{
newlines();
cout << PlayerTwo.GetMyName() << " steps back.\n";
cout << PlayerOne.GetMyName() << ", how do you respond?\n";
goto ifend2;
}
ifend2:
p1defendlist();
}
// ----------------------------------------------- Create new lines.
void newlines()
{
cout << "\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n";
cout << "\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n";
}
// ----------------------------------------------- Defense stuff.
void p1defendlist ()
{
cout << "***************** DEFEND MENU *****************\n";
cout << "1. DODGE\n";
cout << "2. BLOCK\n";
cout << "3. STRONG BLOCK\n";
// cout << "4. COUNTER ATTACK\n";
cout << PlayerOne.GetMyName() << ", make a selection.\n";
cin >> *pp1defendselection;
if (*pp1defendselection == 1 && *pp2attackselection == 1) // dodge/stab
{
*pp1stamina = *pp1stamina - 0;
cout << "You've successfully dodged " << PlayerOne.GetMyName()
<< "'s stab attack!\n";
// remove later
cout << "Player One's stamina: " << *pp1stamina << endl;
cout << "Player Two's stamina: " << *pp2stamina << endl;
*pturnstate = 1;
}
else if (*pp1defendselection == 1 && (*pp2attackselection == 2 || *pp2attackselection == 3
|| *pp2attackselection == 4 || *pp2attackselection == 5 || *pp2attackselection == 6))
{
cout << "You failed to dodge!\n";
*pp1stamina = *pp1stamina - 15;
// remove later
cout << "Player One's stamina: " << *pp1stamina << endl;
cout << "Player Two's stamina: " << *pp2stamina << endl;
*pturnstate = 2;
}
else if ((*pp1defendselection == 2 || *pp1defendselection == 3) && *pp2attackselection == 1)
{
cout << "You've been stabbed!\n";
*pp1stamina = *pp1stamina - 10;
// remove later
cout << "Player One's stamina: " << *pp1stamina << endl;
cout << "Player Two's stamina: " << *pp2stamina << endl;
*pturnstate = 2;
}
else if (*pp1defendselection == 3 && *pp2attackselection == 2) // strong block/shield bash
{
cout << "Your strong block stopped the force of "
<< PlayerTwo.GetMyName()
<< "'s shield bash! Your arm is a little tired though.\n";
*pp1stamina = *pp1stamina - 5;
// remove later
cout << "Player One's stamina: " << *pp1stamina << endl;
cout << "Player Two's stamina: " << *pp2stamina << endl;
*pturnstate = 1;
}
else if (*pp1defendselection == 2 && *pp2attackselection == 2)
{
cout << "You stagger back.\n";
*pp1stamina = *pp1stamina - 10;
// remove later
cout << "Player One's stamina: " << *pp1stamina << endl;
cout << "Player Two's stamina: " << *pp2stamina << endl;
*pturnstate = 2;
}
else if (*pp1defendselection == 2 && *pp2attackselection == 3) // block/thrust
{
cout << PlayerTwo.GetMyName() << " loses his balance after you block his thrust.\n";
cout << "The advantage is yours!\n";
*pp1stamina = *pp1stamina - 0;
// remove later
cout << "Player One's stamina: " << *pp1stamina << endl;
cout << "Player Two's stamina: " << *pp2stamina << endl;
*pturnstate = 1;
}
else if (*pp1defendselection == 2 && *pp2attackselection == 4) // block/strong thrust
{
cout << PlayerTwo.GetMyName() << "'s hard thrust overcomes your block!"
<< "He readies to strike again!\n";
*pp1stamina = *pp1stamina - 10;
// remove later
cout << "Player One's stamina: " << *pp1stamina << endl;
cout << "Player Two's stamina: " << *pp2stamina << endl;
*pturnstate = 2;
}
else if (*pp1defendselection == 2 && *pp2attackselection == 5) // block/slash
{
cout << PlayerTwo.GetMyName() << "'s slash falls harmlessly onto your shield.\n";
*pp1stamina = *pp1stamina -0;
// remove later
cout << "Player One's stamina: " << *pp1stamina << endl;
cout << "Player Two's stamina: " << *pp2stamina << endl;
*pturnstate = 1;
}
else if (*pp1defendselection == 2 && *pp2attackselection == 6) // block/strong slash
{
cout << PlayerTwo.GetMyName() << "'s hard slash slides across your shield and knicks"
<< "your neck. You're shaken.\n";
*pp1stamina = *pp1stamina - 15;
// remove later
cout << "Player One's stamina: " << *pp1stamina << endl;
cout << "Player Two's stamina: " << *pp2stamina << endl;
*pturnstate = 2;
}
else if (*pp1defendselection == 3 && *pp2attackselection == 3)
{
cout << "You stop " << PlayerTwo.GetMyName() << "'s thrust with a sweeping shield "
<< "block.";
*pp1stamina = *pp1stamina - 5;
// remove later
cout << "Player One's stamina: " << *pp1stamina << endl;
cout << "Player Two's stamina: " << *pp2stamina << endl;
*pturnstate = 1;
}
else if (*pp1defendselection == 3 && *pp2attackselection == 4)
{
cout << "You block " << PlayerTwo.GetMyName() << "'s strong thrust by "
<< "throwing your shield towards his " << PlayerTwo.GetMyWeapon() << ".\n";
*pp1stamina = *pp1stamina - 5;
// remove later
cout << "Player One's stamina: " << *pp1stamina << endl;
cout << "Player Two's stamina: " << *pp2stamina << endl;
*pturnstate = 1;
}
else if (*pp1defendselection == 3 && *pp2attackselection == 5)
{
cout << "You stop " << PlayerTwo.GetMyName() << "'s slash cold, he looks shaken.\n";
*pp1stamina = *pp1stamina - 5;
// remove later
cout << "Player One's stamina: " << *pp1stamina << endl;
cout << "Player Two's stamina: " << *pp2stamina << endl;
*pturnstate = 1;
}
else if (*pp1defendselection == 3 && *pp2attackselection == 6)
{
cout << "Your shield buckles with " << PlayerTwo.GetMyName()
<< "'s " << PlayerTwo.GetMyWeapon() << " and his attack is rendered "
<< "useless\n";
*pp1stamina = *pp1stamina - 5;
// remove later
cout << "Player One's stamina: " << *pp1stamina << endl;
cout << "Player Two's stamina: " << *pp2stamina << endl;
*pturnstate = 1;
}
if (*pturnstate == 1)
{
p1attacklogic();
}
else if (*pturnstate == 2)
{
p2attacklogic();
}
}
void p2defendlist ()
{
cout << "***************** DEFEND MENU *****************\n";
cout << "1. DODGE\n";
cout << "2. BLOCK\n";
cout << "3. STRONG BLOCK\n";
// cout << "4. COUNTER ATTACK\n";
cout << PlayerTwo.GetMyName() << ", make a selection.\n";
cin >> *pp2defendselection;
if (*pp2defendselection == 1 && *pp1attackselection == 1) // dodge/stab
{
cout << "You've successfully dodged " << PlayerOne.GetMyName()
<< "'s stab attack!\n";
*pp2stamina = *pp2stamina = - 0;
// remove later
cout << "Player One's stamina: " << *pp1stamina << endl;
cout << "Player Two's stamina: " << *pp2stamina << endl;
*pturnstate = 2;
}
else if ((*pp2defendselection == 1 && *pp1attackselection == 2) || (*pp2defendselection == 1 &&
*pp1attackselection == 3) || (*pp2defendselection == 1 && *pp1attackselection == 4) ||
(*pp2defendselection == 1 && *pp1attackselection == 5) || (*pp2defendselection == 1 && *pp1attackselection == 6))
{
cout << "You failed to dodge!\n";
*pp2stamina = *pp2stamina - 15;
// remove later
cout << "Player One's stamina: " << *pp1stamina << endl;
cout << "Player Two's stamina: " << *pp2stamina << endl;
*pturnstate = 1;
}
else if ((*pp2defendselection == 2 || *pp2defendselection == 3) && *pp1attackselection == 1)
{
cout << "You've been stabbed!\n";
*pp2stamina = *pp2stamina - 10;
// remove later
cout << "Player One's stamina: " << *pp1stamina << endl;
cout << "Player Two's stamina: " << *pp2stamina << endl;
*pturnstate = 1;
}
else if (*pp2defendselection == 3 && *pp1attackselection == 2) // strong block/shield bash
{
cout << "Your strong block stopped the force of "
<< PlayerOne.GetMyName()
<< "'s shield bash! Your arm is a little tired though.\n";
*pp2stamina = *pp2stamina - 5;
// remove later
cout << "Player One's stamina: " << *pp1stamina << endl;
cout << "Player Two's stamina: " << *pp2stamina << endl;
*pturnstate = 2;
}
else if (*pp2defendselection == 2 && *pp1attackselection == 2)
{
cout << "You stagger back.\n";
*pp2stamina = *pp2stamina - 10;
// remove later
cout << "Player One's stamina: " << *pp1stamina << endl;
cout << "Player Two's stamina: " << *pp2stamina << endl;
*pturnstate = 1;
}
else if (*pp2defendselection == 2 && *pp1attackselection == 3) // block/thrust
{
cout << PlayerOne.GetMyName() << " loses his balance after you block his thrust.\n";
cout << "The advantage is yours!\n";
*pp2stamina = *pp2stamina - 0;
// remove later
cout << "Player One's stamina: " << *pp1stamina << endl;
cout << "Player Two's stamina: " << *pp2stamina << endl;
*pturnstate = 2;
}
else if (*pp2defendselection == 2 && *pp1attackselection == 4) // block/strong thrust
{
cout << PlayerOne.GetMyName() << "'s hard thrust overcomes your block!"
<< "He readies to strike again!\n";
*pp2stamina = *pp2stamina - 10;
// remove later
cout << "Player One's stamina: " << *pp1stamina << endl;
cout << "Player Two's stamina: " << *pp2stamina << endl;
*pturnstate = 1;
}
else if (*pp2defendselection == 2 && *pp1attackselection == 5) // block/slash
{
cout << PlayerOne.GetMyName() << "'s slash falls harmlessly onto your shield.\n";
*pp2stamina = *pp2stamina -0;
// remove later
cout << "Player One's stamina: " << *pp1stamina << endl;
cout << "Player Two's stamina: " << *pp2stamina << endl;
*pturnstate = 2;
}
else if (*pp2defendselection == 2 && *pp1attackselection == 6) // block/strong slash
{
cout << PlayerOne.GetMyName() << "'s hard slash slides across your shield and knicks"
<< "your neck. You're shaken.\n";
*pp2stamina = *pp2stamina - 15;
// remove later
cout << "Player One's stamina: " << *pp1stamina << endl;
cout << "Player Two's stamina: " << *pp2stamina << endl;
*pturnstate = 1;
}
else if (*pp2defendselection == 3 && *pp1attackselection == 3)
{
cout << "You stop " << PlayerOne.GetMyName() << "'s thrust with a sweeping shield "
<< "block.";
*pp2stamina = *pp2stamina - 5;
// remove later
cout << "Player One's stamina: " << *pp1stamina << endl;
cout << "Player Two's stamina: " << *pp2stamina << endl;
*pturnstate = 2;
}
else if (*pp2defendselection == 3 && *pp1attackselection == 4)
{
cout << "You block " << PlayerOne.GetMyName() << "'s strong thrust by "
<< "throwing your shield towards his " << PlayerOne.GetMyWeapon() << ".\n";
*pp2stamina = *pp2stamina - 5;
// remove later
cout << "Player One's stamina: " << *pp1stamina << endl;
cout << "Player Two's stamina: " << *pp2stamina << endl;
*pturnstate = 2;
}
else if (*pp2defendselection == 3 && *pp1attackselection == 5)
{
cout << "You stop " << PlayerOne.GetMyName() << "'s slash cold, he looks shaken.\n";
*pp2stamina = *pp2stamina - 5;
// remove later
cout << "Player One's stamina: " << *pp1stamina << endl;
cout << "Player Two's stamina: " << *pp2stamina << endl;
*pturnstate = 2;
}
else if (*pp2defendselection == 3 && *pp1attackselection == 6)
{
cout << "Your shield buckles with " << PlayerOne.GetMyName()
<< "'s " << PlayerOne.GetMyWeapon() << " and his attack is rendered "
<< "useless\n";
*pp2stamina = *pp2stamina - 5;
// remove later
cout << "Player One's stamina: " << *pp1stamina << endl;
cout << "Player Two's stamina: " << *pp2stamina << endl;
*pturnstate = 2;
}
if (*pturnstate == 1)
{
p1attacklogic();
}
else if (*pturnstate == 2)
{
p2attacklogic();
}
}
void turnstates ()
{
if (*pturnstate = 1)
{
void p1attacklogic();
}
else if (*pturnstate = 2)
{
void p2attacklogic();
}
}
void start()
{
void p1attacklogic();
}
void p1success()
{
if (*pp1hitswitch = 1) // If player one blocks successfully.
{
*pturnstate = 1; // It becomes player one's turn.
}
if (*pp1hitswitch = 2) // if Player one fails to block.
{
*pturnstate = 2; // Player one has to try again (it stays p2's turn).
}
}
void victory()
{
if (*pp1stamina <= 1 && *pp2stamina >= 1)
{
cout << PlayerOne.GetMyName() << " has killed " << PlayerTwo.GetMyName() << ".\n";
}
else if (*pp2stamina <= 1 && *pp1stamina >= 1)
{
cout << PlayerTwo.GetMyName() << "has killed " << PlayerOne.GetMyName() << ".\n";
}
else if (*pp1stamina <= 0 && pp2stamina <= 0)
{
cout << "Both players have died!\n";
}
}