-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathHandledMethods.cpp
More file actions
101 lines (80 loc) · 2.31 KB
/
HandledMethods.cpp
File metadata and controls
101 lines (80 loc) · 2.31 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
#include "NetworkHandler.h"
#include "Client.h"
#include "Game.h"
#include "LogUtil.h"
void handleInit(std::vector<std::string> args) //Arg Size 2
{
int playerNum = atoi(args[0].c_str());
int id = atoi(args[1].c_str());
CardType trump = static_cast<CardType>(atoi(args[2].c_str()));
logI(std::format("Received id {} from network", id));
client->id = id;
game->preInit(playerNum, id);
game->setCurrentPlayer(id);
game->setTrump(trump);
}
void handleInitResponse(std::vector<std::string> args) //Arg Size 0
{
server->initResponses++;
if (isServer())
{
//Start game when all clients have been initialized
if (server->initResponses == server->clients.size())
{
game->postInit();
}
}
}
void handleAddCard(std::vector<std::string> args) //Arg Size 2
{
Player* player = game->getPlayer(atoi(args[0].c_str()));
std::string cardId = args[1];
player->addCard(getCard(cardId), true);
}
void handleRemoveCard(std::vector<std::string> args) //Arg Size 2
{
Player* player = game->getPlayer(atoi(args[0].c_str()));
std::string cardId = args[1];
player->removeCard(getCard(cardId), true);
}
void handleAddToStack(std::vector<std::string> args) //Arg Size 1
{
std::string id = args[0];
game->cardStack.push_back(getCard(id));
}
void handleStart(std::vector<std::string> args) //Arg Size 0
{
durak->show();
}
void handleStartAttack(std::vector<std::string> args) //Arg Size 3
{
int defId = atoi(args[0].c_str());
int attId1 = atoi(args[1].c_str());
int attId2 = atoi(args[2].c_str());
Attack::createAttack(game->getPlayer(defId), game->getPlayer(attId1), game->getPlayer(attId2), true);
}
void handleAddToAttack(std::vector<std::string> args) //Arg Size 2
{
int attId = atoi(args[0].c_str());
std::string cardId = args[1];
game->currentAttack->addCard(game->getPlayer(attId), getCard(cardId), true);
}
void handleDefend(std::vector<std::string> args) //Arg Size 2
{
std::string attId = args[0];
std::string defId = args[1];
game->currentAttack->defend(getCard(attId), getCard(defId), true);
}
void handleLeaveAttack(std::vector<std::string> args) //Arg Size 1
{
int id = atoi(args[0].c_str());
game->currentAttack->leave(game->getPlayer(id), true);
}
void handleEndGame(std::vector<std::string> args) //Arg Size 0
{
game->endGame();
}
void handleReset(std::vector<std::string> args) //Arg Size 0
{
resetGame();
}