002
12.12.2005, 01:08 Uhr
Leopard
|
der code ist:
C++: |
#include <iostream> #include <stdlib> #include <time>
#define WINSCORE 4 // Brunnen(b) -> Stein(s) -> Shere -> Papier char PickRandomOption (void) { char option; srand (time (NULL) ); int value = rand()%4; switch (value) { case 0: option= 'b'; break; case 1: option= 's'; break; case 2: option= 'x'; break; case 3: option= 'p'; break; } return option; } int WhoWins (char a, char b) { switch (a) { case 'b': if (b== 's') return 1; else if ( b== 'x' || b== 'p') return 2; else return 0; case 's': if (b== 'x') return 1; else if (b== 'p' || b== 'b') return 2; else return 0; case 'x': if (b== 'p') return 1; else if (b== 'b' || b== 's') return 2; else return 0; case 'p': if (b== 'b') return 1; else if (b== 's' || b== 'x') return 2; else return 0; default: return -1; } } int main () { char you, me; int mypoints = 0; int yourpoints = 0; int winner; do { // prompt user. cout << "\nEnter b, s, x oder p " ; // Problem!! cout << " (b=Brunnen, s=stone, x=scissors, p=paper): "; cin >> you; // Problem!! //decide computer's option and say it. me = PickRandomOption (); cout << "I say: " << me << "\n"; //check who is the winner. winner = WhoWins (you, me); //show appropiate message. if (winner ==0) cout << "Tied\n"; else if (winner ==1) { cout << "You win\n" ; yourpoints++; } else if (winner ==2) { cout << "I win\n"; mypoints++; } //show current scoreboar. cout << "POINTS: You:" << yourpoints; cout << " Me:" << mypoints << "\n"; } while (yourpoints < WINSCORE&&mypoints<WINSCORE); if (yourpoints > mypoints) cout << "You win the competition!\n"; else cout << "I win the competition!\n"; return 0; }
|
Bearbeitung von 0xdeadbeef: |
cpp-tags. Nächstes mal selbst machen.
|
Dieser Post wurde am 12.12.2005 um 10:00 Uhr von 0xdeadbeef editiert. |