Question
I need help writing this C++ Rock, Paper, Scissors program. My teacher will be grading harshly on this program and would be judging on neatness and clarity as well.
Overview:
Use object oriented programming to develop a game application that plays the children’s game of rock, paper, scissors. The user enters a letter indicating his or her choice. When a choice is entered the r and function from is used to pick a value in the range of 1 through 3, with 1 corresponding to roc, 2 corresponding to paper, and 3 corresponding to scissors. The computers choice is compared to the users choice according to these rules: rock breaks scissors, scissors cut paper, paper covers rock. Choices that match are considered ties. Output a count of the sins by the user and the computer, and of the ties. The application ends when the user enters a invalid choice.
Explanation / Answer
#include #include #include //------------------------------------------------------------------------------- using namespace std; //------------------------------------------------------------------------------- enum choices { ROCK, SPOCK, PAPER, LIZARD, SCISSORS, MX_C }; enum indexes { PLAYER, COMPUTER, DRAW }; //------------------------------------------------------------------------------- class stats { public: stats() : _draw( 0 ) { ZeroMemory( _moves, sizeof( _moves ) ); ZeroMemory( _win, sizeof( _win ) ); } void draw() { _draw++; } void win( int p ) { _win[p]++; } void move( int p, int m ) { _moves[p][m]++; } int getMove( int p, int m ) { return _moves[p][m]; } string format( int a ) { char t[32]; wsprintf( t, "%.3d", a ); string d( t ); return d; } void print() { string d = format( _draw ), pw = format( _win[PLAYER] ), cw = format( _win[COMPUTER] ), pr = format( _moves[PLAYER][ROCK] ), cr = format( _moves[COMPUTER][ROCK] ), pp = format( _moves[PLAYER][PAPER] ), cp = format( _moves[COMPUTER][PAPER] ), ps = format( _moves[PLAYER][SCISSORS] ), cs = format( _moves[COMPUTER][SCISSORS] ), pl = format( _moves[PLAYER][LIZARD] ), cl = format( _moves[COMPUTER][LIZARD] ), pk = format( _moves[PLAYER][SPOCK] ), ck = format( _moves[COMPUTER][SPOCK] ); system( "cls" ); cout