-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathdelete_player_from_database.cpp
More file actions
58 lines (51 loc) · 1.24 KB
/
Copy pathdelete_player_from_database.cpp
File metadata and controls
58 lines (51 loc) · 1.24 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
#include "functions_definitions.h"
#include "conio.h"
#include <iostream>
// Modules for sleep_for function
#include <thread>
#include <chrono>
bool min(PlayersDatabase* database)
{
clrscr();
if (database->number_of_players == 0)
{
gotoxy(1, 1);
std::cout << "Sorry, but we can't remove another player.";
std::cout << "\nCurrently we don't have any players inside our database, going back...";
// Sleep for 2 seconds
std::this_thread::sleep_for(std::chrono::seconds(2));
return true;
}
return false;
}
void delete_player_from_database(PlayersDatabase* d)
{
if (min(d))
return;
gotoxy(1, 1);
std::cout << "Give index of a player to be removed: ";
int index;
index = getche();
index -= 48;
if (index > d->number_of_players || index < 0)
{
std::cout << "\nWrong index value, going back...";
// Sleep for 2 seconds
std::this_thread::sleep_for(std::chrono::seconds(2));
return;
}
std::cout << "\nRemoving player " << index << "...";
for (int i = 0; i < d->number_of_players; ++i)
{
if (i == index)
{
// Found the player, remove and shift others
for (int j = i; j < d->number_of_players - 1; ++j)
{
d->players[j] = d->players[j + 1];
}
// Decrement number of players
d->number_of_players--;
}
}
}