1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101
|
#include <iostream>
#include <cstdlib>
#include <ctime>
using namespace std;
int roll();
void sortRolls(int& a, int& b);
void sortRolls(int&a, int&b, int&c);
bool attackerLoses(int attackRoll, int defendRoll);
void riskRoll(int& strengthOfA, int& strengthOfD);
void match(int strenthOfA, int strengthOfD);
void extendRolls(int&attackStreng, int&defendStreng);
int main()
{
match();
return 0;
}
int roll()
{
return (rand()%6)+1;
}
void sortRolls(int&a, int&b)
{
a = roll();
b = roll();
if(b >= a)
swap(a,b);
return;
}
void sortRolls(int&a, int&b, int&c)
{
a = roll();
b = roll();
c = roll();
if(c >= b)
swap(c,b);
if(c >= a)
swap(c,a);
if(b >= a)
swap(b,a);
return;
}
bool attackerLoses(int attackRoll, int defendRoll)
{
if(attackRoll > defendRoll)
return false;
else
return true;
}
void riskRoll(int& strengthOfA, int& strengthOfD)
{
int rollA, rollB, firstADie, secondADie, thirdADie,firstDDie, secondDDie;
if(strengthOfA > 3)
{
rollA = 3;
sortRolls(firstADie, secondADie, thirdADie);
}
if(strengthOfA = 2)
{
rollA = 2;
sortRolls(firstADie, secondADie);
}
if(strengthOfD > 2)
{
rollB = 2;
sortRolls(firstDDie, secondDDie);
}
if(strengthOfD = 1)
{
rollB = 1;
firstDDie = roll();
}
cout << "You have made a roll!\n";
}
void match(int strenthOfA, int strengthOfD)
{
void extendRolls();
cout << "You have started a new match!\n";
}
void extendRolls(int& strengthOfA, int& strengthOfD)
{
cout << "Enter your attacking strength.\n";
cin >> strengthOfA;
cout << "Enter your defending strength.\n";
cin >> strengthOfD;
riskRoll(strengthOfA, strengthOfD);
if (strengthOfA > strengthOfD)
cout << "Attacker Wins!\n";
else
cout << "Defender Wins!\n";
}
|