Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #include <stdio.h>
- #define LINES 5
- #define COLS 5
- #define BOMB -1
- #define WATER 0
- #define BOMB_HIT -2
- #define SHIP_HIT -3
- #define WATER_HIT -4
- void generateBoard(int board[LINES][COLS]) {
- }
- void printBoard(int board[LINES][COLS]) {
- int i, j;
- char c;
- for (i = 0; i < LINES; i++) {
- for (j = 0; j < COLS; j++) {
- if (board[i][j] == BOMB_HIT)
- c = 'B';
- else if (board[i][j] == SHIP_HIT)
- c = 'N';
- else if (board[i][j] == WATER_HIT)
- c = 'A';
- else
- c = 'X';
- printf("%c ", c);
- }
- printf("\n");
- }
- }
- int main() {
- int running = 1;
- int atk_line, atk_col;
- // Creates the players.
- int player[LINES][COLS];
- int opponent[LINES][COLS];
- // Bombs hit counter.
- int opponent_bombsHit = 0;
- int player_bombsHit = 0;
- while (running) {
- do {
- printf("\nDigite a linha que você deseja atacar.\n");
- scanf(" %d", &atk_line);
- printf("\nDigite a coluna que você deseja atacar.\n");
- scanf(" %d", &atk_col);
- if (opponent[atk_line][atk_col] <= BOMB_HIT)
- printf("\nVocê já atacou essa posição. Escolha outra.\n");
- } while(opponent[atk_line][atk_col] <= BOMB_HIT);
- // Checa o que o jogador acertou.
- if (opponent[atk_line][atk_col] == BOMB) {
- player_bombsHit++;
- opponent[atk_line][atk_col] = BOMB_HIT;
- printf("\nVocê acertou uma bomba! Você já acertou %d bomba(s), se acertar três, você perde.\n", player_bombsHit);
- } else if (opponent[atk_line][atk_col] > 0) {
- opponent[atk_line][atk_col] = SHIP_HIT;
- printf("\nVocê acertou a parte de um navio do oponente.\n");
- } else if (opponent[atk_line][atk_col] == WATER) {
- opponent[atk_line][atk_col] = WATER_HIT;
- printf("\nQue pena, você não acertou nada.\n");
- }
- printf("\nIsso é o que você já sabe do seu oponente no momento.\n");
- printBoard(opponent);
- if (player_bombsHit >= 3) {
- running = 0;
- printf("\nQue pena, você perdeu.\n");
- }
- }
- return 0;
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement