Untitled
void Player::Move(Grid* pGrid, Command moveCommands[]) { int x, y; const int maxCommands = 5; Input* pIn = pGrid->GetInput(); Output* pOut = pGrid->GetOutput(); for (int i = 0; i < maxCommands; i++) { if (moveCommands[i] == NO_COMMAND) { break; } CellPosition currentPos = pCell->GetCellPosition(); CellPosition newPos = currentPos; switch (moveCommands[i]) { case MOVE_FORWARD_ONE_STEP: newPos.SetVCell(newPos.VCell() - 1); break; case MOVE_FORWARD_TWO_STEPS: newPos.SetVCell(newPos.VCell() - 2); break; case MOVE_FORWARD_THREE_STEPS: newPos.SetVCell(newPos.VCell() - 3); break; case MOVE_BACKWARD_ONE_STEP: newPos.SetVCell(newPos.VCell() + 1); break; case MOVE_BACKWARD_TWO_STEPS: newPos.SetVCell(newPos.VCell() + 2); break; case MOVE_BACKWARD_THREE_STEPS: newPos.SetVCell(newPos.VCell() + 3); break; case ROTATE_CLOCKWISE: RotateClockwise(); continue; case ROTATE_COUNTERCLOCKWISE: RotateCounterClockwise(); continue; default: continue; } if (!newPos.IsValidCell()) { pOut->PrintMessage("invalid move"); pIn->GetPointClicked(x, y); return; } pGrid->UpdatePlayerCell(this, newPos); if (i < maxCommands - 1 && moveCommands[i + 1] != NO_COMMAND) { pOut->PrintMessage("click anywhere to execute next command"); pIn->GetPointClicked(x, y); } } Cell* finalCell = pGrid->GetCell(pCell->GetCellPosition()); GameObject* obj = finalCell->GetGameObject(); if (obj != nullptr) { obj->Apply(pGrid, this); } }
Leave a Comment