Advertisement
Guest User

Untitled

a guest
Nov 12th, 2019
110
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C++ 1.63 KB | None | 0 0
  1. #include <iostream>
  2.  
  3. #include "player.h"
  4.  
  5. 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) {}
  6.  
  7. int Player::get_hp() {
  8.     return this->hp;
  9. }
  10.  
  11. int Player::get_arm() {
  12.     return this->arm;
  13. }
  14.  
  15. int Player::get_x() {
  16.     return this->x;
  17. }
  18.  
  19. int Player::get_y() {
  20.     return this->y;
  21. }
  22.  
  23. void Player::take_dmg(int external_dmg) {
  24.     if (arm >= external_dmg) {
  25.         hp -= 1;
  26.         return;
  27.     }
  28.     hp -= external_dmg - arm - 1;
  29. }
  30.  
  31. void Player::move(std::string dir) {
  32.     if (dir == "left") {
  33.         x -= 1;
  34.     }
  35.     if (dir == "right") {
  36.         x += 1;
  37.     }
  38.     if (dir == "down") {
  39.         y -= 1;
  40.     }
  41.     if (dir == "up") {
  42.         y += 1;
  43.     }
  44.     std::cout << "moved" << std::endl;
  45. }
  46.  
  47. void Player::pick(std::string item_name, Thing* item) {
  48.     auto it = items.find(item_name);
  49.     if (it != items.end()) {
  50.         return;
  51.     }
  52.     items.emplace(item_name, item);
  53.     arm += item->get_arm();
  54.     wgt += item->get_wgt();
  55.     std::cout << "clothes worn" << std::endl;
  56. }
  57.  
  58. int Player::pack_size() {
  59.     return this->items.size();
  60. }
  61. void Player::can_throw() {
  62.     for (auto it = items.begin(); it != items.end(); it++) {
  63.         std::cout << "throw " << it->first << std::endl;
  64.     }
  65. }
  66. void Player::throw_item(std::string name) {
  67.     auto it = items.find(name);
  68.     if (it == items.end()) {
  69.         return;
  70.     }
  71.     arm -= it->second->get_arm();
  72.     wgt -= it->second->get_wgt();
  73.     it = items.erase(it);
  74.     std::cout << "the " << name << " is thrown out" << std::endl;
  75. }
  76.  
  77. void Player::print_info() {
  78.     std::cout << get_x() << " x " << get_y() << ", hp: " << get_hp() << ", armor: " << get_arm() << std::endl;
  79. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement