0% found this document useful (0 votes)
64 views3 pages

Campo - Minado.c Bernardo Alves Costa Pereira Campominadorafael.c Rafael Parreira Chequer

The document contains code from two C programs that implement a minesweeper game. The first program tracks the number of safe spaces and checks if the player loses by clicking a mine. The second program tracks the number of mines on the board, checks for valid moves, and checks surrounding spaces to determine if they are mines or safe. It also tracks the number of correct guesses and checks for errors on the player's turn.
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
64 views3 pages

Campo - Minado.c Bernardo Alves Costa Pereira Campominadorafael.c Rafael Parreira Chequer

The document contains code from two C programs that implement a minesweeper game. The first program tracks the number of safe spaces and checks if the player loses by clicking a mine. The second program tracks the number of mines on the board, checks for valid moves, and checks surrounding spaces to determine if they are mines or safe. It also tracks the number of correct guesses and checks for errors on the player's turn.
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
You are on page 1/ 3

campo_minado.c Bernardo Alves Costa Pereira campominadorafael.

c Rafael Parreira Chequer


1 #include <stdio.h> === 1 #include <stdio.h>
2 #include <stdbool.h> =## 2 #include <stdlib.h>
3 === 3
>>> 4 struct teste
4 struct ponto { =## 5 {
5 int coordX; =## 6 int x;
6 int coordY; =## 7 int y;
7 }; === 8 };
8 <<<
9 int main(void) =## 9 int main()
10 { === 10 {
11 int num; =## 11 int jogos;
12 scanf("%d", &num); =## 12 scanf("%d",&jogos);
13 <<<
14 for (int z = 0; z < num; z++) =## 13 for (int a = 0; a < jogos; a++)
15 { === 14 {
16 int tamanho; =## 15 int lado;
17 scanf("%d", &tamanho); =## 16 scanf("%d", &lado);
>>> 17 char tabuleiro[lado][lado];
18 getchar(); === 18 getchar();
19 <<<
20 char tab[tamanho][tamanho]; <<<
21 int safes_counter = 0; ### 19 int numerox = 0;
22 for (int i = 0; i < tamanho; i++) =## 20 for (int i = 0; i < lado; i++)
23 { === 21 {
24 for (int j = 0; j < tamanho; j++) =## 22 for (int j = 0; j < lado; j++)
25 { === 23 {
26 scanf("%c", &tab[i][j]); =## 24 scanf("%c", &tabuleiro[i][j]);
27 getchar(); === 25 getchar();
28 if (tab[i][j] == 'x') =## 26 if (tabuleiro[i][j] == 'x')
>>> 27 {
>>> 28 numerox++;
29 safes_counter++; ### 29 }
30 } === 30 }
31 } === 31 }
>>> 32 int jogadas;
32 ### 33 int x , y;
33 bool lost = false; =## 34 int erro = 0;
34 int n, coordX, coordY; <<<
35 int counter = 0; =## 35 int contador = 0;
36 struct ponto ponto; =## 36 struct teste t1;
37 struct ponto checked[tamanho*tamanho]; =## 37 struct teste t2[lado*lado];
38 <<<
39 scanf("%d", &n); =## 38 scanf("%d", &jogadas);
40 for (int k = 0; k < n; k++) =## 39 for (int b = 0; b < jogadas; b++)
41 { === 40 {
>>> 41 scanf("%d",&x);
42 scanf("%d %d", &coordX, &coordY); ### 42 scanf("%d",&y);
43 if (tab[coordX][coordY] == 'b') { ### 43 if(tabuleiro[x][y] == 'b')
>>> 44 {
44 lost = true; =## 45 erro = 1;
45 } === 46 }
>>> 47 else
46 else { =## 48 {
47 bool mark = false; =## 49 int referencia = 0;
48 for (int i = -1; i <= 1; i++) { ### 50 for (int f = -1; f <= 1; f++)
>>> 51 {
49 if (coordX+i < 0 || coordX+i > tamanho =## 52 if (x+f < 0 || x+f > lado-1)
>>> 53 {
50 continue; === 54 continue;
51 ### 55 }
52 for (int j = -1; j <= 1; j++) { ### 56 for (int g = -1; g <= 1; g++)
>>> 57 {
53 if (coordY+j < 0 || coordY+j > tama =## 58 if (y+g < 0 || y+g > lado-1)
>>> 59 {
54 continue; === 60 continue;
55 ### 61 }
56 if (tab[coordX+i][coordY+j] == 'b' =## 62 if (tabuleiro[x+f][y+g] == 'b')
>>> 63 {
57 mark = true; =## 64 referencia = 1;
>>> 65 }
58 } === 66 }
59 } === 67 }
60 if (!mark) ### 68 if (referencia == 0)
61 { === 69 {
62 for (int i = -1; i <= 1; i++) { ### 70 for (int f = -1; f <= 1; f++)
>>> 71 {
63 if (coordX+i < 0 || coordX+i > tama =## 72 if (x+f < 0 || x+f > lado-1)
>>> 73 {
64 continue; === 74 continue;
65 ### 75 }
66 for (int j = -1; j <= 1; j++) { ### 76 for (int g = -1; g <= 1; g++)
>>> 77 {
67 if (coordY+j < 0 || coordY+j > =## 78 if (y+g < 0 || y+g > lado-1)
>>> 79 {
68 continue; === 80 continue;
69 ### 81 }
70 if (!counter) { ### 82 if (!contador)
>>> 83 {
71 ponto.coordX = coordX+i; =## 84 t1.x = x+f;
72 ponto.coordY = coordY+j; =## 85 t1.y = y+g;
73 checked[counter] = ponto; =## 86 t2[contador] = t1;
74 counter++; =## 87 contador++;
75 } === 88 }
>>> 89 else
76 else { =## 90 {
77 bool check = false; =## 91 int verificado = 0;
78 ponto.coordX = coordX+i; =## 92 t1.x = x+f;
79 ponto.coordY = coordY+j; =## 93 t1.y = y+g;
80 for (int l = 0; l < counter =## 94 for (int c = 0; c < contado
81 { === 95 {
82 if (checked[l].coordX = ### 96 if (t2[c].x == t1.x &&
>>> 97 {
83 check = true; =## 98 verificado = 1;
84 break; === 99 break;
85 } === 100 }
86 } === 101 }
87 if (!check) { ### 102 if (verificado == 0)
>>> 103 {
88 checked[counter] = pont =## 104 t2[contador] = t1;
89 counter++; =## 105 contador++;
90 } === 106 }
91 } === 107 }
92 } === 108 }
93 } === 109 }
94 } === 110 }
>>> 111 else
95 else { =## 112 {
96 ponto.coordX = coordX; =## 113 t1.x = x;
97 ponto.coordY = coordY; =## 114 t1.y = y;
98 checked[counter] = ponto; =## 115 t2[contador] = t1;
99 counter++; =## 116 contador++;
100 } === 117 }
101 } === 118 }
102 } === 119 }
103 if (lost) ### 120 if(erro == 1)
>>> 121 {
104 printf("PERDEU\n"); === 122 printf("PERDEU\n");
>>> 123 }
105 else ### 124 else if(numerox != contador)
106 { === 125 {
107 if (safes_counter == counter) <<<
108 printf("GANHOU\n"); =## 126 printf("FALTOU TERMINAR\n");
>>> 127 }
109 else ==# 128 else
>>> 129 {
110 printf("FALTOU TERMINAR\n"); =## 130 printf("GANHOU\n");
111 } === 131 }
112 } === 132 }
113 return 0; ### 133 exit(0);
114 } === 134 }

You might also like