Untitled
unknown
c_cpp
10 months ago
2.9 kB
8
Indexable
#include "Antenna.h"
Antenna::Antenna(const CellPosition & antennaPosition):GameObject(antennaPosition)
{
}
void Antenna::Draw(Output * pOut) const
{
pOut->DrawAntenna(position);
}
void Antenna::Apply(Grid * pGrid, Player * pPlayer)
{
///TODO: Implement this function as mentioned in the guideline steps (numbered below) below
// == Here are some guideline steps (numbered below) to implement this function ==
// 1- Print a message "the antenna will decide the turn of players. Click to continue ..." and wait mouse click
{
// Get Output and Input interfaces
Output* pOut = pGrid->GetOutput();
Input* pIn = pGrid->GetInput();
int x, y;
// Ensure the antenna exists
// Print a message to notify the player
pOut->PrintMessage("The antenna will decide the turn of players. Click to continue...");
pIn->GetPointClicked(x, y); // Wait for the user to click
pOut->ClearStatusBar();
// Initialize players and distances
Player* player1 = pGrid->GetCurrentPlayer(); // Get first player
pGrid->AdvanceCurrentPlayer(); // Move to the second player
Player* player2 = pGrid->GetCurrentPlayer(); // Get second player
CellPosition player1Pos = player1->GetCell()->GetCellPosition();
CellPosition player2Pos = player2->GetCell()->GetCellPosition();
CellPosition antennaPos = this->GetPosition();
// Calculate distances for both players
int player1Distance = (player1Pos.VCell() > antennaPos.VCell()
? (player1Pos.VCell() - antennaPos.VCell())
: (antennaPos.VCell() - player1Pos.VCell())) +
(player1Pos.HCell() > antennaPos.HCell()
? (player1Pos.HCell() - antennaPos.HCell())
: (antennaPos.HCell() - player1Pos.HCell()));
int player2Distance = (player2Pos.VCell() > antennaPos.VCell())
? (player2Pos.VCell() - antennaPos.VCell())
: (antennaPos.VCell() - player2Pos.VCell()) +
(player2Pos.HCell() > antennaPos.HCell())
?
(player2Pos.HCell() - antennaPos.HCell())
: (antennaPos.HCell() - player2Pos.HCell());
// Determine the first player
Player * firstPlayer = nullptr;
if (player1Distance < player2Distance ||
(player1Distance == player2Distance && player1->GetPlayerNumber() < player2->GetPlayerNumber())) {
firstPlayer = player1;
}
else {
firstPlayer = player2;
}
// Notify the user about the first player
pOut->PrintMessage("Player " + to_string(firstPlayer->GetPlayerNumber()) + " will play first. Click anywhere to continue...");
pIn->GetPointClicked(x, y);
pOut->ClearStatusBar();
}
Antenna::~Antenna()
{
}
Editor is loading...
Leave a Comment