Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #include <stdio.h>
- #pragma warning(disable:4996)
- #define N 10
- #define MAX_MOVES 30
- void Draw(char s[][N], int how_many_X, int moves);
- void Update(char s[][N], int row, int column, int *how_many_X);
- int main()
- {
- int moves = 0;
- char tab[N][N];
- int i, j, row, column, how_many_X = 0;
- for (i = 0; i < N; i++)
- for (j = 0; j < N; j++)
- tab[i][j] = '0';
- ////////////
- while (how_many_X != N*N && moves != MAX_MOVES)
- {
- Draw(tab, how_many_X,MAX_MOVES- moves);
- do
- {
- printf("\nNumer wiersza: ");
- scanf("%d", &row);
- if (!(row >= 0 && row <= 9)) printf("Blad. Wpisz jeszcze raz\n");
- } while (!(row >= 0 && row <= 9));
- do
- {
- printf("Numer kolumny: ");
- scanf("%d", &column);
- if (!(column >= 0 && column <= 9)) printf("Blad. Wpisz jeszcze raz\n");
- } while (!(column >= 0 && column <= 9));
- Update(tab, row, column, &how_many_X);
- moves++;
- }
- system("cls");
- printf("Koniec gry.\n");
- for (i = 0; i < N; i++)
- printf("%d", i);
- printf("\n");
- for (i = 0; i < N; i++)
- {
- printf("%d", i);
- for (j = 0; j < N; j++)
- printf("%c", tab[i][j]);
- printf("\n");
- }
- return 0;
- }
- void Draw(char s[][N], int how_many_X, int moves) //
- {
- system("cls");
- int i, j;
- printf("Liczba ruchow: %d\n", moves);
- printf("Pozostalo jeszcze %d pol do zamiany\n\n", N * N - how_many_X);
- printf(" ");
- for (i = 0; i < N; i++)
- printf("%d", i);
- printf("\n");
- for (i = 0; i < N; i++)
- {
- printf("%d", i);
- for (j = 0; j < N; j++)
- printf("%c", s[i][j]);
- printf("\n");
- }
- }
- void Update(char s[][N], int row, int column, int *how_many_X)
- {
- if (s[row][column+1] != 'X' && column != N-1)
- {
- s[row][column+1] = 'X';
- ++*how_many_X;
- }
- if (s[row][column-1] != 'X' && column != 0)
- {
- s[row][column-1] = 'X';
- ++*how_many_X;
- }
- if (s[row + 1][column] != 'X' && row != N-1)
- {
- s[row+1][column] = 'X';
- ++*how_many_X;
- }
- if (s[row - 1][column] != 'X' && row != 0)
- {
- s[row-1][column] = 'X';
- ++*how_many_X;
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement