Archived

This topic is now archived and is closed to further replies.

C++ text game question

This topic is 5816 days old which is more than the 365 day threshold we allow for new replies. Please post a new topic.

If you intended to correct an error in the post then please contact us.

Recommended Posts

This deals with c++... I have a text deathmatch game (ya I think I invented that genre) and I have it set up with the "do" keyword so that your turn repeats until enemies = 0. You enter your move and it changes the variables that represent your x and y coordinates. When the "do" loop repeats, the xcoord and ycoord variables are set back to 2, as they were originally, instead of changing to correspond with your previous move. This is the code (the text with all the symbols is the map): do { enemies = 2; Enemy Enemy1; Enemy Enemy2; Enemy1.HP = 80; Enemy1.xcoord = 4; Enemy1.ycoord = 5; Enemy2.HP = 80; Enemy2.xcoord = 9; Enemy2.ycoord = 5; Player1.xcoord = 2; Player1.ycoord = 2; cout << "\n"; cout << "\n"; cout << "\f = Enemy\n"; cout << "0 = Defeated Enemy\n"; cout << "\n"; cout << " x-axis\n"; cout << " 1 2 3 4 5 6 7 8 9 10\n"; cout << " _______ 1 y\n"; cout << " / \\ 2 a\n"; cout << "/ \\ 3 x\n"; cout << "| |_______ 4 i\n"; cout << "\\ \f ___ \f | 5 s\n"; cout << " \\________/ \\____/ 6\n"; cout << "\n"; cout << "Your stats:\n"; cout << "X coordinate: " << Player1.xcoord << "\n"; cout << "Y coordinate: " << Player1.ycoord << "\n"; cout << "HP: " << Player1.HP << "\n"; cout << "Armor: " << Player1.Armor << "\n"; cout << "Weapon dmg: " << Player1.Weapon << "\n"; cout << "Grenades: " << Player1.Grenades << "\n"; cout << "Type the number for your action-\n"; cout << "Move up: 1 Move down: 2 Move left: 3 Move right: 4\n"; cin >> move; if (move == 1) { Player1.ycoord = Player1.ycoord - 1; } if (move == 2) { Player1.ycoord = Player1.ycoord + 1; } if (move == 3) { Player1.xcoord = Player1.xcoord - 1; } if (move == 4) { Player1.xcoord = Player1.xcoord + 1; } } while (enemies > 0); Any suggestions?

Share this post


Link to post
Share on other sites