Me gustaria saber porque los objetos que se invocan dejan un rastro azul
Publicado por Jon Jairo (2 intervenciones) el 14/05/2016 21:18:31
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
#include<stdio.h>
#include<windows.h>
#include<conio.h>
#include<stdlib.h>
#define ARRIBA 72
#define IZQUIERDA 75
#define DERECHA 77
#define ABAJO 80
void gotoxy(int x, int y){
HANDLE hCon;
hCon = GetStdHandle(STD_OUTPUT_HANDLE);COORD dwPos;
dwPos.X = x;
dwPos.Y = y;
SetConsoleCursorPosition(hCon, dwPos);
}
void OcultarCursor()
{
HANDLE hCon;
hCon = GetStdHandle(STD_OUTPUT_HANDLE);
CONSOLE_CURSOR_INFO pene;
pene.dwSize = 2;
pene.bVisible = FALSE;
SetConsoleCursorInfo(hCon,&pene );
}
void pintar_limites(){
for (int i = 2; i<78 ; i++){
gotoxy(i,3); printf("%c",205);
gotoxy(i,23); printf("%c",205);
}
for(int i = 4; i < 23 ; i++){
gotoxy(2,i);printf("%c",186);
gotoxy(77,i);printf("%c",186);
}
gotoxy(2,3);printf("%c",201);
gotoxy(2,23);printf("%c",200);
gotoxy(77,3);printf("%c",187);
gotoxy(77,23);printf("%c",188);
}
class COCHE{
int x, y;
int corazones;
int vidas;
public:
COCHE(int _x, int _y, int _corazones, int _vidas):x(_x),y(_y),corazones(_corazones), vidas(_vidas){};
void Pintura();
void Borrar();
void mover ();
void pintar_corazones();
void morir();
};
void COCHE::Pintura(){
gotoxy(x,y); printf("ccCCCcc");
gotoxy(x,y+1);printf(" CCC ");
gotoxy(x,y+2);printf(" CCC ");
gotoxy(x,y+3);printf("ccCCCcc");
}
void COCHE::Borrar(){
gotoxy(x,y); printf(" ");
gotoxy(x,y+1);printf(" ");
gotoxy(x,y+2);printf(" ");
gotoxy(x,y+3);printf(" ");
}
void COCHE::mover(){
if(_kbhit()){
char tecla = _getch();
Borrar();
if(tecla == IZQUIERDA && x > 3) x--;
if(tecla == DERECHA && x+7 < 76) x++;
if(tecla == ARRIBA && y > 4) y--;
if(tecla == ABAJO && y+3 < 22) y++;
if(tecla == 'e')corazones--;
if(tecla == 'r')corazones++;
Pintura();
pintar_corazones();
}
}
void COCHE::pintar_corazones(){
gotoxy(50,2);printf("VIDAS %d",vidas);
gotoxy(64,2); printf("Salud");
gotoxy(70,2); printf(" ");
for (int i = 0 ; i < corazones; i++){
gotoxy(70+i,2); printf("%c",3);
}
}
void COCHE::morir(){
if(corazones == 0 )
{
Borrar();
gotoxy(x,y) ;printf(" ** ");
gotoxy(x,y+1);printf(" **** ");
gotoxy(x,y+2);printf(" ** ");
Sleep(300);
Borrar();
gotoxy(x,y) ;printf(" * ** *");
gotoxy(x,y+1);printf(" **** ");
gotoxy(x,y+2);printf(" * ** *");
Sleep(200);
Borrar();
gotoxy(x,y) ;printf(" **** ");
gotoxy(x,y+1);printf(" ** ");
gotoxy(x,y+2);printf(" **** ");
Sleep(300);
Borrar();
vidas--;
corazones = 3 ;
pintar_corazones();
Pintura();
}
}
class OBJETOS{
int x,y;
public:
OBJETOS(int _x, int _y):x(_x),y(_y){}
void pintar();
void mover();
};
void OBJETOS::pintar(){
gotoxy(x,y); printf("%c",223);
gotoxy(x+1,y); printf("%c",223);
gotoxy(x+2,y); printf("%c",223);
gotoxy(x+3,y); printf("%c",223);
Sleep(25);
}
void OBJETOS::mover(){
gotoxy(x,y); printf (" ");
gotoxy(x+1,y); printf(" ");
gotoxy(x+2,y); printf(" ");
gotoxy(x+3,y); printf(" ");
y++;
if(y > 22 ){
x = rand()%70+3;
y = 4;
}
pintar();
}
int main(){
OcultarCursor();
pintar_limites();
COCHE N (7,7,3,3);
N.Pintura();
N.pintar_corazones();
OBJETOS obj(10,4);
int x = 10,y = 10;
bool game_over = false;
while(!game_over){
obj.mover();
N.morir();
N.mover();
}
return 0;
}
Valora esta pregunta
0