YAPOG
0.0.1
Yet Another Pokemon Online Game
Main Page
Related Pages
Namespaces
Classes
Files
File List
File Members
PokemonMoveSet.cpp
Go to the documentation of this file.
1
#include "
YAPOG/System/Error/Exception.hpp
"
2
#include "
YAPOG/Game/Factory/XmlObjectIDLoader.hpp
"
3
#include "
YAPOG/Game/Factory/ObjectFactory.hpp
"
4
#include "
YAPOG/Game/Pokemon/PokemonMoveSet.hpp
"
5
#include "
YAPOG/System/MathHelper.hpp
"
6
#include "
YAPOG/Game/Pokemon/Pokemon.hpp
"
7
8
namespace
yap
9
{
10
const
UInt8
PokemonMoveSet::DEFAULT_MOVE_NUMBER
= 0;
11
12
PokemonMoveSet::PokemonMoveSet
()
13
: moveSet_ (
Pokemon
::MAX_POKEMON_MOVE_NUMBER, nullptr)
14
, moveNumber_ (DEFAULT_MOVE_NUMBER)
15
{
16
}
17
18
PokemonMoveSet::PokemonMoveSet
(
const
PokemonMoveSet
& copy)
19
: moveSet_ (
Pokemon
::MAX_POKEMON_MOVE_NUMBER, nullptr)
20
, moveNumber_ (copy.moveNumber_)
21
{
22
for
(
int
i = 0; i <
Pokemon::MAX_POKEMON_MOVE_NUMBER
; i++)
23
{
24
if
(copy.
moveSet_
[i] !=
nullptr
)
25
moveSet_
[i] =
new
PokemonMove
(*copy.
moveSet_
[i]);
26
}
27
}
28
29
PokemonMoveSet::~PokemonMoveSet
()
30
{
31
for
(
int
i = 0; i <
Pokemon::MAX_POKEMON_MOVE_NUMBER
; i++)
32
{
33
if
(
moveSet_
[i] !=
nullptr
)
34
delete
moveSet_
[i];
35
}
36
}
37
38
// Getters
39
const
collection::Array<PokemonMove*>
&
40
PokemonMoveSet::GetMoves
()
const
41
{
return
moveSet_
; }
42
43
const
UInt8
PokemonMoveSet::GetMoveNumber
()
const
44
{
return
moveNumber_
; }
45
46
// Return a pointeur to check if there is a move or not
47
const
PokemonMove
*
PokemonMoveSet::GetMove
(
const
UInt8
& index)
const
48
{
return
moveSet_
[index]; }
49
50
void
PokemonMoveSet::AddMove
(
PokemonMove
* move,
const
UInt8
& index)
51
{
52
if
(index >=
moveSet_
.
Count
())
53
{
54
throw
yap::Exception
(
55
"Impossible to add this move, out of bound."
);
56
}
57
58
if
(
moveSet_
[index] !=
nullptr
)
59
ReplaceMove
(move, index);
60
else
61
{
62
moveSet_
[index] = move;
63
64
moveNumber_
++;
65
}
66
}
67
68
bool
PokemonMoveSet::AddMove
(
const
ID
& moveID)
69
{
70
for
(
int
i = 0; i < 4; i++)
71
{
72
if
(
moveSet_
[i] ==
nullptr
)
73
{
74
moveSet_
[i] =
new
PokemonMove
(moveID);
75
return
true
;
76
}
77
}
78
79
return
false
;
80
}
81
82
void
PokemonMoveSet::ReplaceMove
(
const
ID
& moveID,
UInt8
index)
83
{
84
if
(
moveSet_
[index] !=
nullptr
)
85
delete
moveSet_
[index];
86
87
moveSet_
[index] =
new
PokemonMove
(moveID);
88
}
89
90
void
PokemonMoveSet::ReplaceMove
(
PokemonMove
* move,
UInt8
index)
91
{
92
if
(
moveSet_
[index] !=
nullptr
)
93
delete
moveSet_
[index];
94
95
moveSet_
[index] = move;
96
}
97
98
}
YAPOG
src
YAPOG
Game
Pokemon
PokemonMoveSet.cpp
Generated on Mon Sep 17 2012 22:24:25 for YAPOG by
1.8.1.1