C++ text game question

Started by
2 comments, last by BioSquirrel 22 years, 3 months ago
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?
Advertisement
your do...while wraps the entire thing, including the initialization of the enemies and player position... put the "do {" right before the first cout...

--- krez (krezisback@aol.com)
--- krez ([email="krez_AT_optonline_DOT_net"]krez_AT_optonline_DOT_net[/email])
Doh! I didn''t even notice that thanks a lot!
Doh! I didn''t even notice that thanks a lot!

This topic is closed to new replies.

Advertisement