I think I'm still really confused with the syntax for vectors |
You were doing fine with vectors in your poker assignment.
I added istream eof(); to the Floor class |
As I said before, a Floor is not an istream. There is no such thing as an eof() condition on a floor object.
Line 6: I really don't understand what you're trying to do with this loop. Per your comment, there is no reason to read in Floor. Presumably, you've already read in all three floors via the Game::Read function I already provided. Once you've read in the three floors, you have them in memory. There is no reason to read them in again. You're not reading them here, but you're calling eof() as if you were.
Lines 8-13: A couple of problems here:
1) You're looping through every row and column and trying to push a Floor onto the characters array.
2) sizeof(*m_floor) makes no sense. This tells you how many bytes are in a Floor object. The number of bytes in a Floor object should not be your loop limit.
3) You're trying to push a floor. A floor is not a class derived from Character.
4) m_floor is an array, not a single instance.
lines 15-20: Again, you're trying to search a vector you haven;t populated yet.
Line 24: You're trying to replace an object derived from Character with a space. Not a valid operation.
Lines 27-28: Right idea. A few problems though.
1) You need to iterate through alll the tiles of a floor. There may be multiple ghosts.
2) tiles is a private member of floor, so you can't access tiles directly. You need a getter. See code below.
3) You're trying to push ghost, but ghost is not defined.
Lne 21: Looks like an extra }
Line 53: player is not defined. You need to pass it in as an argument (by reference).
Line 54: return is in the wrong place. Should be after line 55.
Line 59: x and y have gone out of scope (no longer defined).
C++ does not support an implicit left hand side expression (|| 'P').
There is no need for a condition here. If you get here, you're in trouble.
|
raise std::exception ("Entrance not found");
|
Line 73: legal_move is a member of Flloor, not Player.
Lines 78-79,82: tiles[][] is not a member of Player.
Line 82: You can't test tiles[x][y] equal to 'K' here because you just overlaid tiles[x][y] with a space at line 79. You're using the assignment operator (=) here, not the equality operator (==).
Line 91: You need to do a cin here to get the character.
Line 106: You need a default case in the event the user typed something other than WASD.
Line 107: You're missing a } and the
while
condition of the do statement.
I feel like I'm just going in circles with my populateMaze function.
|
Here's my take on enter_floor, leave_floor, and populate_maze.
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29
|
void Game::enter_floor (Floor & floor) // We've entered a new floor
{ m_curr_floor = & floor; // Save pointer to current floor
for (int r=0; r<FLOOR::ROWS; r++) // Assumes ROWS is public
for (int c=0; c<FLOOR::COLS; c++) // Ditto for COLS
{ if (floor.get_tile(r,c) == 'G')
{ Ghost ghost (r,c); // Ghost has a constructor that takes x and y
characters.push_back (ghost);
}
}
}
void Game::leave_floor ()
{ // Iterate through characters vector and remove any ghosts
}
void Game::populateMaze ()
{ Player player;
Read (); // Read in the floors (in case you haven't already done this)
m_floor[0].place_player (); // Place the player at the entrance of first floor
characters.push_back (player); // Add player to characters vector
enter_floor (m_floor[0]); // Scan for ghosts
}
void Floor::ladder_up (Game & game)
{ game.leave_floor (*this); // Remove ghosts from characters vector
game.enter_floor (*this[1]); // Scan next floor for ghosts and add to characters
// Player's x and y stay the same, just on the next floor
}
|
Lines 23,26: Don't use the m_ prefix here. m_ indicates variable is a member of the class. These are arguments.
Would you mind posting the patterns for floorB and floorC please?