Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- void Trap::event_trigger(){
- if(this->player.get_finesse() < 15)
- this->player.set_health(this->player.get_health() - this->value);
- else
- std::cout << "You dodged a trap\n";
- }
- void Teleport::event_trigger(){
- if(this->player.get_intelligence() >= 15)
- this->field.set_new_loc(this->new_loc.first, this->new_loc.second);
- else
- this->field.set_new_loc(this->field.get_start().first, this->field.get_start().second);
- }
- Manipulator.cpp
- #ifndef Manipulator_cpp
- #define Manipualtor_cpp
- #include "Manipulator.h"
- #include <iostream>
- #include <typeinfo>
- Manipulator::Manipulator(Player& player, Field& field): player(player), field(field){}
- void Manipulator::player_movement(MOVEMENT move){
- int new_x = this->coordinates.first;
- int new_y = this->coordinates.second;
- if(!this->check_coordinates(new_x, new_y)){
- std::cout << "This cell is out of reach\n";
- return ;
- }
- switch (move) {
- case MOVEMENT::RIGHT:
- if(!this->field.get_cell(new_x, new_y).get_wall(RIGHT))
- new_x += 1;
- else{
- std::cout << "There is a wall\n";
- return ;
- }
- break;
- case MOVEMENT::LEFT:
- if(!this->field.get_cell(new_x, new_y).get_wall(LEFT))
- new_x -= 1;
- else{
- std::cout << "There is a wall\n";
- return ;
- }
- break;
- case MOVEMENT::UP:
- if(!this->field.get_cell(new_x, new_y).get_wall(UP))
- new_y += 1;
- else{
- std::cout << "There is a wall\n";
- return ;
- }
- break;
- case MOVEMENT::DOWN:
- if(!this->field.get_cell(new_x, new_y).get_wall(DOWN))
- new_y -= 1;
- else{
- std::cout << "There is a wall\n";
- return ;
- }
- break;
- default:
- break;
- }
- Cell cell = this->field.get_cell(new_x, new_y);
- if(cell.get_pass()){
- this->field.get_cell(this->coordinates.first, this->coordinates.second).set_player_presence(false);
- this->coordinates.first = new_x;
- this->coordinates.second = new_y;
- this->field.get_cell(new_x, new_y).set_player_presence(true);
- if(this->field.get_cell(new_x, new_y).get_event() != nullptr){
- this->check_for_event();
- std::cout << "Event was triggered\n";
- }
- } else
- std::cout << "Path is blocked\n";
- }
- bool Manipulator::check_for_miss(int finesse, int check) {
- if(this->player.get_finesse() < check)
- return true;
- return false;
- }
- void Manipulator::take_damage(int damage, bool hit) {
- if (hit)
- this->player.set_health(this->player.get_health() - damage);
- }
- void Manipulator::get_exp(int value) {
- this->player.set_exp(this->player.get_exp() + value);
- }
- void Manipulator::show_stats() {
- std::cout << "Name: " << this->player.get_name() << "\n";
- std::cout << "Health: " << this->player.get_health() << "\n";
- std::cout << "Strength: " << this->player.get_strength() << "\n";
- std::cout << "Finesse: " << this->player.get_finesse() << "\n";
- std::cout << "Intelligence: " << this->player.get_intelligence() << "\n";
- std::cout << "Exp: " << this->player.get_exp() << "\n";
- std::cout << "Money: " << this->player.get_money() << "\n";
- std::cout << "Armor: " << this->player.get_armor() << "\n";
- }
- void Manipulator::show_coords(){
- std::cout << "Your X coordinate: " << this->coordinates.first << "\n";
- std::cout << "Your Y coordinate: " << this->coordinates.second << "\n";
- }
- bool Manipulator::check_coordinates(int x, int y){
- if(x < 0 || x > MAX_W || y < 0 || y > MAX_H)
- return false;
- else
- return true;
- }
- void Manipulator::update_coords(){
- int x = this->field.get_new_loc().first;
- int y = this->field.get_new_loc().second;
- if(x == -1){ return; }
- int prev_x = this->coordinates.first;
- int prev_y = this->coordinates.second;
- this->field.get_cell(prev_x, prev_y).set_event(nullptr);
- this->field.get_cell(prev_x, prev_y).set_player_presence(false);
- if(this->check_coordinates(x, y)){
- this->coordinates.first = x;
- this->coordinates.second = y;
- this->field.get_cell(x, y).set_player_presence(true);
- }
- this->field.set_new_loc(-1, -1);
- }
- void Manipulator::check_for_event(){
- int x = this->coordinates.first;
- int y = this->coordinates.second;
- Cell cell = this->field.get_cell(x, y);
- cell.get_event()->event_trigger();
- this->update_coords();
- }
- void Manipulator::start_the_game() {
- std::cout << "It's the start of the game. Choose your name:\n";
- std::string name;
- std::cin >> name;
- this->player.set_name(name);
- std::cout << "Choose your character:\n";
- std::cout << "Press 1 to choose Fighter\n";
- std::cout << "Press 2 to choose Wizard\n";
- std::cout << "Press 3 to choose Rogue\n";
- int input;
- std::cin >> input;
- switch (input) {
- case(1):
- this->player.set_character(SUBCLASS::FIGHTER);
- break;
- case(2):
- this->player.set_character(SUBCLASS::WIZARD);
- break;
- case(3):
- this->player.set_character(SUBCLASS::ROGUE);
- break;
- default:
- std::cout << "You decided to start as a commoner.\n";
- }
- std::cout << "Character's info: \n";
- this->show_stats();
- std::cout << "\n";
- IFieldGen* ev = new FieldGenerator(30, 30);
- this->field = ev->create_field(this->player);
- FieldDisplay field_display(this->field);
- this->update_coords();
- this->field.get_cell(1, 0).set_event(new Teleport(std::make_pair(9, 9), this->field, this->player));
- this->show_coords();
- field_display.show_field();
- this->player_movement(RIGHT);
- this->show_stats();
- field_display.show_field();
- }
- #endif
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement