So I'm struggling with a game that I made in class, its call the Game of Nim. Anyway, there are a number of objects in the game. What I'm struggling with is how to make the game print out a visual character x number of objects.
Something like:
There are 8 objects left.
########
There are 5 objects left.
#####
etc.
I'm suppose to do this with a for loop. So far all I have been able to get is the number of objects the game starts with and then it just messes up the rest of the game.
So I'm back to square one... Any help? Suggestions? I'm really new to this.
I know the code is probably a mess, I haven't had the time to clean it up yet as I was in hurry and I just went with things that I knew worked.
// The game of Nim
#include<iostream>
#include<cstdlib>
usingnamespace std;
int game();
int main() {
int num_objects = 23;
int current_player = 1;
int move;
double y;
double n;
char answer;
cout << " Luke_Lyon " << endl;
cout << " Assignment_#1 " << endl;
cout << " Section_#2 " << endl << endl;
cout << " The Game of NIM" << endl << endl;
cout << " Remove 1-4 objects, try to force me to remove the last one." << endl << endl;
int num_objects = 23;
int current_player = 1;
int move;
double y;
double n;
char answer;
cout << " Luke_Lyon " << endl;
cout << " Assignment_#1 " << endl;
cout << " Section_#2 " << endl << endl;
cout << " The Game of NIM" << endl << endl;
cout << " Remove 1-4 objects, try to force me to remove the last one." << endl << endl;
do {
game();
cout << "How about another game? y/n" << endl;
cin >> answer;
cin.ignore();
cout << "\n";
}
while (answer=='y');
cout << "Thanks for entertaining me!";
cin.get();
}
int game(){
int num_objects = 23;
int current_player = 1;
int move;
do { // beginning of the game loop
cout << num_objects << " ObJeCtS LeFt!" << endl;
if (current_player == 1) { // user's move
do {
cout << "It's your move buddy: ";
cin >> move;
} while (move < 1 || move > 4 || move > num_objects);
} else { // computer's move
do {
if (current_player != 1 && num_objects == 4) move == 3;
if (current_player != 1 && num_objects == 3) move == 2;
if (current_player != 1 && num_objects == 2) move == 1;
move = 1 + rand() % 4;
} while (move < 1 || move > 4 || move > num_objects);
cout << "I burned " << move << endl;
if (num_objects == 22) cout << "We're still in the early stages of play, folks!" << endl;
if (num_objects == 21) cout << "We're still in the early stages of play, folks!" << endl;
if (num_objects == 20) cout << "We're still in the early stages of play, folks!" << endl;
if (num_objects == 19) cout << "We're still in the early stages of play, folks!" << endl;
if (num_objects == 18) cout << "We are really getting into this game now!" << endl;
if (num_objects == 17) cout << "We are really getting into this game now!" << endl;
if (num_objects == 16) cout << "We are really getting into this game now!" << endl;
if (num_objects == 15) cout << "I'm betting on User 1 folks, what about you?" << endl;
if (num_objects == 14) cout << "I'm betting on User 1 folks, what about you?" << endl;
if (num_objects == 13) cout << "I'm betting on User 1 folks, what about you?" << endl;
if (current_player != 1 && num_objects == 6) cout << "Uh-oh, the computer's been known to make a mistake at this poi$
if (current_player != 1 && num_objects == 5) cout << "Uh-oh, the computer's been known to make a mistake at this poi$
if (current_player != 1 && num_objects == 4) cout << "Uh-oh, the computer's been known to make a mistake at this poi$
if (current_player == 1 && num_objects == 4) cout << "This is it folks. User 1 could win it all right here!" << endl;
if (current_player == 1 && num_objects == 3) cout << "This is it folks. User 1 could win it all right here!" << endl;
if (current_player == 1 && num_objects == 2) cout << "This is it folks. User 1 could win it all right here!" << endl;
if (current_player == 1 && num_objects == 1) cout << "This is it folks. User 1 could win it all right here!" << endl$
}
num_objects = num_objects - move; // adjust objects
current_player = (current_player + 1) % 2; // adjust turn
} while (num_objects > 0); // end of the game loop
cout << "User " << current_player << " YOU ARE THE WINNER!!!" << endl;
}
Ohhh lol !
I thought those '#' were just to aesthetically please my eyes :p hahaha
1 2 3 4 5
cout << "There are " << num_objects << " objects remaining." << endl;
for(int i=0; i< num_objects ; i++) //the index may be off by 1 depending on ur code
{
cout << "#";
}