Advertisement
Guest User

Untitled

a guest
Jan 20th, 2017
87
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.79 KB | None | 0 0
  1. #include <iostream>
  2. using namespace std;
  3. int const n = 8;
  4. int GP [n][n];
  5. bool player, isStarted;
  6. int x, y;
  7.  
  8. void PrintGP()
  9. {
  10. for (int i=0; i<n; i++)
  11. {
  12. for (int j=0; j<n;j++)
  13. {
  14. cout<<GP[i][j]<<' ';
  15. }
  16. cout<<endl;
  17. }
  18. }
  19. void SetingGame ()
  20. {
  21. player = true;
  22. for (int i=0; i<n; i++)
  23. {
  24. for (int j=0; j<n;j++)
  25. {
  26. GP[i][j]=0;
  27. }
  28. }
  29.  
  30. }
  31.  
  32. bool CheckNeighbours(){
  33. for(int i = x - 1; i <= x + 1; i++)
  34. for(int j = y - 1; j<=y+1;j++)
  35. if (i >= 0 && i < 8 && j >= 0 && j < 8)
  36. if (GP[i][j] != 0)
  37. return true;
  38.  
  39.  
  40.  
  41.  
  42.  
  43. return false;
  44. }
  45.  
  46. bool ifAviable(){
  47.  
  48. cin >> x >> y;
  49.  
  50. if (GP[x][y] == 0){
  51. if (isStarted == false){
  52. if (player == true)
  53. GP[x][y]=1;
  54. else
  55. GP[x][y]=2;
  56. player=!player;
  57. isStarted = !isStarted;
  58. system ("cls");
  59.  
  60. return true;
  61. }
  62. if (CheckNeighbours()){
  63. if (player == true)
  64. GP[x][y]=1;
  65. else
  66. GP[x][y]=2;
  67. player=!player;
  68. system ("cls");
  69.  
  70. return true;
  71. }
  72. }
  73. system ("cls");
  74. PrintGP();
  75. cout << "Ошибка 404: Свободная клетка не найдена! Повторте попытку:\n";
  76. return false;
  77. }
  78.  
  79. int main () {
  80. setlocale(0, "Russian");
  81. SetingGame();
  82. isStarted = false;
  83. for(int hod=0; hod<64; hod++)
  84. {
  85. PrintGP ();
  86. bool Aviable = false;
  87. if (player)
  88. {
  89. cout << "Игрок 1, введите координаты:\n";
  90. while (!Aviable)
  91. if (ifAviable())
  92. Aviable = !Aviable;
  93. }
  94.  
  95. else
  96. {
  97. cout << "Игрок 2, введите координаты:\n";
  98. while (!Aviable)
  99. if (ifAviable())
  100. Aviable = true;
  101. }
  102. }
  103. system ("pause");
  104. return 0;
  105. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement