add result table
parent
832f174664
commit
020d82cab8
21
Client.cpp
21
Client.cpp
|
@ -90,6 +90,18 @@ void Client::processCustomPacket(MsgType type, sf::Packet& packet) {
|
||||||
switch (type) {
|
switch (type) {
|
||||||
case MsgType::Kill:
|
case MsgType::Kill:
|
||||||
packet >> buffId[0] >> buffId[1];
|
packet >> buffId[0] >> buffId[1];
|
||||||
|
_lastEvent = "";
|
||||||
|
if(buffId[1] == _socket.ownId()) {
|
||||||
|
_player->addKill();
|
||||||
|
SoundController::playSound(SoundTag("kill"), ShooterConsts::KILL_SOUND);
|
||||||
|
_lastEvent += _player->playerName();
|
||||||
|
}
|
||||||
|
else {
|
||||||
|
_players[buffId[1]]->addKill();
|
||||||
|
_lastEvent += _players[buffId[1]]->playerName();
|
||||||
|
}
|
||||||
|
_lastEvent += " kill ";
|
||||||
|
|
||||||
if(buffId[0] == _socket.ownId()) {
|
if(buffId[0] == _socket.ownId()) {
|
||||||
_player->addDeath();
|
_player->addDeath();
|
||||||
// respawn
|
// respawn
|
||||||
|
@ -97,15 +109,12 @@ void Client::processCustomPacket(MsgType type, sf::Packet& packet) {
|
||||||
_player->initWeapons();
|
_player->initWeapons();
|
||||||
_player->setFullAbility();
|
_player->setFullAbility();
|
||||||
SoundController::playSound(SoundTag("death"), ShooterConsts::DEATH_SOUND);
|
SoundController::playSound(SoundTag("death"), ShooterConsts::DEATH_SOUND);
|
||||||
|
_lastEvent += _player->playerName();
|
||||||
}
|
}
|
||||||
else
|
else {
|
||||||
_players[buffId[0]]->addDeath();
|
_players[buffId[0]]->addDeath();
|
||||||
if(buffId[1] == _socket.ownId()) {
|
_lastEvent += _players[buffId[0]]->playerName();
|
||||||
_player->addKill();
|
|
||||||
SoundController::playSound(SoundTag("kill"), ShooterConsts::KILL_SOUND);
|
|
||||||
}
|
}
|
||||||
else
|
|
||||||
_players[buffId[1]]->addKill();
|
|
||||||
break;
|
break;
|
||||||
case MsgType::FireTrace:
|
case MsgType::FireTrace:
|
||||||
packet >> dbuff[0] >> dbuff[1] >> dbuff[2] >> dbuff[3] >> dbuff[4] >> dbuff[5];
|
packet >> dbuff[0] >> dbuff[1] >> dbuff[2] >> dbuff[3] >> dbuff[4] >> dbuff[5];
|
||||||
|
|
6
Client.h
6
Client.h
|
@ -10,6 +10,8 @@
|
||||||
|
|
||||||
class Client final : public ClientUDP {
|
class Client final : public ClientUDP {
|
||||||
private:
|
private:
|
||||||
|
std::string _lastEvent;
|
||||||
|
|
||||||
std::map<sf::Uint16, std::shared_ptr<Player>> _players{};
|
std::map<sf::Uint16, std::shared_ptr<Player>> _players{};
|
||||||
std::shared_ptr<Player> _player;
|
std::shared_ptr<Player> _player;
|
||||||
|
|
||||||
|
@ -50,7 +52,9 @@ public:
|
||||||
void changeWeapon(const std::string& weaponName);
|
void changeWeapon(const std::string& weaponName);
|
||||||
|
|
||||||
void addPlayer(sf::Uint16 id, std::shared_ptr<Player> player);
|
void addPlayer(sf::Uint16 id, std::shared_ptr<Player> player);
|
||||||
std::map<sf::Uint16, std::shared_ptr<Player>>const & players() const { return _players; }
|
[[nodiscard]] std::map<sf::Uint16, std::shared_ptr<Player>>const & players() const { return _players; }
|
||||||
|
|
||||||
|
[[nodiscard]] std::string lastEvent() const { return _lastEvent; }
|
||||||
};
|
};
|
||||||
|
|
||||||
|
|
||||||
|
|
|
@ -173,7 +173,9 @@ void Shooter::gui() {
|
||||||
}
|
}
|
||||||
|
|
||||||
void Shooter::drawStatsTable() {
|
void Shooter::drawStatsTable() {
|
||||||
int i = 0;
|
int i = 1;
|
||||||
|
|
||||||
|
screen->drawText(client->lastEvent(),Vec2D{10, 10},25, sf::Color(0, 0, 0, 100));
|
||||||
|
|
||||||
vector<shared_ptr<Player>> allPlayers;
|
vector<shared_ptr<Player>> allPlayers;
|
||||||
allPlayers.push_back(player);
|
allPlayers.push_back(player);
|
||||||
|
@ -185,8 +187,8 @@ void Shooter::drawStatsTable() {
|
||||||
} );
|
} );
|
||||||
|
|
||||||
for(auto& p : allPlayers) {
|
for(auto& p : allPlayers) {
|
||||||
screen->drawText(std::to_string(i + 1) + "\t" + p->playerName() + "\t" + std::to_string(p->kills()) + " / " + std::to_string(p->deaths()),
|
screen->drawText(std::to_string(i) + "\t" + p->playerName() + "\t" + std::to_string(p->kills()) + " / " + std::to_string(p->deaths()),
|
||||||
Vec2D{10, 10 + 35.0*i}, 25, sf::Color(0, 0, 0, 150));
|
Vec2D{10, 15 + 35.0*i}, 25, sf::Color(0, 0, 0, 150));
|
||||||
i++;
|
i++;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in New Issue