Advertisement
maxim_shlyahtin

Cpp

Oct 26th, 2023
823
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C++ 5.32 KB | None | 0 0
  1. void Trap::event_trigger(){
  2.     if(this->player.get_finesse() < 15)
  3.         this->player.set_health(this->player.get_health() - this->value);
  4.     else
  5.         std::cout << "You dodged a trap\n";
  6. }
  7.  
  8. void Teleport::event_trigger(){
  9.     if(this->player.get_intelligence() >= 15)
  10.         this->field.set_new_loc(this->new_loc.first, this->new_loc.second);
  11.     else
  12.         this->field.set_new_loc(this->field.get_start().first, this->field.get_start().second);
  13. }
  14.  
  15. Manipulator.cpp
  16. #ifndef Manipulator_cpp
  17. #define Manipualtor_cpp
  18. #include "Manipulator.h"
  19. #include <iostream>
  20. #include <typeinfo>
  21.  
  22.  
  23. Manipulator::Manipulator(Player& player, Field& field): player(player), field(field){}
  24.  
  25. void Manipulator::player_movement(MOVEMENT move){
  26.     int new_x = this->coordinates.first;
  27.     int new_y = this->coordinates.second;
  28.     if(!this->check_coordinates(new_x, new_y)){
  29.         std::cout << "This cell is out of reach\n";
  30.         return ;
  31.     }
  32.     switch (move) {
  33.         case MOVEMENT::RIGHT:
  34.             if(!this->field.get_cell(new_x, new_y).get_wall(RIGHT))
  35.                 new_x += 1;
  36.             else{
  37.                 std::cout << "There is a wall\n";
  38.                 return ;
  39.             }
  40.             break;
  41.         case MOVEMENT::LEFT:
  42.             if(!this->field.get_cell(new_x, new_y).get_wall(LEFT))
  43.                 new_x -= 1;
  44.             else{
  45.                 std::cout << "There is a wall\n";
  46.                 return ;
  47.             }
  48.             break;
  49.         case MOVEMENT::UP:
  50.             if(!this->field.get_cell(new_x, new_y).get_wall(UP))
  51.                 new_y += 1;
  52.             else{
  53.                 std::cout << "There is a wall\n";
  54.                 return ;
  55.             }
  56.             break;
  57.         case MOVEMENT::DOWN:
  58.             if(!this->field.get_cell(new_x, new_y).get_wall(DOWN))
  59.                 new_y -= 1;
  60.             else{
  61.                 std::cout << "There is a wall\n";
  62.                 return ;
  63.             }
  64.             break;
  65.         default:
  66.             break;
  67.     }
  68.     Cell cell = this->field.get_cell(new_x, new_y);
  69.     if(cell.get_pass()){
  70.         this->field.get_cell(this->coordinates.first, this->coordinates.second).set_player_presence(false);
  71.         this->coordinates.first = new_x;
  72.         this->coordinates.second = new_y;
  73.         this->field.get_cell(new_x, new_y).set_player_presence(true);
  74.         if(this->field.get_cell(new_x, new_y).get_event() != nullptr){
  75.             this->check_for_event();
  76.             std::cout << "Event was triggered\n";
  77.         }
  78.     } else
  79.         std::cout << "Path is blocked\n";
  80. }
  81.  
  82.  
  83.  
  84. bool Manipulator::check_for_miss(int finesse, int check) {
  85.     if(this->player.get_finesse() < check)
  86.         return true;
  87.     return false;
  88. }
  89.  
  90. void Manipulator::take_damage(int damage, bool hit) {
  91.     if (hit)
  92.         this->player.set_health(this->player.get_health() - damage);
  93. }
  94.  
  95. void Manipulator::get_exp(int value) {
  96.     this->player.set_exp(this->player.get_exp() + value);
  97. }
  98.  
  99. void Manipulator::show_stats() {
  100.     std::cout << "Name: " << this->player.get_name() << "\n";
  101.     std::cout << "Health: " << this->player.get_health() << "\n";
  102.     std::cout << "Strength: " << this->player.get_strength() << "\n";
  103.     std::cout << "Finesse: " << this->player.get_finesse() << "\n";
  104.     std::cout << "Intelligence: " << this->player.get_intelligence() << "\n";
  105.     std::cout << "Exp: " << this->player.get_exp() << "\n";
  106.     std::cout << "Money: " << this->player.get_money() << "\n";
  107.     std::cout << "Armor: " << this->player.get_armor() << "\n";
  108. }
  109.  
  110. void Manipulator::show_coords(){
  111.     std::cout << "Your X coordinate: " << this->coordinates.first << "\n";
  112.     std::cout << "Your Y coordinate: " << this->coordinates.second << "\n";
  113. }
  114.  
  115. bool Manipulator::check_coordinates(int x, int y){
  116.     if(x < 0 || x > MAX_W || y < 0 || y > MAX_H)
  117.         return false;
  118.     else
  119.         return true;
  120. }
  121.  
  122. void Manipulator::update_coords(){
  123.     int x = this->field.get_new_loc().first;
  124.     int y = this->field.get_new_loc().second;
  125.     if(x == -1){ return; }
  126.     int prev_x = this->coordinates.first;
  127.     int prev_y = this->coordinates.second;
  128.     this->field.get_cell(prev_x, prev_y).set_event(nullptr);
  129.     this->field.get_cell(prev_x, prev_y).set_player_presence(false);
  130.     if(this->check_coordinates(x, y)){
  131.         this->coordinates.first = x;
  132.         this->coordinates.second = y;
  133.         this->field.get_cell(x, y).set_player_presence(true);
  134.     }
  135.     this->field.set_new_loc(-1, -1);
  136. }
  137.  
  138. void Manipulator::check_for_event(){
  139.     int x = this->coordinates.first;
  140.     int y = this->coordinates.second;
  141.     Cell cell = this->field.get_cell(x, y);
  142.     cell.get_event()->event_trigger();
  143.     this->update_coords();
  144. }
  145.  
  146. void Manipulator::start_the_game() {
  147.     std::cout << "It's the start of the game. Choose your name:\n";
  148.     std::string name;
  149.     std::cin >> name;
  150.     this->player.set_name(name);
  151.     std::cout << "Choose your character:\n";
  152.     std::cout << "Press 1 to choose Fighter\n";
  153.     std::cout << "Press 2 to choose Wizard\n";
  154.     std::cout << "Press 3 to choose Rogue\n";
  155.     int input;
  156.     std::cin >> input;
  157.     switch (input) {
  158.         case(1):
  159.             this->player.set_character(SUBCLASS::FIGHTER);
  160.             break;
  161.         case(2):
  162.             this->player.set_character(SUBCLASS::WIZARD);
  163.             break;
  164.         case(3):
  165.             this->player.set_character(SUBCLASS::ROGUE);
  166.             break;
  167.         default:
  168.             std::cout << "You decided to start as a commoner.\n";
  169.     }
  170.     std::cout << "Character's info: \n";
  171.     this->show_stats();
  172.     std::cout << "\n";
  173.     IFieldGen* ev = new FieldGenerator(30, 30);
  174.     this->field = ev->create_field(this->player);
  175.     FieldDisplay field_display(this->field);
  176.     this->update_coords();
  177.     this->field.get_cell(1, 0).set_event(new Teleport(std::make_pair(9, 9), this->field, this->player));
  178.     this->show_coords();
  179.     field_display.show_field();
  180.     this->player_movement(RIGHT);
  181.     this->show_stats();
  182.     field_display.show_field();
  183. }
  184.  
  185. #endif
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement