Added copy operators for game's static instance
Player CommandParser can be swapped but not copied.
This commit is contained in:
+35
-1
@@ -1,9 +1,32 @@
|
||||
#include "player.h"
|
||||
#include <algorithm>
|
||||
#include <string>
|
||||
|
||||
Player::Player()
|
||||
{
|
||||
Init();
|
||||
}
|
||||
|
||||
Player::Player(Player &rhs)
|
||||
{
|
||||
id = rhs.id;
|
||||
level = rhs.level;
|
||||
stats = rhs.stats;
|
||||
name = rhs.name;
|
||||
description = rhs.description;
|
||||
curRoomID = rhs.curRoomID;
|
||||
prevRoomID = rhs.prevRoomID;
|
||||
}
|
||||
|
||||
Player& Player::operator=(Player& rhs)
|
||||
{
|
||||
swap(*this, rhs);
|
||||
return *this;
|
||||
}
|
||||
|
||||
void Player::Init() {
|
||||
// initialize stats, room location, inventory and item data
|
||||
stats = Stats{100.0f, 50.00f, 150.00f, 50.00f};
|
||||
|
||||
name = "Player";
|
||||
}
|
||||
|
||||
@@ -29,3 +52,14 @@ void Player::ChangeRoom(int roomID) {
|
||||
curRoomID = roomID;
|
||||
}
|
||||
}
|
||||
|
||||
Player::~Player()
|
||||
{
|
||||
id = -1;
|
||||
level = -1;
|
||||
stats = {};
|
||||
name.erase();
|
||||
description.erase();
|
||||
curRoomID = -1;
|
||||
prevRoomID = -1;
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user