Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #include <stdio.h>
- #include <stdlib.h>
- #include <time.h>
- #include <unistd.h>
- #define N 5
- #define M 5
- #define EMPTY ' '
- #define NAVE 'N'
- #define PROIETTILE 'P'
- #define COLPITO 'C'
- #define AFFONDATO 'A'
- char board[N][N] = {EMPTY};
- void inizializza_scacchiera(char board[N][N]);
- void mostra_scacchiera(char board[N][N]);
- void mossa_umano(char board[N][N]);
- int main()
- {
- inizializza_scacchiera(board);
- mostra_scacchiera(board);
- system("PAUSE");
- }
- void inizializza_scacchiera(char board[N][N])
- {
- srand(time(NULL));
- int i, j, k, tmprand, status;
- int rand_val[M] = {0};
- for (i = 0; i < M; i++)
- {
- do
- {
- status = 0;
- tmprand = rand() % (N*N);
- for (j = 0; j < M; j++)
- {
- if (rand_val[j] == tmprand)
- {
- status = 1;
- }
- }
- if (status == 0)
- {
- rand_val[i] = tmprand;
- }
- } while(status == 1);
- }
- for (k = 0; k < M; k++)
- {
- board[rand_val[k] / 5][rand_val[k] % 5] = NAVE;
- }
- }
- void mostra_scacchiera(char board[N][N])
- {
- int i, j;
- for(i=0; i < N+2; i++)
- printf("-");
- printf("\n");
- for(i=0; i < N; i++)
- {
- printf("|");
- for(j=0; j < N; j++)
- {
- printf("%c", board[i][j]);
- }
- printf("|\n");
- }
- for(i=0; i < N+2; i++)
- printf("-");
- printf("\n");
- }
- void mossa_umano(char board[N][N])
- {
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement