YAPOG  0.0.1
Yet Another Pokemon Online Game
PokemonMoveSet.cpp
Go to the documentation of this file.
7 
8 namespace yap
9 {
11 
13  : moveSet_ (Pokemon::MAX_POKEMON_MOVE_NUMBER, nullptr)
14  , moveNumber_ (DEFAULT_MOVE_NUMBER)
15  {
16  }
17 
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 
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
41  { return moveSet_; }
42 
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 
91  {
92  if (moveSet_[index] != nullptr)
93  delete moveSet_[index];
94 
95  moveSet_[index] = move;
96  }
97 
98 }