Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #include <iostream>
- #include "player.h"
- Player::Player(int hp, int dmg, int x, int y, int arm, int wgt) : hp(hp), dmg(dmg), x(x), y(y), arm(arm), wgt(wgt) {}
- int Player::get_hp() {
- return this->hp;
- }
- int Player::get_arm() {
- return this->arm;
- }
- int Player::get_x() {
- return this->x;
- }
- int Player::get_y() {
- return this->y;
- }
- void Player::take_dmg(int external_dmg) {
- if (arm >= external_dmg) {
- hp -= 1;
- return;
- }
- hp -= external_dmg - arm - 1;
- }
- void Player::move(std::string dir) {
- if (dir == "left") {
- x -= 1;
- }
- if (dir == "right") {
- x += 1;
- }
- if (dir == "down") {
- y -= 1;
- }
- if (dir == "up") {
- y += 1;
- }
- std::cout << "moved" << std::endl;
- }
- void Player::pick(std::string item_name, Thing* item) {
- auto it = items.find(item_name);
- if (it != items.end()) {
- return;
- }
- items.emplace(item_name, item);
- arm += item->get_arm();
- wgt += item->get_wgt();
- std::cout << "clothes worn" << std::endl;
- }
- int Player::pack_size() {
- return this->items.size();
- }
- void Player::can_throw() {
- for (auto it = items.begin(); it != items.end(); it++) {
- std::cout << "throw " << it->first << std::endl;
- }
- }
- void Player::throw_item(std::string name) {
- auto it = items.find(name);
- if (it == items.end()) {
- return;
- }
- arm -= it->second->get_arm();
- wgt -= it->second->get_wgt();
- it = items.erase(it);
- std::cout << "the " << name << " is thrown out" << std::endl;
- }
- void Player::print_info() {
- std::cout << get_x() << " x " << get_y() << ", hp: " << get_hp() << ", armor: " << get_arm() << std::endl;
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement