Advertisement
Guest User

Untitled

a guest
Feb 26th, 2020
99
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 4.38 KB | None | 0 0
  1. #include <iostream>
  2. #include <cstring>
  3.  
  4. #define fill "default"
  5.  
  6. using namespace std;
  7.  
  8. class Board_Position {
  9. int x, y;
  10. public:
  11. int GetX() { return x; };
  12.  
  13. int GetY() { return y; };
  14.  
  15. Board_Position(const Board_Position &);
  16.  
  17. Board_Position();
  18.  
  19. Board_Position(int a, int b);
  20.  
  21. ~Board_Position();
  22.  
  23. Board_Position &SetX(int);
  24.  
  25. Board_Position &SetY(int);
  26.  
  27. void print_full();
  28.  
  29. void print_main();
  30.  
  31.  
  32. };
  33.  
  34.  
  35. Board_Position::Board_Position(const Board_Position &a) {
  36. x = a.x;
  37. y = a.y;
  38.  
  39.  
  40. }
  41.  
  42. Board_Position::Board_Position() {
  43. x = 0;
  44. y = 0;
  45.  
  46. }
  47.  
  48. Board_Position::Board_Position(int a, int b) {
  49. x = a;
  50. y = b;
  51.  
  52. }
  53.  
  54. void Board_Position::print_full() {
  55. cout << "x = " << x << " y = " << y << endl;
  56.  
  57.  
  58. }
  59.  
  60. void Board_Position::print_main() {
  61. cout << "CLASS: Board_Position" << "\t" << " Main information: Coordinates" << "\t" << "(" << x << ";" << y << ")"
  62. << endl;
  63.  
  64. }
  65.  
  66. Board_Position &Board_Position::SetX(int a) {
  67. x = a;
  68. return *this;
  69. }
  70.  
  71. Board_Position &Board_Position::SetY(int b) {
  72. y = b;
  73. return *this;
  74. }
  75.  
  76. Board_Position::~Board_Position() = default;
  77.  
  78. class Figure {
  79. Board_Position coords;
  80. char *figure_colour;
  81. public:
  82. Figure();
  83.  
  84. Figure(char *, Board_Position &);
  85.  
  86. Figure(const Figure &);
  87.  
  88. ~Figure();
  89.  
  90. Figure &Change_Colour(char *, Board_Position &);
  91.  
  92. void print_full();
  93.  
  94. void print_main();
  95.  
  96. void move();
  97.  
  98.  
  99. };
  100.  
  101. Figure::Figure() {
  102. figure_colour = new char[7];
  103. strcpy(figure_colour, fill);
  104. Board_Position();
  105.  
  106.  
  107. }
  108.  
  109. Figure::Figure(char *name, Board_Position &position) {
  110. figure_colour = new char[strlen(name)];
  111. strcpy(figure_colour, name);
  112. coords = position;
  113.  
  114.  
  115. }
  116.  
  117. void Figure::print_full() {
  118. cout << "Color - " << figure_colour << "\t" << "Coordinates :";
  119. coords.print_full();
  120.  
  121.  
  122. }
  123.  
  124. Figure::Figure(const Figure &a) {
  125. figure_colour = new char[strlen(a.figure_colour)];
  126. strcpy(figure_colour, a.figure_colour);
  127. coords = a.coords;
  128.  
  129. }
  130.  
  131. Figure &Figure::Change_Colour(char *a, Board_Position &object) {
  132. figure_colour = new char[strlen(a)];
  133. strcpy(figure_colour, a);
  134. coords = object;
  135. return *this;
  136. }
  137.  
  138. void Figure::print_main() {
  139. cout << "CLASS : Figure" << "\t" << "Main information : Coordinates " << "(" << coords.GetX() << ";"
  140. << coords.GetY() << ")" << endl;
  141.  
  142. }
  143.  
  144. void Figure::move() {
  145. int z;
  146. cout << "Choose direction of move:" << "\n" << " Press 1 for straight, 2 for back" << endl;
  147. cin >> z;
  148. switch (z) {
  149. case 1:
  150. if (coords.GetY() > 7) {
  151. cout << "You cant move in this direction\n";
  152. break;
  153. } else {
  154. coords.SetY(coords.GetY() + 1);
  155. cout << "Coordinates after move :" << "(" << coords.GetX() << ";" << coords.GetY() << ")" << endl;
  156. break;
  157. }
  158. case 2:
  159. if (coords.GetY() < 2) {
  160. cout << "You cant move in this direction\n";
  161. break;
  162. } else {
  163. coords.SetY(coords.GetY() - 1);
  164. cout << "Coordinates after move :" << "(" << coords.GetX() << ";" << coords.GetY() << ")" << endl;
  165. break;
  166. }
  167. default:
  168. cout << "Wrong direction!\n" << endl;
  169.  
  170.  
  171. }
  172.  
  173.  
  174. }
  175.  
  176.  
  177. Figure::~Figure() = default;
  178.  
  179.  
  180. int main() {
  181. int x, y;
  182. char array[10];
  183. cout << "Enter coordinates, each coordinate less or equal to 8 " << endl;
  184. cin >> x >> y;
  185. Board_Position position_1 = Board_Position(x, y);
  186. Board_Position position_2 = Board_Position();
  187. Board_Position position_3 = Board_Position(position_1);
  188.  
  189. position_1.print_full();
  190. position_1.print_main();
  191. position_2.print_full();
  192. position_2.print_main();
  193. position_3.print_full();
  194. position_3.print_main();
  195.  
  196.  
  197. cout << "Enter colour of your figure" << endl;
  198. cin >> array;
  199. Figure *figure2 = new Figure();
  200. Figure *figure1 = new Figure(array, position_1);
  201. Figure *figure3 = new Figure(*figure1);
  202.  
  203. figure1->print_main();
  204. figure1->print_full();
  205. figure2->print_main();
  206. figure2->print_full();
  207. figure3->print_main();
  208. figure3->print_full();
  209.  
  210. figure3->move();
  211.  
  212.  
  213. delete figure1;
  214. delete figure2;
  215. delete figure3;
  216.  
  217.  
  218. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement