62 lines
1.3 KiB
C++
62 lines
1.3 KiB
C++
#include "Player.hpp"
|
|
|
|
Player::Player(const std::string& name, unsigned int seed, short color):
|
|
name(name), seed(seed), color(color), pawnsFinished(0) {}
|
|
|
|
const std::string& Player::getName() const {
|
|
return name;
|
|
}
|
|
|
|
unsigned int Player::getSeed() const {
|
|
return seed;
|
|
}
|
|
|
|
void Player::initializePawns(int totalPawns) {
|
|
pawns.resize(totalPawns);
|
|
}
|
|
|
|
int Player::getRollCount() const {
|
|
return this->rollCount;
|
|
}
|
|
|
|
void Player::incrementRollCount() {
|
|
this->rollCount++;
|
|
}
|
|
|
|
short Player::getColor() const {
|
|
return this->color;
|
|
}
|
|
|
|
short Player::tryMovingPawn(short pawnID, short fields) {
|
|
// this->pawnsFinished = 4; // do debugowania, wymusza zakończenia gry
|
|
return 0;
|
|
}
|
|
|
|
void Player::movePawn(int pawnIndex, int steps) {
|
|
if (pawnIndex < 0 || pawnIndex >= pawns.size()) return;
|
|
|
|
// TODO: zaimplementować logikę ruchu pionków
|
|
Pawn& pawn = pawns[pawnIndex];
|
|
if (pawn.isAtBase()) {
|
|
if (steps == 6) {
|
|
pawn.setRelativePosition(1);
|
|
}
|
|
} else {
|
|
int newPosition = pawn.getRelativePosition() + steps;
|
|
// TODO: sprawdź pozycję pionków
|
|
pawn.setRelativePosition(newPosition);
|
|
|
|
if (newPosition >= 51/* "koniec", do przerobienia */) {
|
|
pawn.setRelativePosition(51/* "koniec" */);
|
|
pawnsFinished++;
|
|
}
|
|
}
|
|
}
|
|
|
|
std::vector<Pawn>& Player::getPawns() {
|
|
return pawns;
|
|
}
|
|
|
|
bool Player::hasWon() const {
|
|
return pawnsFinished == pawns.size();
|
|
} |