54 lines
1.5 KiB
C++
54 lines
1.5 KiB
C++
#include "player.h"
|
|
|
|
PlayerManager::PlayerManager()
|
|
{
|
|
// Register default players with distinct, unique color combinations
|
|
// Player 1: Royal Blue primary, Radiant Gold secondary
|
|
addPlayer(1, "Speler 1", QColor(30, 136, 229), QColor(255, 213, 79));
|
|
|
|
// Player 2: Crimson Red primary, Crisp White secondary
|
|
addPlayer(2, "Speler 2", QColor(229, 57, 53), QColor(255, 255, 255));
|
|
|
|
// Player 3: Emerald Green primary, Amber Yellow secondary
|
|
addPlayer(3, "Speler 3", QColor(67, 160, 71), QColor(255, 179, 0));
|
|
|
|
// Player 4: Imperial Purple primary, Cyan secondary
|
|
addPlayer(4, "Speler 4", QColor(142, 36, 170), QColor(0, 229, 255));
|
|
}
|
|
|
|
bool PlayerManager::isCombinationUnique(const QColor &primary, const QColor &secondary, int excludeId) const
|
|
{
|
|
for (const auto &p : m_players) {
|
|
if (p.id == excludeId) continue;
|
|
if (p.primaryColor == primary && p.secondaryColor == secondary) {
|
|
return false;
|
|
}
|
|
}
|
|
return true;
|
|
}
|
|
|
|
bool PlayerManager::addPlayer(int id, const QString &name, const QColor &primary, const QColor &secondary)
|
|
{
|
|
if (!isCombinationUnique(primary, secondary)) {
|
|
return false;
|
|
}
|
|
m_players.emplace_back(id, name, primary, secondary);
|
|
return true;
|
|
}
|
|
|
|
const Player* PlayerManager::getPlayer(int id) const
|
|
{
|
|
for (const auto &p : m_players) {
|
|
if (p.id == id) return &p;
|
|
}
|
|
return nullptr;
|
|
}
|
|
|
|
Player* PlayerManager::getPlayer(int id)
|
|
{
|
|
for (auto &p : m_players) {
|
|
if (p.id == id) return &p;
|
|
}
|
|
return nullptr;
|
|
}
|