Advertisement
Guest User

Untitled

a guest
Aug 22nd, 2017
72
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.89 KB | None | 0 0
  1. #include <stdio.h>
  2.  
  3. #define LINES 5
  4. #define COLS 5
  5.  
  6. #define BOMB -1
  7. #define WATER 0
  8.  
  9. #define BOMB_HIT -2
  10. #define SHIP_HIT -3
  11. #define WATER_HIT -4
  12.  
  13. void generateBoard(int board[LINES][COLS]) {
  14.  
  15. }
  16.  
  17. void printBoard(int board[LINES][COLS]) {
  18. int i, j;
  19. char c;
  20.  
  21. for (i = 0; i < LINES; i++) {
  22. for (j = 0; j < COLS; j++) {
  23. if (board[i][j] == BOMB_HIT)
  24. c = 'B';
  25. else if (board[i][j] == SHIP_HIT)
  26. c = 'N';
  27. else if (board[i][j] == WATER_HIT)
  28. c = 'A';
  29. else
  30. c = 'X';
  31.  
  32. printf("%c ", c);
  33. }
  34. printf("\n");
  35. }
  36. }
  37.  
  38. int main() {
  39. int running = 1;
  40.  
  41. int atk_line, atk_col;
  42.  
  43. // Creates the players.
  44. int player[LINES][COLS];
  45. int opponent[LINES][COLS];
  46.  
  47. // Bombs hit counter.
  48. int opponent_bombsHit = 0;
  49. int player_bombsHit = 0;
  50.  
  51. while (running) {
  52.  
  53. do {
  54. printf("\nDigite a linha que você deseja atacar.\n");
  55. scanf(" %d", &atk_line);
  56.  
  57. printf("\nDigite a coluna que você deseja atacar.\n");
  58. scanf(" %d", &atk_col);
  59.  
  60. if (opponent[atk_line][atk_col] <= BOMB_HIT)
  61. printf("\nVocê já atacou essa posição. Escolha outra.\n");
  62.  
  63. } while(opponent[atk_line][atk_col] <= BOMB_HIT);
  64.  
  65. // Checa o que o jogador acertou.
  66. if (opponent[atk_line][atk_col] == BOMB) {
  67. player_bombsHit++;
  68. opponent[atk_line][atk_col] = BOMB_HIT;
  69. printf("\nVocê acertou uma bomba! Você já acertou %d bomba(s), se acertar três, você perde.\n", player_bombsHit);
  70. } else if (opponent[atk_line][atk_col] > 0) {
  71. opponent[atk_line][atk_col] = SHIP_HIT;
  72. printf("\nVocê acertou a parte de um navio do oponente.\n");
  73. } else if (opponent[atk_line][atk_col] == WATER) {
  74. opponent[atk_line][atk_col] = WATER_HIT;
  75. printf("\nQue pena, você não acertou nada.\n");
  76. }
  77.  
  78. printf("\nIsso é o que você já sabe do seu oponente no momento.\n");
  79. printBoard(opponent);
  80.  
  81. if (player_bombsHit >= 3) {
  82. running = 0;
  83. printf("\nQue pena, você perdeu.\n");
  84. }
  85.  
  86. }
  87.  
  88. return 0;
  89. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement