Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #include <iostream>
- #include <cstring>
- #define fill "default"
- using namespace std;
- class Board_Position {
- int x, y;
- public:
- int GetX() { return x; };
- int GetY() { return y; };
- Board_Position(const Board_Position &);
- Board_Position();
- Board_Position(int a, int b);
- ~Board_Position();
- Board_Position &SetX(int);
- Board_Position &SetY(int);
- void print_full();
- void print_main();
- };
- Board_Position::Board_Position(const Board_Position &a) {
- x = a.x;
- y = a.y;
- }
- Board_Position::Board_Position() {
- x = 0;
- y = 0;
- }
- Board_Position::Board_Position(int a, int b) {
- x = a;
- y = b;
- }
- void Board_Position::print_full() {
- cout << "x = " << x << " y = " << y << endl;
- }
- void Board_Position::print_main() {
- cout << "CLASS: Board_Position" << "\t" << " Main information: Coordinates" << "\t" << "(" << x << ";" << y << ")"
- << endl;
- }
- Board_Position &Board_Position::SetX(int a) {
- x = a;
- return *this;
- }
- Board_Position &Board_Position::SetY(int b) {
- y = b;
- return *this;
- }
- Board_Position::~Board_Position() = default;
- class Figure {
- Board_Position coords;
- char *figure_colour;
- public:
- Figure();
- Figure(char *, Board_Position &);
- Figure(const Figure &);
- ~Figure();
- Figure &Change_Colour(char *, Board_Position &);
- void print_full();
- void print_main();
- void move();
- };
- Figure::Figure() {
- figure_colour = new char[7];
- strcpy(figure_colour, fill);
- Board_Position();
- }
- Figure::Figure(char *name, Board_Position &position) {
- figure_colour = new char[strlen(name)];
- strcpy(figure_colour, name);
- coords = position;
- }
- void Figure::print_full() {
- cout << "Color - " << figure_colour << "\t" << "Coordinates :";
- coords.print_full();
- }
- Figure::Figure(const Figure &a) {
- figure_colour = new char[strlen(a.figure_colour)];
- strcpy(figure_colour, a.figure_colour);
- coords = a.coords;
- }
- Figure &Figure::Change_Colour(char *a, Board_Position &object) {
- figure_colour = new char[strlen(a)];
- strcpy(figure_colour, a);
- coords = object;
- return *this;
- }
- void Figure::print_main() {
- cout << "CLASS : Figure" << "\t" << "Main information : Coordinates " << "(" << coords.GetX() << ";"
- << coords.GetY() << ")" << endl;
- }
- void Figure::move() {
- int z;
- cout << "Choose direction of move:" << "\n" << " Press 1 for straight, 2 for back" << endl;
- cin >> z;
- switch (z) {
- case 1:
- if (coords.GetY() > 7) {
- cout << "You cant move in this direction\n";
- break;
- } else {
- coords.SetY(coords.GetY() + 1);
- cout << "Coordinates after move :" << "(" << coords.GetX() << ";" << coords.GetY() << ")" << endl;
- break;
- }
- case 2:
- if (coords.GetY() < 2) {
- cout << "You cant move in this direction\n";
- break;
- } else {
- coords.SetY(coords.GetY() - 1);
- cout << "Coordinates after move :" << "(" << coords.GetX() << ";" << coords.GetY() << ")" << endl;
- break;
- }
- default:
- cout << "Wrong direction!\n" << endl;
- }
- }
- Figure::~Figure() = default;
- int main() {
- int x, y;
- char array[10];
- cout << "Enter coordinates, each coordinate less or equal to 8 " << endl;
- cin >> x >> y;
- Board_Position position_1 = Board_Position(x, y);
- Board_Position position_2 = Board_Position();
- Board_Position position_3 = Board_Position(position_1);
- position_1.print_full();
- position_1.print_main();
- position_2.print_full();
- position_2.print_main();
- position_3.print_full();
- position_3.print_main();
- cout << "Enter colour of your figure" << endl;
- cin >> array;
- Figure *figure2 = new Figure();
- Figure *figure1 = new Figure(array, position_1);
- Figure *figure3 = new Figure(*figure1);
- figure1->print_main();
- figure1->print_full();
- figure2->print_main();
- figure2->print_full();
- figure3->print_main();
- figure3->print_full();
- figure3->move();
- delete figure1;
- delete figure2;
- delete figure3;
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement