Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #include <iostream>
- #include <string>
- #include <stdlib.h>
- #include <stdio.h>
- const int GRID_WIDTH = 20;
- const int GRID_HEIGHT = 20;
- const int GRID_START_X = 10;
- const int GRID_START_Y = 10;
- using namespace std;
- class Movable {
- public:
- virtual void moveUp() = 0;
- virtual void moveDown() = 0;
- virtual void moveRight() = 0;
- virtual void moveLeft() = 0;
- virtual ~Movable() {};
- };
- class Drawable {
- public:
- virtual void draw() = 0;
- virtual ~Drawable() {};
- };
- class User : public Movable, public Drawable {
- private:
- int m_x;
- int m_y;
- string m_name;
- int m_health;
- int m_defence;
- int m_power;
- int m_agility;
- int m_intellect;
- public:
- User() {
- m_x = GRID_START_X;
- m_y = GRID_START_Y;
- m_name = "Ksenia";
- m_health = 100;
- m_defence = 5;
- m_power = 40;
- m_agility = 22;
- m_intellect = 88;
- }
- void setName(string name) {
- m_name = name;
- }
- void moveUp() override {
- m_y = (m_y - 1) % GRID_HEIGHT;
- };
- void moveDown() override {
- m_y = (m_y + 1) % GRID_HEIGHT;
- };
- void moveRight() override {
- m_x = (m_x + 1) % GRID_WIDTH;
- };
- void moveLeft() override {
- m_x = (m_x - 1) % GRID_WIDTH;
- };
- void draw() override {
- system("clear");
- cout << "* name: " << m_name << endl;
- cout << "* health: " << m_health << endl;
- cout << "* defence: " << m_defence << endl;
- cout << "* power: " << m_power << endl;
- cout << "* agility: " << m_agility << endl;
- cout << "* intellect: " << m_intellect << endl << endl;
- for (int i = 0; i < GRID_HEIGHT; i++) {
- for (int j = 0; j < GRID_WIDTH; j++) {
- if (i == m_y && j == m_x) {
- cout << '@';
- } else {
- cout << '.';
- }
- }
- cout << endl;
- }
- }
- virtual ~User() {};
- };
- int main ()
- {
- User u;
- u.draw();
- u.setName("Kesnia Volkova");
- while (true) {
- char m = getchar();
- if (m == 'w') {
- u.moveUp();
- } else if (m == 's') {
- u.moveDown();
- } else if (m == 'a') {
- u.moveLeft();
- } else if (m == 'd') {
- u.moveRight();
- } else if (m == 'x') {
- break;
- }
- u.draw();
- }
- return 0;
- }
Add Comment
Please, Sign In to add comment