Guest User

Untitled

a guest
Nov 18th, 2017
73
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 2.19 KB | None | 0 0
  1. #include <iostream>
  2. #include <string>
  3. #include <stdlib.h>
  4. #include <stdio.h>
  5.  
  6. const int GRID_WIDTH = 20;
  7. const int GRID_HEIGHT = 20;
  8. const int GRID_START_X = 10;
  9. const int GRID_START_Y = 10;
  10.  
  11. using namespace std;
  12.  
  13. class Movable {
  14. public:
  15. virtual void moveUp() = 0;
  16. virtual void moveDown() = 0;
  17. virtual void moveRight() = 0;
  18. virtual void moveLeft() = 0;
  19. virtual ~Movable() {};
  20. };
  21.  
  22. class Drawable {
  23. public:
  24. virtual void draw() = 0;
  25. virtual ~Drawable() {};
  26. };
  27.  
  28. class User : public Movable, public Drawable {
  29. private:
  30. int m_x;
  31. int m_y;
  32.  
  33. string m_name;
  34. int m_health;
  35. int m_defence;
  36. int m_power;
  37. int m_agility;
  38. int m_intellect;
  39.  
  40. public:
  41. User() {
  42. m_x = GRID_START_X;
  43. m_y = GRID_START_Y;
  44. m_name = "Ksenia";
  45. m_health = 100;
  46. m_defence = 5;
  47. m_power = 40;
  48. m_agility = 22;
  49. m_intellect = 88;
  50. }
  51.  
  52. void setName(string name) {
  53. m_name = name;
  54. }
  55.  
  56. void moveUp() override {
  57. m_y = (m_y - 1) % GRID_HEIGHT;
  58. };
  59.  
  60. void moveDown() override {
  61. m_y = (m_y + 1) % GRID_HEIGHT;
  62. };
  63.  
  64. void moveRight() override {
  65. m_x = (m_x + 1) % GRID_WIDTH;
  66. };
  67.  
  68. void moveLeft() override {
  69. m_x = (m_x - 1) % GRID_WIDTH;
  70. };
  71.  
  72. void draw() override {
  73. system("clear");
  74. cout << "* name: " << m_name << endl;
  75. cout << "* health: " << m_health << endl;
  76. cout << "* defence: " << m_defence << endl;
  77. cout << "* power: " << m_power << endl;
  78. cout << "* agility: " << m_agility << endl;
  79. cout << "* intellect: " << m_intellect << endl << endl;
  80. for (int i = 0; i < GRID_HEIGHT; i++) {
  81. for (int j = 0; j < GRID_WIDTH; j++) {
  82. if (i == m_y && j == m_x) {
  83. cout << '@';
  84. } else {
  85. cout << '.';
  86. }
  87. }
  88. cout << endl;
  89. }
  90. }
  91.  
  92. virtual ~User() {};
  93. };
  94.  
  95.  
  96. int main ()
  97. {
  98. User u;
  99. u.draw();
  100. u.setName("Kesnia Volkova");
  101. while (true) {
  102. char m = getchar();
  103. if (m == 'w') {
  104. u.moveUp();
  105. } else if (m == 's') {
  106. u.moveDown();
  107. } else if (m == 'a') {
  108. u.moveLeft();
  109. } else if (m == 'd') {
  110. u.moveRight();
  111. } else if (m == 'x') {
  112. break;
  113. }
  114. u.draw();
  115. }
  116. return 0;
  117. }
Add Comment
Please, Sign In to add comment