-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathGame_Run.cpp
More file actions
143 lines (118 loc) · 4.02 KB
/
Copy pathGame_Run.cpp
File metadata and controls
143 lines (118 loc) · 4.02 KB
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
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
//
// Game_Run.cpp
//
// Created by MAQ on 07/08/25.
//
#include "pokemon_game.hpp"
// constructor to initialize the game with all Pokemon data
RunGame::RunGame(string playerName, string aiName ) : player(playerName), ai(aiName)
{
allPokemons = CreatePokedex::createPokemonList(); // now all pokemons have been created
}
// function to start the game
void RunGame::start()
{
srand(static_cast< unsigned int >(time(0)));
cout << "Welcome to Pokemon Battle Simulator!\n";
// Team selection phase
displayPokemonSelection();
selectPlayerTeam();
selectAITeam();
// Display teams
cout << "\nYour team:\n";
player.displayTeam();
cout << "\nAI's team:\n";
ai.displayTeam();
// Battle phase
battle();
}
// function to display Pokemon selection menu
void RunGame::displayPokemonSelection()
{
cout << "Choose 4 Pokemons for your team:\n";
for (size_t i = 0; i < allPokemons.size(); i++)
{
cout << i+1 << ". " << allPokemons[i].getName()
<< " (Type: " << TypeToString(allPokemons[i].getType()) << ")\n";
}
}
// function to select player's team
void RunGame::selectPlayerTeam()
{
vector<int> selected;
// while loop
while (selected.size() < 4)
{
int choice;
cout << "Select Pokemon " << selected.size()+1 << ": ";
cin >> choice;
cin.ignore();
// Input validation
if (choice < 1 || choice > allPokemons.size())
{
cout << "Invalid choice. Please enter a number between 1 and "
<< allPokemons.size() << ".\n";
continue;
}
// Add selected Pokemon
Pokemon pokemon = allPokemons[choice-1]; // makes a copy of the Pokemon
// Get nickname
string nickname;
cout << "Enter nickname for " << pokemon.getName() << ": ";
getline(cin,nickname);
pokemon.setNickName(nickname);
player.addPokemon(pokemon); // stores the copy in the team
selected.push_back(choice);
/*note: by implementing this copy than refering , ensures that the your and AI pokemon are different, thats why i specifically created a class which holds all the pokemon in like a containier*/
}
}
// function to select AI's team randomly
void RunGame::selectAITeam()
{
vector<int> selected;
while (selected.size() < 4)
{
int choice = rand() % allPokemons.size() + 1;
if (find(selected.begin(), selected.end(), choice) == selected.end()) // itrator we did in last class
{
ai.addPokemon(allPokemons[choice-1]);
selected.push_back(choice);
}
}
}
// function to handle the battle sequence
void RunGame::battle()
{
TextForBattle::displayBattleStart(player, ai);
// while who ever has a usuable pokemon
while (player.hasUsablePokemon() && ai.hasUsablePokemon())
{
// Display current status
cout << "\n----------------------------------------\n";
player.getFirstUsablePokemon().displayStatus();
ai.getFirstUsablePokemon().displayStatus();
cout << "----------------------------------------\n";
// Determine turn order based on speed
if (player.getFirstUsablePokemon().getSpeed() >= ai.getFirstUsablePokemon().getSpeed())
{
cout << "\n----------------------------------------\n";
BattleTurn::playerTurn(player, ai);
if (ai.hasUsablePokemon())
{
BattleTurn::aiTurn(player, ai);
}
cout << "\n----------------------------------------\n";
}
else
{
cout << "\n----------------------------------------\n";
BattleTurn::aiTurn(player, ai);
if (player.hasUsablePokemon())
{
BattleTurn::playerTurn(player, ai);
}
cout << "\n----------------------------------------\n";
}
}
TextForBattle::displayBattleEnd(player, ai);
}