add result table

master
Vectozavr 2021-10-26 13:50:59 +07:00
parent 832f174664
commit 020d82cab8
3 changed files with 25 additions and 10 deletions

View File

@ -90,6 +90,18 @@ void Client::processCustomPacket(MsgType type, sf::Packet& packet) {
switch (type) {
case MsgType::Kill:
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()) {
_player->addDeath();
// respawn
@ -97,15 +109,12 @@ void Client::processCustomPacket(MsgType type, sf::Packet& packet) {
_player->initWeapons();
_player->setFullAbility();
SoundController::playSound(SoundTag("death"), ShooterConsts::DEATH_SOUND);
_lastEvent += _player->playerName();
}
else
else {
_players[buffId[0]]->addDeath();
if(buffId[1] == _socket.ownId()) {
_player->addKill();
SoundController::playSound(SoundTag("kill"), ShooterConsts::KILL_SOUND);
_lastEvent += _players[buffId[0]]->playerName();
}
else
_players[buffId[1]]->addKill();
break;
case MsgType::FireTrace:
packet >> dbuff[0] >> dbuff[1] >> dbuff[2] >> dbuff[3] >> dbuff[4] >> dbuff[5];

View File

@ -10,6 +10,8 @@
class Client final : public ClientUDP {
private:
std::string _lastEvent;
std::map<sf::Uint16, std::shared_ptr<Player>> _players{};
std::shared_ptr<Player> _player;
@ -50,7 +52,9 @@ public:
void changeWeapon(const std::string& weaponName);
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; }
};

View File

@ -173,7 +173,9 @@ void Shooter::gui() {
}
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;
allPlayers.push_back(player);
@ -185,8 +187,8 @@ void Shooter::drawStatsTable() {
} );
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()),
Vec2D{10, 10 + 35.0*i}, 25, sf::Color(0, 0, 0, 150));
screen->drawText(std::to_string(i) + "\t" + p->playerName() + "\t" + std::to_string(p->kills()) + " / " + std::to_string(p->deaths()),
Vec2D{10, 15 + 35.0*i}, 25, sf::Color(0, 0, 0, 150));
i++;
}
}