Advertisement
Guest User

Untitled

a guest
Nov 14th, 2019
123
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 2.13 KB | None | 0 0
  1. #include <stdio.h>
  2. #pragma warning(disable:4996)
  3. #define N 10
  4. #define MAX_MOVES 30
  5.  
  6. void Draw(char s[][N], int how_many_X, int moves);
  7. void Update(char s[][N], int row, int column, int *how_many_X);
  8.  
  9. int main()
  10. {
  11. int moves = 0;
  12. char tab[N][N];
  13. int i, j, row, column, how_many_X = 0;
  14. for (i = 0; i < N; i++)
  15. for (j = 0; j < N; j++)
  16. tab[i][j] = '0';
  17.  
  18. ////////////
  19. while (how_many_X != N*N && moves != MAX_MOVES)
  20. {
  21. Draw(tab, how_many_X,MAX_MOVES- moves);
  22.  
  23. do
  24. {
  25. row = -1;
  26. printf("\nNumer wiersza: ");
  27. if(scanf("%d", &row) != 1) row = -1;
  28. while (getchar() != '\n');
  29. if (!(row >= 0 && row <= 9)) printf("Blad. Wpisz jeszcze raz\n");
  30. } while (!(row >= 0 && row <= 9));
  31. do
  32. {
  33. column = -1;
  34. printf("Numer kolumny: ");
  35. if (scanf("%d", &column) != 1) column = -1;
  36. while (getchar() != '\n');
  37. if (!(column >= 0 && column <= 9)) printf("Blad. Wpisz jeszcze raz\n");
  38. } while (!(column >= 0 && column <= 9));
  39.  
  40.  
  41. Update(tab, row, column, &how_many_X);
  42. moves++;
  43. }
  44. system("cls");
  45. printf("Koniec gry.\n");
  46. for (i = 0; i < N; i++)
  47. printf("%d", i);
  48. printf("\n");
  49. for (i = 0; i < N; i++)
  50. {
  51. printf("%d", i);
  52. for (j = 0; j < N; j++)
  53. printf("%c", tab[i][j]);
  54. printf("\n");
  55. }
  56. return 0;
  57. }
  58.  
  59. void Draw(char s[][N], int how_many_X, int moves) //
  60. {
  61. system("cls");
  62. int i, j;
  63. printf("Liczba ruchow: %d\n", moves);
  64. printf("Pozostalo jeszcze %d pol do zamiany\n\n", N * N - how_many_X);
  65. printf(" ");
  66. for (i = 0; i < N; i++)
  67. printf("%d", i);
  68. printf("\n");
  69. for (i = 0; i < N; i++)
  70. {
  71. printf("%d", i);
  72. for (j = 0; j < N; j++)
  73. printf("%c", s[i][j]);
  74. printf("\n");
  75. }
  76. }
  77.  
  78. void Update(char s[][N], int row, int column, int *how_many_X)
  79. {
  80. if (s[row][column+1] != 'X' && column != N-1)
  81. {
  82. s[row][column+1] = 'X';
  83. ++*how_many_X;
  84. }
  85. if (s[row][column-1] != 'X' && column != 0)
  86. {
  87. s[row][column-1] = 'X';
  88. ++*how_many_X;
  89. }
  90. if (s[row + 1][column] != 'X' && row != N-1)
  91. {
  92. s[row+1][column] = 'X';
  93. ++*how_many_X;
  94. }
  95. if (s[row - 1][column] != 'X' && row != 0)
  96. {
  97. s[row-1][column] = 'X';
  98. ++*how_many_X;
  99. }
  100. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement