-
Notifications
You must be signed in to change notification settings - Fork 0
/
DeleteGameObjectAction.cpp
43 lines (38 loc) · 1.31 KB
/
DeleteGameObjectAction.cpp
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
30
31
32
33
34
35
36
37
38
39
40
41
42
43
#include "DeleteGameObjectAction.h"
#include "Action.h"
#include "Grid.h"
#include "Ladder.h"
#include "Snake.h"
DeleteGameObjectAction::DeleteGameObjectAction(ApplicationManager* pApp) : Action(pApp)
{
}
void DeleteGameObjectAction::ReadActionParameters()
{
pManager->GetGrid()->GetOutput()->PrintMessage("Please select object to delete ");
ObjectToDeletePos = pManager->GetGrid()->GetInput()->GetCellClicked();
}
void DeleteGameObjectAction::Execute()
{
ReadActionParameters();
Cell* deleteCell;
deleteCell = pManager->GetGrid()->GetCellWithPos(ObjectToDeletePos);
if (pManager->GetGrid()->GetCellWithPos(ObjectToDeletePos)->GetGameObject()==NULL)
{
pManager->GetGrid()->GetOutput()->PrintMessage("Error Cell doesn't have object");
return;
}
if (deleteCell->HasLadder())
{
pManager->GetGrid()->GetCellWithPos(deleteCell->HasLadder()->GetEndPosition())->setisEndCell(false);
}
else if (deleteCell->HasSnake())
{
pManager->GetGrid()->GetCellWithPos(deleteCell->HasSnake()->GetEndPosition())->setisEndCell(false);
}
delete pManager->GetGrid()->GetCellWithPos(ObjectToDeletePos)->GetGameObject();
pManager->GetGrid()->RemoveObjectFromCell(ObjectToDeletePos);
pManager->GetGrid()->GetOutput()->ClearStatusBar();
}
DeleteGameObjectAction::~DeleteGameObjectAction()
{
}