-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathpantalla.c
307 lines (242 loc) · 8.6 KB
/
pantalla.c
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
//------------------------------------------------------------------------------
// pantalla.c
//
// Authors:
// Luis Antonio Úbeda Medina (lubeme23@gmail.com)
// Héctor Veiga Ortiz (hveiga@hawk.iit.edu)
//
// Copyright 2010 Héctor Veiga Ortiz and Luis Antonio Úbeda Medina.
//
// This file is part of Coldtrix Game Suite.
//
// Coldtrix Game Suite is free software: you can redistribute it and/or modify
// it under the terms of the GNU General Public License as published by
// the Free Software Foundation, either version 3 of the License, or
// (at your option) any later version.
//
// Coldtrix Game Suite is distributed in the hope that it will be useful,
// but WITHOUT ANY WARRANTY; without even the implied warranty of
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
// GNU General Public License for more details.
//
// You should have received a copy of the GNU General Public License
// along with Coldtrix Game Suite. If not, see <http://www.gnu.org/licenses/>.
//------------------------------------------------------------------------------
#include "pantalla.h"
//------------------------------------------------------
// void seleccionarMensaje(int mensaje)
//
// Descripción:
// Muestra por consola el mensaje seleccionado
//------------------------------------------------------
void seleccionarMensaje(int mensaje) {
switch(mensaje) {
case MENSAJE0:
output("\nElija el nivel de dificultad del juego:\n- Pulse (1) Fácil\n- Pulse (4) Medio\n- Pulse (7) Difícil.\n");
break;
case MENSAJE1:
output("\nNivel seleccionado: Fácil.\n");
break;
case MENSAJE2:
output("\nNivel seleccionado: Medio.\n");
break;
case MENSAJE3:
output("\nNivel seleccionado: Difícil.\n");
break;
case MENSAJE4:
output("Tecla no válida.\n");
break;
case MENSAJE5:
output("Pulse A para comenzar la partida\n");
break;
case MENSAJE6:
output("Tecla no válida, por favor, pulse A para jugar\n");
break;
case MENSAJE7:
output("Empieza el juego!\n\n");
break;
case MENSAJE8:
output("\nPerdiste");
if(estado.juego==JUEGO_TETRIS){
output("\nNúmero de líneas completadas: ");
outNum(BASE10, resultado.lineas, OP_OUTNUM);
output("\nPuntos conseguidos: ");
outNum(BASE10, getResultado(), OP_OUTNUM);
output("\nTetris conseguidos: ");
outNum(BASE10, getTetris(), OP_OUTNUM);
output("\nTiempo empleado: ");
outNum(BASE10, getTiempo(), OP_OUTNUM);
output(" segundos");
output("\nFilas por segundo: ");
outNumDec(BASE10, getFilasPorSegundo(), NUM_DECIMALES, OP_OUTNUM);
output("\nPuntos por segundo: ");
outNumDec(BASE10, getPuntosPorSegundo(), NUM_DECIMALES, OP_OUTNUM);
}
if(estado.juego==JUEGO_SNAKE){
output("\nNúmero de alimentos obtenidos: ");
outNum(BASE10, resultado.comidas, OP_OUTNUM);
output("\nPuntos conseguidos: ");
outNum(BASE10, getResultado(), OP_OUTNUM);
output("\nTiempo empleado: ");
outNum(BASE10, getTiempo(), OP_OUTNUM);
output(" segundos");
output("\nComidas por segundo: ");
outNumDec(BASE10, getComidasPorSegundo(), NUM_DECIMALES, OP_OUTNUM);
}
output("\nPulse una tecla para continuar\n\n");
break;
case MENSAJE9:
output("\nSeleccione modo de juego:\n- Pulse (1) para el modo de nivel incremental\n- Pulse (4) para el modo normal\n- Pulse (7) para el modo de juego con bloques fijos\n");
break;
case MENSAJE10:
output(" ,-----. ,-----. ,--. ,------. ,--------.,------. ,--.,--. ,--.
' .--./' .-. '| | | .-. \\'--. .--'| .--. '| | \\ `.' /
| | | | | || | | | \\ : | | | '--'.'| | .' \\
' '--'\\' '-' '| '--.| '--' / | | | |\\ \\ | | / .'. \\
`-----' `-----' `-----'`-------' `--' `--' '--'`--''--' '--' ");
output("\nSeleccione juego:\n- Pulse (1) para el Tetris\n- Pulse (4) para Snake\n");
break;
case MENSAJE11:
output("\nSeleccione modo de juego:\n- Pulse (1) para el modo de nivel incremental\n- Pulse (4) para el modo normal\n");
break;
}
}
//------------------------------------------------------
// void pulsarA() {
//
// Descripción:
// Espera a pulsar 'A' para comenzar el juego
//------------------------------------------------------
void pulsarA() {
char inicio;
seleccionarMensaje(MENSAJE5); //Mensaje pulsar A
inicio = teclado();
while(inicio != CHAR_A){
inicio = teclado();
if(inicio != CHAR_A) seleccionarMensaje(MENSAJE6); //Mensaje tecla no valida, pulsar A
}
seleccionarMensaje(MENSAJE7); //Mensaje empieza el juego
}
//------------------------------------------------------
// int seleccionNivel(char tPulsada)
//
// Descripción:
// Selecciona un nivel de juego en caso
// contrario, espera a recibir un nivel correcto
//------------------------------------------------------
void seleccionNivel(void){
char tPulsada;
seleccionarMensaje(MENSAJE0); //Mensaje seleccion de nivel
reproducirDAC(DAC_NIVEL); //Reproducimos el mensaje por el DAC
tPulsada = teclado();
while(!((tPulsada == CHAR_UNO)|| (tPulsada == CHAR_CUATRO) || (tPulsada == CHAR_SIETE))){
seleccionarMensaje(MENSAJE4);
seleccionarMensaje(MENSAJE0); //Mensaje seleccion de nivel
tPulsada = teclado();
}
if(tPulsada == CHAR_UNO) {
seleccionarMensaje(MENSAJE1);//Mensaje seleccion de nivel facil
estado.nivel = FACIL;
}
if(tPulsada == CHAR_CUATRO) {
seleccionarMensaje(MENSAJE2); //Mensaje seleccion de nivel medio
estado.nivel = MEDIO;
}
if(tPulsada == CHAR_SIETE) {
seleccionarMensaje(MENSAJE3); //Mensaje seleccion de nivel dificil
estado.nivel = DIFICIL;
}
pulsarA();
estado.jugando = JUGANDO; //Empezamos a jugar
}
//------------------------------------------------------
// int seleccionTipoNivel(void)
//
// Descripción:
// Selecciona un nivel de juego en caso
// contrario, espera a recibir un nivel correcto
//------------------------------------------------------
void seleccionTipoNivel(void){
char tecla;
seleccionarMensaje(MENSAJE9); //Mensaje seleccion de modo
reproducirDAC(DAC_MODO); //Reproducimos el mensaje por el DAC
tecla = teclado();
while(!((tecla == CHAR_UNO) || (tecla == CHAR_CUATRO) || (tecla == CHAR_SIETE))) {
seleccionarMensaje(MENSAJE4);
seleccionarMensaje(MENSAJE9); //Mensaje seleccion de modo
tecla = teclado();
}
if(tecla == CHAR_UNO) {
estado.nivelIncremental = TRUE;
estado.juegoBloques = FALSE;
estado.nivel = FACIL;
pulsarA();
estado.jugando = JUGANDO;
}
if(tecla == CHAR_CUATRO) {
estado.nivelIncremental = FALSE;
estado.juegoBloques = FALSE;
seleccionNivel();
}
if(tecla == CHAR_SIETE) {
estado.nivelIncremental = FALSE;
estado.juegoBloques = TRUE;
seleccionNivel();
}
}
//------------------------------------------------------
// int seleccionModoSerp(void)
//
// Descripción:
// Selecciona un nivel de juego en caso
// contrario, espera a recibir un nivel correcto
//------------------------------------------------------
void seleccionModoSerp(void){
char tecla;
seleccionarMensaje(MENSAJE11); //Mensaje seleccion de modo
reproducirDAC(DAC_MODO); //Reproducimos el mensaje por el DAC
tecla = teclado();
while(!((tecla == CHAR_UNO) || (tecla == CHAR_CUATRO))) {
seleccionarMensaje(MENSAJE4);
seleccionarMensaje(MENSAJE11); //Mensaje seleccion de modo
tecla = teclado();
}
if(tecla == CHAR_UNO) {
estado.nivelIncremental = TRUE;
estado.juegoBloques = FALSE;
estado.nivel = FACIL;
pulsarA();
estado.jugando = JUGANDO;
}
if(tecla == CHAR_CUATRO) {
estado.nivelIncremental = FALSE;
estado.juegoBloques = FALSE;
seleccionNivel();
}
}
//------------------------------------------------------
// int seleccionJuego(void)
//
// Descripción:
// Selecciona un nivel de juego en caso
// contrario, vuelve a preguntar
//------------------------------------------------------
void seleccionJuego(void){
char tecla;
seleccionarMensaje(MENSAJE10); //Mensaje seleccion de juego
reproducirDAC(DAC_JUEGO); //Reproducimos el mensaje por el DAC
tecla = teclado();
while(!((tecla == CHAR_UNO) || (tecla == CHAR_CUATRO))) {
seleccionarMensaje(MENSAJE4);
seleccionarMensaje(MENSAJE10); //Mensaje seleccion de juego
tecla = teclado();
}
if(tecla == CHAR_UNO) {
estado.juego = JUEGO_TETRIS;
}
if(tecla == CHAR_CUATRO) {
estado.juego = JUEGO_SNAKE;
}
if(estado.juego == JUEGO_TETRIS) { seleccionTipoNivel(); }
if(estado.juego == JUEGO_SNAKE) { seleccionModoSerp(); }
}