Hello.
I have been experimenting with some code iv found and iv made a 2-player game. I am just learning how to write code and this is the first project I have done that can be expanded and changed.
This is definitely not finished and im sorry if its a bit sloppy and the comments don't make sense. Iv been too busy learning and having fun to keep tidy. You should see my flat!
I plan to add the following later on:
menu's and to be able to pick character.
new characters like mage or wizard.
basic AI for single player game.
Any comments or suggestions would be awesome.
Code:
#include <iostream>
#include <cstdlib>
using namespace std;
int main()
{
int damage = 0;
int player1HP = 100;
int player2HP = 100;
int player1MP = 0;
int player1ATK = 2;
int player2ATK = 2;
int potionSTR = 3;
int potionNUM1 = 3;
int potionNUM2 = 3;
int turn = 1;
char enter;
//Combat
cout << "welcome to Atco's savage fighting game!\n\nEnter 1: ";
cin >> enter;
if (enter == '1')
cout << system("CLS");
else system ("CLS");
while (player1HP > 0 && player2HP > 0)
{
system("CLS");
cout << "Berserker Warrior's HP = " << player1HP << endl;
cout << "Berserker Warrior's rage = " << player1MP << endl;
cout << "Shadow Priest's HP = " << player2HP << endl;
cout << "damage is " << damage << endl;
//Player 1's Turn
if(turn == 1)
{
cout << "\nWarrior's Turn.\n" << potionNUM1 << " potion's left." << "\nY = Bash, N = Zerg Potion, X = Special Attack, M for devastate: ";
cout << " " << "\n (cost's 5 rage) (cost's 20 rage)";
char player1Attack;
cin >> player1Attack;
//Player 1 Attacks plus gains 2 health P1attck
if(player1Attack == 'y')
{
player2HP = player2HP - player1ATK;
player1HP = player1HP + 2;
damage = player1ATK;
if(player2HP <= 0)
{
player2HP = 0;
}
player1MP = player1MP + 2;
turn = 2;
}
//Player 1 Uses Potion P1 attck potion
else if (player1Attack == 'n')
{
if (potionNUM1 >= 1)
{player1ATK = player1ATK + potionSTR;
potionNUM1--;
if (player1HP > 51)
player1HP = 75;
turn =2;}
if (potionNUM1 <= 0)
turn = 2;
player1MP = player1MP + 2;
damage = 0;
turn = 2;
}
//Player 1 Special attck 5 RAGE
else if(player1Attack == 'x')
{
if (player1MP >= 5)
{player2HP = player2HP - (player1ATK+4);
player1HP = player1HP - 2;
player1MP = player1MP - 5;
turn = 2;}
damage = (player1ATK+4);
if (player1MP <= 4)
turn = 2;
if(player2HP <= 0)
{
player2HP = 0;
}
player1MP = player1MP + 2;
turn = 2;
}
//Player 1 Special attck 20 RAGE
else if(player1Attack == 'm')
{
if (player1MP >= 20)
{player2HP = player2HP - (player1ATK+50);
player1HP = player1HP - 2;
player1MP = player1MP - 20;
turn = 2;}
damage = player1ATK+50;
if (player1MP <= 19)
turn = 2;
if(player2HP <= 0)
{
player2HP = 0;
}
player1MP = player1MP + 2;
turn = 2;
}
}
//Player 2's Turn
else
{
cout << "\nPriest's Turn.\n" << potionNUM2 << " potions left." << "\nY = Leach health, N = Health potion, X = Special Attack: ";
char player2Attack;
cin >> player2Attack;
//Player 2 Attacks p2
if(player2Attack == 'y')
{
player1HP = player1HP - (player2ATK);
player2HP = player2HP + (player1MP/2) + 4;
player1MP = player1MP + 3;
damage = player2ATK + player1MP/2;
if(player1HP <= 0)
{
player1HP = 0;
}
turn = 1;
}
//PLayer 2 Uses Potion P2
else if (player2Attack == 'n')
{ if (potionNUM2 >= 1)
{player2HP = player2HP + 40;
potionNUM2--;}
if (potionNUM2 <= 0)
turn =1;
if (player2HP > 101)
{
player2HP = 100;
}damage = 0;
turn = 1;
}
//Player 2 Special attck
else if(player2Attack == 'x')
{
player1HP = player1HP - (player2ATK + player1MP/2);
damage = (player2ATK + player1MP/2);
if(player1HP <= 0)
{
player1HP = 0;
}
turn = 1;
cout << "test";
}
}
}
// Game Over - Either Player 1 wins or Player 2 Wins.
//Player 2 Wins
if(player1HP == 0)
{
system("cls");
cout << "Warrior's HP = " << player1HP << endl;
cout << "Priest's HP = " << player2HP << endl;
cout << "Shadow Priest Wins!" << endl;
}
//Player 1 Wins
else
{
system("cls");
cout << "Warrior's HP = " << player1HP << endl;
cout << "Priest's HP = " << player2HP << endl;
cout << "Berserker Warrior Wins!" << endl;
}
return 0;
}