Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- //Darts Exercise 1, a simple game of 301
- #include <iostream>
- #include <time.h>
- #include <ctime>
- #include <conio.h>
- #include <windows.h>
- #include <time.h>
- #include <ctype.h>
- using namespace std;
- int sidscore=301;
- int joescore=301;
- int joeselfishmeter=0;
- int sidselfishmeter=0;
- int turn_number=1;
- //Define States & Inputs
- enum current_state {sidthrew, joethrew, neutral};
- enum current_input {sidthrow, joethrow, No_input};
- current_state state = neutral;
- //Initialise Display
- void Init_Graphics(void);
- inline void Set_Color(int fcolor, int bcolor);
- inline void Draw_String(int x,int y, char *string);
- void run_fsm();
- void display_welcome_screen();
- void display_neutral();
- void display_sidthrew();
- void display_joethrew();
- void main(){
- run_fsm();
- }
- // Local declarations
- void run_fsm(){
- state = neutral;
- current_input input = No_input;
- display_welcome_screen();
- while (1){
- switch (state){
- case neutral: display_neutral(); break;
- case sidthrew: display_sidthrew(); break;
- case joethrew: display_joethrew(); break;
- }
- Sleep(800);
- if(joeselfishmeter < 1){
- input = joethrow;
- }
- if(sidselfishmeter < 1){
- input = sidthrow;
- }
- if(input == sidthrow || input == joethrow){
- switch (state) {
- case neutral: if(input == sidthrow){
- state = sidthrew;
- }
- if(input == joethrow){
- state = joethrew;
- }
- break;
- } // end switch
- }// end if
- } // end while
- } // end run_fsm()
- void display_welcome_screen(){
- cout << "Joe vs Sid, Task 1" << endl << endl;
- Sleep(1200);
- cout << "301 Darts Simulation" << endl << endl;
- Sleep(1500);
- cout << "Press return to start the simulation" << endl << endl;
- cin.get();
- }
- void display_neutral(){
- if ((sidscore * joescore)>0){
- }
- if (sidscore == 0){
- cout << " Congratulations, Sid has won!" << endl;
- joeselfishmeter=1;
- sidselfishmeter=1;
- }
- if (joescore ==0){
- cout << " Congratulations, Joe has won!" << endl;
- joeselfishmeter=1;
- sidselfishmeter=1;
- }
- };
- void display_sidthrew(){
- srand ( time(NULL) );
- if(sidselfishmeter<1){
- if(sidscore >51){
- if((rand()%100) < 81){
- cout << "Sid Aims For The Darts Board" << endl;
- sidscore=sidscore-20;
- cout << "Turn Number: " << turn_number << " Direct Hit, Nice One! Sid's Score is now: " << sidscore << " Now It's Joe's Turn" << endl;
- sidselfishmeter=1;
- joeselfishmeter=0;
- }
- if((rand()%100) > 80){
- cout << "Sid Aims For The Darts Board" << endl;
- sidscore=sidscore-(rand()%20);
- cout << "Turn Number: " << turn_number << " Missed the target, but you still got a nice hit. Sid's score is now: " << sidscore << " Now It's Joe's Turn" << endl;
- sidselfishmeter=1;
- joeselfishmeter=0;
- }
- }
- if(sidscore <51){
- if((rand()%100) < 51){
- cout << "Turn Number: " << turn_number << " Sid Aims For The Bullseye!" << endl;
- cout << "Congratulations, Sid has won!" << endl;
- joeselfishmeter=1;
- sidselfishmeter=1;
- }
- }
- }
- state = neutral;
- display_neutral();
- turn_number = turn_number+1;
- };
- void display_joethrew(){
- srand ( time(NULL) );
- if(joeselfishmeter<1){
- if(joescore >51){
- if((rand()%100) < 81){
- cout << "Joe Aims For The Darts Board" << endl;
- joescore=joescore-20;
- cout << "Turn Number: " << turn_number << " Direct Hit, Nice One! Joe's Score is now: " << joescore << " Now It's Sid's Turn" << endl;
- sidselfishmeter=0;
- joeselfishmeter=1;
- }
- if((rand()%100) > 80){
- cout << "Joe Aims For The Darts Board" << endl;
- joescore=joescore-(rand()%20);
- cout << "Turn Number: " << turn_number << " Missed the Target, but still a nice hit. Joe's score is now " << joescore << " Now It's Sid's Turn" << endl;
- sidselfishmeter=0;
- joeselfishmeter=1;
- }
- }
- if(joescore <51){
- if((rand()%100) < 51){
- cout << "Joe Aims For The Bullseye!" << endl;
- cout << "Turn Number: " << turn_number << " Congratulations, Joe has won!" << endl;
- joeselfishmeter=1;
- sidselfishmeter=1;
- }
- }
- }
- state = neutral;
- display_neutral();
- };
Add Comment
Please, Sign In to add comment