Question
I have a c++ code for a game where players play a basketball shooting game, who misses shots receive one letter from {H,O,R,S,E}, whoever receive
I have a c++ code for a game where players play a basketball shooting game, who misses shots receive one letter from {H,O,R,S,E}, whoever receive all letters loses. I have a code but I have to have 2 files to submit which are Game.cpp and Player.cpp . In the code I have, I will write below, do I need to separate it and paste the first half (which is from 'class Player' until 'int main') for Player.cpp file or do I need to write a new one ? And a header file which will be player.h.
Thank you.
#include
class Player { public: char * horse; = {'H','O','R','S','E'}; int count; Player() { horse = new char[5]; horse[0] = 'H'; horse[1] = 'O'; horse[2] = 'R'; horse[3] = 'S'; horse[4] = 'E'; count = 0; } void reset() { count = 0; } int shot() { return (rand() % 100 > 50); } char addHORSE() { return horse[count++]; } int isHORSE() { if (count == 5) return true; return false; } };
int main() {
char horse[] = { 'H', 'O', 'R', 'S', 'E' }; int i = 0; Player p1; Player p2; int done = 0; std::cout<<" Welcome to the CSCI 240 Game of Horse!"; while (true) { int p1_Hit = p1.shot(); int p2_Hit = p2.shot(); if (p1_Hit) std::cout << "Player #1: Hit Shot!" << endl; else std::cout << "Player #1: Missed Shot!" << endl;
if (p2_Hit) std::cout << "Player #2: Hit Shot!" << endl; else std::cout << "Player #2: Missed Shot!" << endl;
if (p1_Hit == p2_Hit) continue; if (p1_Hit) { char h = p1.addHORSE(); std::cout << "Player #1 Added an '" << h << "'" << endl; if (p1.isHORSE()) { std::cout << "Player 2 Wins :: Player 1 = HORSE" << endl; done = true; } } if (p2_Hit) { char h = p2.addHORSE(); std::cout << "Player #2 Added an '" << h << "'" << endl; if (p2.isHORSE()) { std::cout << "Player 1 Wins :: Player 2 = HORSE" << endl; done = true; } } if (done) { std::cout << "Would you like to play again (Y|N)? :"; string ch; std::cin >> ch; if (ch == "Y" || ch == "y") { p1.reset(); p2.reset(); done = false; continue; } else break; } } }
Step by Step Solution
There are 3 Steps involved in it
Step: 1
Get Instant Access to Expert-Tailored Solutions
See step-by-step solutions with expert insights and AI powered tools for academic success
Step: 2
Step: 3
Ace Your Homework with AI
Get the answers you need in no time with our AI-driven, step-by-step assistance
Get Started