// Jan-Ken-Pon of DOOM by Dopefish
#include <iostream>
#include <ctime>
#include <stdlib.h>
#include <conio.h>
using namespace std;
void score(int iW, int iL, int iT) // Function for writing out the score
{
cout << "Win: " << iW << " Lost: " << iL << " Tie: " << iT << endl;
}
int main ()
{
int iFool; // Random start message
int iComp; // Computer choice
int iPlay; // Player choice
int iLost; // Lost counter
int iWin; // Win counter
int iTie; // Tie counter
bool bGame; // Game status
bGame = 1; // Game is active
srand (time(0)); // Random seed from system clock
cout << "Welcome to Jan-Ken-Pon of DOOM!" << endl;
while (bGame == 1)
{
iComp = (1 + (rand() % 3)); // Comp choice on random (1=Rock, 2=Paper, 4=Scissor)
if (iComp == 3)
{
iComp = 4; // 3 is changed to 4 (Scissor) for calc purposes
}
iFool = (rand() % 3); // Random start message
switch(iFool)
{
case 1:
cout << "I'll cut your throat with my scissor!\n" << endl;
break;
case 2:
cout << "You'll eat my rock!\n" << endl;
break;
default:
cout << "I'm going to slice you up with my paper!\n" << endl;
break;
}
cout << "What are you going to do:" << endl;
cout << "1. (Rock)\n2. (Paper)\n3. (Scissor)\n4. (Give up!)" << endl;
cin >> iPlay;
cout << endl;
switch(iPlay)
{
case 1:
cout << "Rock" << endl;
break;
case 2:
cout << "Paper" << endl;
break;
case 3:
cout << "Scissor" << endl;
iPlay = 4; // 3 is changed to 4 for calc purposes
break;
case 4:
cout << "You run away in to the distance..." << endl;
bGame = 0;
break;
default:
cout << "That wasn't an option sucker!" << endl;
cout << "I don't play with cheaters..." << endl;
bGame = 0;
break;
}
if (bGame == 1)
{
switch(iComp)
{
case 1:
cout << "Rock\n" << endl;
break;
case 2:
cout << "Paper\n" << endl;
break;
case 4:
cout << "Scissor\n" << endl;
break;
}
}
iPlay = iPlay - iComp; // Win, Tie or Loose check (1=Rock, 2=Paper, 4=Scissor)
switch(iPlay)
{
case -3: // Rock vs Scissor
iWin++;
score(iWin, iLost, iTie);
break;
case -2: // Paper vs Scissor
iLost++;
score(iWin, iLost, iTie);
break;
case -1: // Rock vs Paper
iLost++;
score(iWin, iLost, iTie);
break;
case 0: // Both picked the same
iTie++;
score(iWin, iLost, iTie);
cout << "Hmm... that was strange... ";
break;
case 1: // Paper vs Rock
iWin++;
score(iWin, iLost, iTie);
break;
case 2: // Scissor vs Paper
iWin++;
score(iWin, iLost, iTie);
break;
case 3: // Scissor vs Rock
iLost++;
score(iWin, iLost, iTie);
break;
}
getch();
} // end of while loop
return 0;
} // end of main
Saturday, October 23, 2010
Coding skill +1 (Jan-Ken-Pon of DOOM in C++)
More code from over half a decade ago!
Subscribe to:
Post Comments (Atom)
No comments:
Post a Comment