Advertisement
Guest User

Untitled

a guest
Nov 14th, 2019
120
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 2.00 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. printf("\nNumer wiersza: ");
  26. scanf("%d", &row);
  27. if (!(row >= 0 && row <= 9)) printf("Blad. Wpisz jeszcze raz\n");
  28. } while (!(row >= 0 && row <= 9));
  29. do
  30. {
  31. printf("Numer kolumny: ");
  32. scanf("%d", &column);
  33. if (!(column >= 0 && column <= 9)) printf("Blad. Wpisz jeszcze raz\n");
  34. } while (!(column >= 0 && column <= 9));
  35.  
  36.  
  37. Update(tab, row, column, &how_many_X);
  38. moves++;
  39. }
  40. system("cls");
  41. printf("Koniec gry.\n");
  42. for (i = 0; i < N; i++)
  43. printf("%d", i);
  44. printf("\n");
  45. for (i = 0; i < N; i++)
  46. {
  47. printf("%d", i);
  48. for (j = 0; j < N; j++)
  49. printf("%c", tab[i][j]);
  50. printf("\n");
  51. }
  52. return 0;
  53. }
  54.  
  55. void Draw(char s[][N], int how_many_X, int moves) //
  56. {
  57. system("cls");
  58. int i, j;
  59. printf("Liczba ruchow: %d\n", moves);
  60. printf("Pozostalo jeszcze %d pol do zamiany\n\n", N * N - how_many_X);
  61. printf(" ");
  62. for (i = 0; i < N; i++)
  63. printf("%d", i);
  64. printf("\n");
  65. for (i = 0; i < N; i++)
  66. {
  67. printf("%d", i);
  68. for (j = 0; j < N; j++)
  69. printf("%c", s[i][j]);
  70. printf("\n");
  71. }
  72. }
  73.  
  74. void Update(char s[][N], int row, int column, int *how_many_X)
  75. {
  76. if (s[row][column+1] != 'X' && column != N-1)
  77. {
  78. s[row][column+1] = 'X';
  79. ++*how_many_X;
  80. }
  81. if (s[row][column-1] != 'X' && column != 0)
  82. {
  83. s[row][column-1] = 'X';
  84. ++*how_many_X;
  85. }
  86. if (s[row + 1][column] != 'X' && row != N-1)
  87. {
  88. s[row+1][column] = 'X';
  89. ++*how_many_X;
  90. }
  91. if (s[row - 1][column] != 'X' && row != 0)
  92. {
  93. s[row-1][column] = 'X';
  94. ++*how_many_X;
  95. }
  96. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement