forked from rtpHarry/Sokoban
-
Notifications
You must be signed in to change notification settings - Fork 0
/
MoveList.cpp
123 lines (101 loc) · 2.67 KB
/
MoveList.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
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
#include ".\movelist.h"
//////////////////////////////////////////////////////////////////////////
// global functions for a MoveEvent
//////////////////////////////////////////////////////////////////////////
// Get the grid location of offset OffsetAmt in direction Direction
EventLocation GetOffsetLocation(MoveEvent Event, int OffsetAmt)
{
return GetOffsetLocation(Event.Location, Event.Direction, OffsetAmt);
}
// Get the grid location of offset OffsetAmt in direction Direction
EventLocation GetOffsetLocation(EventLocation SourceLocation, EventDirection Direction, int OffsetAmt)
{
EventLocation OffsetValue;
EventLocation ReturnLocation;
// first work out amount to adjust
switch(Direction)
{
case DIR_NORTH:
OffsetValue.x = -OffsetAmt;
OffsetValue.y = 0;
break;
case DIR_SOUTH:
OffsetValue.x = +OffsetAmt;
OffsetValue.y = 0;
break;
case DIR_EAST:
OffsetValue.x = 0;
OffsetValue.y = +OffsetAmt;
break;
case DIR_WEST:
OffsetValue.x = 0;
OffsetValue.y = -OffsetAmt;
break;
}
// work out grid location
ReturnLocation.x = SourceLocation.x + OffsetValue.x;
ReturnLocation.y = SourceLocation.y + OffsetValue.y;
// pass back
return ReturnLocation;
}
//////////////////////////////////////////////////////////////////////////
// end of global functions for MoveEvent
//////////////////////////////////////////////////////////////////////////
// start of movelist class
//////////////////////////////////////////////////////////////////////////
MoveList::MoveList(void)
{
}
MoveList::~MoveList(void)
{
}
// Add an event to the event stack
void MoveList::AddEvent(MoveEvent NewEvent)
{
// only add if trackable event
switch(NewEvent.Type)
{
case MOVE_EVENT_STEP:
case MOVE_EVENT_PUSHTOEMPTY:
case MOVE_EVENT_PUSHTOWALL:
case MOVE_EVENT_PUSHTOTARGET:
case MOVE_EVENT_PUSHFROMTARGET:
case MOVE_EVENT_PUSHBETWEENTARGETS:
// trackable event
_Events.push_back(NewEvent);
break;
default:
// player did not actually move
return;
}
}
void MoveList::AddEvent(EventType type, EventLocation loc, EventDirection dir)
{
MoveEvent NewEvent;
NewEvent.Type = type;
NewEvent.Location = loc;
NewEvent.Direction = dir;
AddEvent(NewEvent);
}
// Remove the last event added and return it for further use
MoveEvent MoveList::RemoveEvent(void)
{
MoveEvent ReturnEvent;
// catch if no events to remove!
if(_Events.empty())
{
// MoveEvent is initialized by default to an empty event so return it
return ReturnEvent;
}
// grab last event
ReturnEvent = _Events.back();
// delete last event added to stack
_Events.pop_back();
// return grabbed event
return ReturnEvent;
}
// Reset the data in MoveList
void MoveList::Reset(void)
{
_Events.clear();
}