Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #include <windows.h>
- #include <stdio.h>
- #include <vector>
- #include <algorithm>
- #include <set>
- #include <string>
- #include <map>
- #include <stdlib.h>
- #include <string.h>
- #include <string>
- #include <queue>
- #include <time.h>
- #include <stack>
- #include <iostream>
- #include <fstream>
- using namespace std;
- char matrix[100][100];
- deque <pair<int,int>> rest;
- bool used[100][100];
- int dx[4] = { 1, -1, 0, 0 };
- int dy[4] = { 0, 0, -1, 1 };
- int n, m;
- bool bfs(int x, int y)
- {
- used[x][y] = 1;
- rest.push_back(make_pair(x, y));
- while (rest.size())
- {
- pair<int, int>t = rest.front();
- rest.pop_front();
- x = t.first;
- y = t.second;
- for (int i = 0; i < 4; i++)
- {
- if (-1 < x + dx[i] < n && -1 < y + dy[i] < m && !used[x + dx[i]][y + dy[i]])
- {
- if (matrix[x + dx[i]][y + dy[i]] == '.' || matrix[x + dx[i]][y + dy[i]] == 'O')
- {
- used[x + dx[i]][y + dy[i]] = 1;
- rest.push_back(make_pair(x + dx[i], y + dy[i]));
- }
- else
- {
- if (matrix[x + dx[i]][y + dy[i]] == 'X')
- {
- return true;
- }
- }
- }
- }
- }
- return false;
- }
- int main()
- {
- srand(time(NULL));
- cin >> n >> m;
- if (n > 100 || m > 100)
- {
- cout << "Build error";
- return 0;
- }
- matrix[1][1] = 'O';
- used[1][1] = true;
- int ty = 0;
- for (int i = 0; i < n; i++)
- {
- for (int j = 0; j < m; j++)
- {
- if (!used[i][j] && rand() % 10 == 0)
- {
- double f = (ty + 1) / n*m;
- if (f < 0.2)
- {
- matrix[i][j] = 'X';
- ty++;
- used[i][j] = true;
- }
- }
- if (!used[i][j])
- {
- matrix[i][j] = '.';
- used[i][j] = true;
- }
- }
- }
- int x1 = 1, y1 = 1;
- if (ty == 0)
- {
- cout << "Randow victory";
- return 0;
- }
- while (ty != 0)
- {
- for (int i = 0; i < n; i++)
- {
- for (int j = 0; j < m; j++)
- {
- cout << matrix[i][j];
- }
- cout << endl;
- }
- char s, t;
- bool ryt = false;
- cin >> s >> t;
- bool gt = false;
- bool tr = false;
- tr = (s == 'q');
- int h;
- if (t == 'w')
- h = 1;
- if (t == 'd')
- h = 3;
- if (t == 's')
- h = 0;
- if (t == 'a')
- h = 2;
- if (tr)
- {
- for (int i = 0; i < 4; i++)
- {
- if (h == i)
- {
- if (-1 < x1 + dx[i] < n && -1 < y1 + dy[i] < m && matrix[x1 + dx[i]][y1 + dy[i]] == '.')
- {
- matrix[x1][y1] = '.';
- x1 += dx[i];
- y1 += dy[i];
- matrix[x1][y1] = 'O';
- }
- else
- {
- cout << "impossible" << endl;
- gt = true;
- break;
- }
- }
- }
- if (gt)
- continue;
- }
- else
- {
- int x2 = x1;
- int y2 = y1;
- for (int i = 0; i < 4; i++)
- {
- if (h == i)
- {
- while ((-1 < x1 + dx[i]) && (x1 + dx[i] < n) && (-1 < y1 + dy[i]) && (y1 + dy[i] < m) && matrix[x1 + dx[i]][y1 + dy[i]] != '#')
- {
- x1 += dx[i];
- y1 += dy[i];
- if (matrix[x1][y1] == 'X')
- {
- ty--;
- matrix[x1][y1] = '.';
- break;
- }
- if (matrix[x1][y1] == '#')
- {
- break;
- }
- matrix[x1][y1] = '-';
- for (int i = 0; i < n; i++)
- {
- for (int j = 0; j < m; j++)
- {
- cout << matrix[i][j];
- }
- cout << endl;
- }
- if (matrix[x1][y1] == '-')
- {
- matrix[x1][y1] = '.';
- }
- Sleep(1000);
- }
- }
- }
- x1 = x2;
- y1 = y2;
- }
- for (int i = 0; i < n; i++)
- {
- for (int j = 0; j < m; j++)
- {
- if (matrix[i][j] == 'X')
- {
- int y = rand();
- for (int v = 0; v < 4; v++)
- {
- if (y % 8 == v)
- {
- if ((-1 < i + dx[v]) && (i + dx[v]) < n && (-1 < j + dy[v]) && (j + dy[v] < m) && matrix[i + dx[v]][j + dy[v]] == '.')
- {
- matrix[i][j] = '.';
- matrix[i + dx[v]][j + dy[v]] = 'X';
- }
- }
- if (y % 8 == v + 4)
- {
- if ((-1 < i + dx[v]) && (i + dx[v]) < n && (-1 < j + dy[v]) && (j + dy[v] < m) && matrix[i + dx[v]][j + dy[v]] == '.')
- {
- matrix[i + dx[v]][j + dy[v]] = '#';
- }
- }
- }
- if (y % 200 == 199)
- {
- cout << "AllllllaxAkbaaar" << endl;
- for (int sd = 0; sd < m; sd++)
- {
- if (matrix[sd][j] == 'O')
- {
- cout << "FFFFFFFFFFFFFFFFFFatality" << endl;
- ryt = true;
- }
- if (matrix[sd][j] == 'X')
- ty--;
- if (sd != i)
- {
- matrix[sd][j] = '#';
- }
- else
- {
- matrix[sd][j] = '.';
- ty--;
- }
- }
- }
- }
- }
- }
- bool g = bfs(x1, y1);
- if (ryt && !g)
- {
- for (int i = 0; i < n; i++)
- {
- for (int j = 0; j < m; j++)
- {
- cout << matrix[i][j];
- }
- cout << endl;
- }
- cout << "GameOver" << endl;
- return 0;
- }
- }
- for (int i = 0; i < n; i++)
- {
- for (int j = 0; j < m; j++)
- {
- cout << matrix[i][j];
- }
- cout << endl;
- }
- cout << "Izi vin";
- return 0;
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement