// 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
Showing posts with label coding. Show all posts
Showing posts with label coding. Show all posts
Saturday, October 23, 2010
Coding skill +1 (Jan-Ken-Pon of DOOM in C++)
More code from over half a decade ago!
Coding Skill +1 (Zombie mower in C++)
Found some code I did over half a decade ago :)
// Zombie mower by Dopefish
#include <iostream>
#include <iodos.h>
#include <conio.h>
using namespace std;
int main()
{
dos_console();
int zombies = 1;
cout << "How many do you see standing on the lawn?" << endl << "> ";
cin >> zombies;
while (zombies > 0)
{
cout << zombies << " zombies left under the moon" << endl;
cout << zombies << " zombies is going to be mown" << endl;
cout << "If one of em' happens to be mown," << endl;
zombies--;
cout << "then it's only " << zombies << " left on the lawn" << endl << endl;
}
if (zombies < 1)
{
cout << zombies << " zombies left under the moon" << endl;
cout << zombies << " zombies is going to be mown" << endl;
cout << "There are no more zombies left to mown..." << endl;
}
getch();
return(0);
}
Subscribe to:
Posts (Atom)