-
Notifications
You must be signed in to change notification settings - Fork 0
/
update.c
138 lines (117 loc) · 3.21 KB
/
update.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
#include <stdio.h>
#include <curses.h>
#include <stdlib.h>
#include <string.h>
#include <unistd.h>
#include <poll.h> // poll(), struct pollfd e POLLIN
#include <time.h>
#include "Structs/sala.h"
#include "Structs/jogador.h"
#include "Structs/inimigo.h"
int deseja_salvar();
void ganhou(void);
// Atualiza uma instancia de mundo, se passando deltaTime segundos
int update(SALA *sala)
{
int i, c;
char mesg[] = "Pontuacao: %d Vida: %d Nivel: %d";
while (sala->link.vida != 0)
{
mvprintw(2, (COLS - strlen(mesg)) / 2, "Pontuacao: %d Vida: %d Nivel: %d", sala->link.pont, sala->link.vida, sala->link.nivel);
for (i = 0; i < sala->numInis; i++)
{
updateInimigo(sala, &sala->inis[i], timeIni);
}
// cada lance do timer o jogador pode se mover
if (sala->link.timer >= 1)
{
mvprintw(5, (COLS - strlen(mesg)) / 2, "Debugger: %f sala->link.timer entrou no if", sala->link.timer);
//sala->link.timer = 0;
c = getch();
mvprintw(7, (COLS - strlen(mesg)) / 2, "Debugger: %d", c);
refresh();
if (c == ESC)
{
if (deseja_salvar() == 0)
{
salva_sala(sala);
}
return 0;
}
move_jogador(sala, c);
}
else
{
// Aumeta o timer
sala->link.timer += timeLink;
mvprintw(4, (COLS - strlen(mesg)) / 2, "Debugger: %f sala->link.timer", sala->link.timer);
}
}
ganhou();
return 0;
}
int deseja_salvar()
{
int i, c = 5, selecionado = 0, selecao = 0;
char mesg1[] = "Deseja salvar o jogo?";
char *op[] = {
"Sim",
"Nao",
};
clear();
refresh();
mvprintw(LINES / 2, (COLS - strlen(mesg1)) / 2, mesg1);
while (1)
{
for (i = 0; i < 2; i++)
{
if (i == selecionado)
attron(A_REVERSE);
if (i)
{
mvprintw((LINES / 2) + 1, ((COLS - strlen(op[i])) / 2) + (i * 5), op[i]);
}
else
{
mvprintw((LINES / 2) + 1, ((COLS - strlen(op[i])) / 2) - 5, op[i]);
}
if (i == selecionado)
attroff(A_REVERSE);
}
selecao = getch();
switch (selecao)
{
case KEY_LEFT:
selecionado--;
if (selecionado < 0)
selecionado = 0;
break;
case KEY_RIGHT:
selecionado++;
if (selecionado > 1)
selecionado = 1;
break;
default:
break;
}
if (selecao == 10)
break;
}
refresh();
clear();
return selecionado;
}
void ganhou(){
char mesg1[] = "Parabens!!!";
char mesg2[] = "Voce terminou o jogo";
char mesg5[] = "Aperte qualquer tecla para voltar ao menu...";
clear();
//refresh();
mvprintw(LINES / 2, (COLS - strlen(mesg1)) / 2, mesg1);
mvprintw(LINES / 2 + 1, (COLS - strlen(mesg2)) / 2, mesg2);
refresh();
sleep(5);
mvprintw(LINES / 2 + 6, (COLS - strlen(mesg5)) / 2, mesg5);
getch();
clear();
}