Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #include <stdlib.h>
- #include <iostream>
- #include <string>
- #include <stdio.h>
- #include <conio.h>
- using namespace std;
- int const a = 40, b = 80;
- char map[a][b];
- char ch = 'W';
- int x = b / 2, y = a / 2, z = 0;
- void drawturtele(int i, int j, int z)
- {
- map[i - 1][j - 1] = ch;
- map[i][j] = ch;
- map[i + 1][j + 1] = ch;
- map[i - 1][j + 1] = ch;
- map[i + 1][j - 1] = ch;
- map[i - 1][j] = ch;
- map[i][j - 1] = ch;
- map[i + 1][j] = ch;
- map[i][j + 1] = ch;
- switch (z)
- {
- case 0:
- map[i - 2][j] = ch;
- break;
- case 1:
- map[i][j + 2] = ch;
- break;
- case 2:
- map[i + 2][j] = ch;
- break;
- case 3:
- map[i][j - 2] = ch;
- break;
- }
- }
- void deleteturtele()
- {
- {
- map[y - 1][x - 1] = ' ';
- map[y][x] = ' ';
- map[y + 1][x + 1] = ' ';
- map[y - 1][x + 1] = ' ';
- map[y + 1][x - 1] = ' ';
- map[y - 1][x] = ' ';
- map[y][x - 1] = ' ';
- map[y + 1][x] = ' ';
- map[y][x + 1] = ' ';
- switch (z)
- {
- case 0: map[y - 2][x] = ' ';
- break;
- case 1: map[y][x + 2] = ' ';
- break;
- case 2: map[y + 2][x] = ' ';
- break;
- case 3: map[y][x - 2] = ' ';
- break;
- }
- }
- }
- void move(string napr, int shag)
- {
- deleteturtele();
- if (napr == "vpered")
- {
- switch (z)
- {
- case 0: y = y - shag;
- break;
- case 1: x = x + shag;
- break;
- case 2: y = y + shag;
- break;
- case 3: x = x - shag;
- break;
- }
- }
- if (napr == "vlevo")
- {
- switch (z)
- {
- case 0: x = x - shag;
- break;
- case 1: y = y - shag;
- break;
- case 2: x = x + shag;
- break;
- case 3: y = y + shag;
- break;
- }
- }
- if (napr == "vpravo")
- {
- switch (z)
- {
- case 0: x = x + shag;
- break;
- case 1: y = y + shag;
- break;
- case 2: x = x - shag;
- break;
- case 3: y = y - shag;
- break;
- }
- }
- if (napr == "nazad")
- {
- switch (z)
- {
- case 0: y = y + shag;
- break;
- case 1: x = x - shag;
- break;
- case 2: y = y - shag;
- break;
- case 3: x = x + shag;
- break;
- }
- }
- }
- void povorot(string napr)
- {
- deleteturtele();
- if (napr == "vpravo")
- {
- z++;
- if (z == 4)
- {
- z = 0;
- }
- }
- if (napr == "vlevo")
- {
- z--;
- if (z == -1)
- {
- z = 3;
- }
- }
- }
- void povtor(int kol, string d1, string d2)
- {
- if (d1 == "povorot")
- for (int i = 0; i < kol; i++)
- {
- povorot(d2);
- }
- if ((d1 == "vpered") or (d1 == "nazad") or (d1 == "vpravo") or (d1 == "vlevo"))
- {
- for (int i = 0; i < kol; i++)
- move(d1, atoi(d2.c_str()));
- }
- }
- void drawmap() //заполнение массива map
- {
- for (int i = 0; i < b; i++)
- {
- map[0][i] = '#';
- }
- for (int i = 1; i < a - 1; i++)
- for (int j = 0; j < b; j++)
- {
- if ((j == 0) || (j == b - 1))
- map[i][j] = '#';
- if ((i == y) && (j == x))
- drawturtele(y, x, z);
- }
- for (int i = 0; i < b; i++)
- {
- map[a - 1][i] = '#';
- }
- }
- void draw() //вывод массива map
- {
- for (int i = 0; i < a; i++)
- {
- for (int j = 0; j < b; j++)
- {
- cout << map[i][j];
- }
- cout << endl;
- }
- }
- int main()
- {
- drawmap();
- draw();
- string lala;
- string buffer[4];
- int buff = 0;
- int w = 100;
- while (w)
- {
- cout<<"Komandi:\npovorot vlevo, vpravo.\nvpered n, nazad n, vlevo n, vpravo n\npovtori n komanda.";
- getline(cin, lala);
- int k = 0;
- for (int i = 0; i < lala.length(); i++)
- {
- if (lala[i] != ' ')
- {
- buffer[k] += lala[i];
- }
- else k++;
- }
- if (buffer[0] == "povorot")
- {
- povorot(buffer[1]);
- }
- if ((buffer[0] == "vpered") or (buffer[0] == "vpravo") or (buffer[0] == "vlevo") or (buffer[0] == "nazad"))
- {
- move(buffer[0], atoi(buffer[1].c_str()));
- }
- if (buffer[0] == "povtori")
- {
- povtor(atoi(buffer[1].c_str()), buffer[2], buffer[3]);
- }
- if (lala == "Vixod")
- return 0;
- lala = "";
- for (int i = 0; i < 4; i++)
- buffer[i] = "";
- system("cls");
- drawmap();
- draw();
- }
- system("pause");
- return 0;
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement