Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #include <iostream>
- using namespace std;
- int const n = 8;
- int GP [n][n];
- bool player, isStarted;
- int x, y;
- void PrintGP()
- {
- for (int i=0; i<n; i++)
- {
- for (int j=0; j<n;j++)
- {
- cout<<GP[i][j]<<' ';
- }
- cout<<endl;
- }
- }
- void SetingGame ()
- {
- player = true;
- for (int i=0; i<n; i++)
- {
- for (int j=0; j<n;j++)
- {
- GP[i][j]=0;
- }
- }
- }
- bool CheckNeighbours(){
- for(int i = x - 1; i <= x + 1; i++)
- for(int j = y - 1; j<=y+1;j++)
- if (i >= 0 && i < 8 && j >= 0 && j < 8)
- if (GP[i][j] != 0)
- return true;
- return false;
- }
- bool ifAviable(){
- cin >> x >> y;
- if (GP[x][y] == 0){
- if (isStarted == false){
- if (player == true)
- GP[x][y]=1;
- else
- GP[x][y]=2;
- player=!player;
- isStarted = !isStarted;
- system ("cls");
- return true;
- }
- if (CheckNeighbours()){
- if (player == true)
- GP[x][y]=1;
- else
- GP[x][y]=2;
- player=!player;
- system ("cls");
- return true;
- }
- }
- system ("cls");
- PrintGP();
- cout << "Ошибка 404: Свободная клетка не найдена! Повторте попытку:\n";
- return false;
- }
- int main () {
- setlocale(0, "Russian");
- SetingGame();
- isStarted = false;
- for(int hod=0; hod<64; hod++)
- {
- PrintGP ();
- bool Aviable = false;
- if (player)
- {
- cout << "Игрок 1, введите координаты:\n";
- while (!Aviable)
- if (ifAviable())
- Aviable = !Aviable;
- }
- else
- {
- cout << "Игрок 2, введите координаты:\n";
- while (!Aviable)
- if (ifAviable())
- Aviable = true;
- }
- }
- system ("pause");
- return 0;
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement