Question
Is there any other way to write this code without bool ? This is a game where it simulates players shooting basketballs, player who collects
Is there any other way to write this code without "bool" ? This is a game where it simulates players shooting basketballs, player who collects the letters of "horse" loses.
#include
using namespace std;
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; } bool shot(){ return (rand()%100 >50); } char addHORSE(){ return horse[count++]; } bool isHORSE(){ if(count==5) return true; return false; } };
int main(){
char horse[] = {'H','O','R','S','E'}; int i=0; Player p1; Player p2; bool done = false; while(true){ bool p1_Hit = p1.shot(); bool p2_Hit = p2.shot(); if(p1_Hit) cout<<"Player #1: Hit Shot!"< if(p2_Hit) cout<<"Player #2: Hit Shot!"< if(p1_Hit==p2_Hit) continue; if(p1_Hit){ char h = p1.addHORSE(); cout<<"Player #1 Added an '"<
Step by Step Solution
There are 3 Steps involved in it
Step: 1
Get Instant Access with AI-Powered 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