// By a complete newbie, Derek Adam
// Version 1, any comments will be appreciated, please note I'm a noob to programming
#include <cstdlib>
#include <iostream>
#include <ctime>
#include <windows.h>
using namespace std;
void dice ();//dice game
void menu ();//menu duh
int u = 1; //upgrade dice max
int main()
{
menu ();
system("PAUSE");
return EXIT_SUCCESS;
}
void dice()
{
char answer[1];
srand((unsigned)time(0));
int hdice; //human dice
int cdice;//comp dice
int hlife = 5;//human life
int clife = 5;//comp life
do{
cout << "A dice rolling simulation....\n\n";
hdice = (rand()%6)+u;// random generator 1 is u so we can upgrade later
cdice = (rand()%6)+1;//comp "" ""
cout << "You:\t" <<hdice << endl;// what you rolled
Sleep(1000);
cout << "Comp:\t" <<cdice << endl;//comp "" ""
Sleep(1000);
if (hdice == cdice) // draw
{
cout << "Reroll, draw.\n";
}
else if(hdice>cdice) // we roll higher they lose a life
{
clife = clife - 1;
cout << "\tLives\n";
cout << "Computer lives: " << clife <<"\t\t "<< hlife << " Human lives\n";
Sleep(1000);
}
else// comp rolls higher we lose a life
{
hlife = hlife - 1;
cout << "\tLives\n";
cout << "Computer lives: " << clife <<"\t\t "<< hlife << " Human lives\n";
}
}while(hlife != 0 && clife != 0);
if (hlife>clife)//who wins?
{
char answer[1];
cout << "YOU \tWIN\n";
}
else
{
cout << "YOU \t LOSE\n";
}
cout << "Would you like to try again?\n";
cout << "y or n\n\n";
cin >> answer[1];
if (answer[1] == 'y')
{
dice();
}
else
{
menu();
}
}
void menu ()
{
char choice[1];
cout << "Welcome to the menu....";
cout << "Please select a choice!\n";
cout << "[d]ice game\t[q]uit\t[u]pgrade dice\n";//options
cin >> choice[1];
switch(choice[1])//Fun section messing with sleep and escape \b to generate typing text
{
case 'd':
dice();
break;
case 'u':
cout << "Now upgrading \n";
Sleep(1000);
cout << ".";
Sleep(1000);
cout << "..";
Sleep(1000);
cout <<"...";
Sleep(1000);
cout << "C";
Sleep(1000);
cout << "\bCO";
Sleep(1000);
cout << "\b\bCOM";
Sleep(1000);
cout << "\b\b\bCOMP";
Sleep(1000);
cout << "\b\b\b\bCOMPL";
Sleep(1000);
cout << "\b\b\b\b\bCOMPLE";
Sleep(1000);
cout << "\b\b\b\b\b\bCOMPLET";
Sleep(1000);
cout << "\b\b\b\b\b\b\bCOMPLETE";
Sleep(1000);
cout << "\b\b\b\b\b\b\b\bCOMPLETE!\n\n";
Sleep(1000);
u = u+1;
menu();
case 'q':
cin.get();
break;
}
}