elhacker.net cabecera Bienvenido(a), Visitante. Por favor Ingresar o Registrarse
¿Perdiste tu email de activación?.

 

 


Tema destacado: Como proteger una cartera - billetera de Bitcoin


+  Foro de elhacker.net
|-+  Programación
| |-+  Programación C/C++ (Moderadores: Eternal Idol, Littlehorse, K-YreX)
| | |-+  Juego naves error código
0 Usuarios y 1 Visitante están viendo este tema.
Páginas: [1] Ir Abajo Respuesta Imprimir
Autor Tema: Juego naves error código  (Leído 3,542 veces)
Luffy97

Desconectado Desconectado

Mensajes: 15


Ver Perfil
Juego naves error código
« en: 14 Marzo 2016, 09:56 am »

Hola, tengo un problema el otro día estaba realizando un tutorial de como crear un juego en c++ y una vez terminado me funcionaba perfectamente (visual studio 2015), pero en ejecutarlo en dev c++ me daba otros errores... si me pudieran echar un vistazo en el código y ayudarme se lo agradecería.
Erro linea 256 y línea 270.
Aquí adjunto el código:
Código
  1. #include <stdio.h>
  2. #include <windows.h>
  3. #include <conio.h>
  4. #include <stdlib.h>
  5. #include <list>
  6. using namespace std;
  7. #define ARRIBA 72
  8. #define IZQUIERDA 75
  9. #define DERECHA 77
  10. #define ABAJO 80
  11.  
  12. void fflush_in() {
  13. int ch;
  14. while ((ch = fgetc(stdin)) != EOF && ch != '\n') {}
  15. }
  16.  
  17. void gotoxy(int x, int y) {
  18. //HANDLE es el nombre que recibe la consola, i l'he ponemos el nombre de que queramos
  19. //en este caso hCon que es el que se pone por defecto.
  20. HANDLE hCon;
  21. //Coje el identificador de la ventana (GetStdHandle)
  22. hCon = GetStdHandle(STD_OUTPUT_HANDLE);
  23. //Creamos las cordenadas.
  24. COORD dwPos;
  25. dwPos.X = x;
  26. dwPos.Y = y;
  27. SetConsoleCursorPosition(hCon, dwPos);
  28. }
  29. void ocultarCursor() {
  30. HANDLE hCon;
  31. hCon = GetStdHandle(STD_OUTPUT_HANDLE);
  32. CONSOLE_CURSOR_INFO cci;
  33. cci.dwSize = 2;
  34. cci.bVisible = FALSE;
  35. SetConsoleCursorInfo(hCon, &cci);
  36. }
  37. void pintarLimites() {
  38. for (int i = 2; i < 78; i++) {
  39. gotoxy(i, 3); printf("%c", 205);
  40. gotoxy(i, 33); printf("%c", 205);
  41. }
  42. for (int i = 4; i < 33; i++) {
  43. gotoxy(2, i); printf("%c", 186);
  44. gotoxy(77, i); printf("%c", 186);
  45. }
  46. gotoxy(2, 3); printf("%c", 201);
  47. gotoxy(2, 33); printf("%c", 200);
  48. gotoxy(77, 3); printf("%c", 187);
  49. gotoxy(77, 33); printf("%c", 188);
  50. }
  51.  
  52. class NAVE {
  53. int x, y;
  54. int corazones;
  55. int vidas;
  56. public:
  57. NAVE(int _x, int _y, int _corazones, int _vidas) : x(_x), y(_y), corazones(_corazones), vidas(_vidas) {}
  58. int X() { return x; }
  59. int Y() { return y; }
  60. int VID() { return vidas; }
  61. void pCorazon() { corazones--; }
  62. void gCorazon() { if (corazones < 3)corazones++; }
  63. void pintar();
  64. void borrar();
  65. void mover();
  66. void pintarCorazones();
  67. void morir();
  68. };
  69. class AST {
  70. int x, y;
  71. public:
  72. AST(int _x, int _y) : x(_x), y(_y) {}
  73. void pintar();
  74. void mover();
  75. void choque(class NAVE &N);
  76. void borrar();
  77. int X() { return x; }
  78. int Y() { return y; }
  79. };
  80. class VIDA {
  81. int x, y;
  82. public:
  83. VIDA(int _x, int _y) : x(_x), y(_y) {}
  84. void pintar();
  85. void mover();
  86. void choque(class NAVE &N);
  87. void borrar();
  88. };
  89. class BALA {
  90. int x, y;
  91. public:
  92. BALA(int _x, int _y) : x(_x), y(_y) {};
  93. int X() { return x; }
  94. int Y() { return y; }
  95. void mover();
  96. bool fuera();
  97. };
  98. /*
  99. ALTERNATIVA a : x(_x), y(_y) {}
  100. NAVE::NAVE(int _x, int _y) {
  101. x = _x;
  102. y = _y;
  103. }*/
  104. void NAVE::pintar() {
  105. gotoxy(x, y); printf(" %c", 30);
  106. gotoxy(x, y + 1); printf(" %c%c%c", 40, 207, 41);
  107. gotoxy(x, y + 2); printf("%c%c %c%c", 30, 190, 190, 30);
  108. system("color 7");
  109. }
  110.  
  111. void NAVE::borrar() {
  112. gotoxy(x, y); printf(" ");
  113. gotoxy(x, y + 1); printf(" ");
  114. gotoxy(x, y + 2); printf(" ");
  115. }
  116.  
  117. void NAVE::mover() {
  118.  
  119. if (kbhit()) {
  120. char tecla = getch();
  121. borrar();
  122. if (tecla == IZQUIERDA && x > 3) x--;
  123. if (tecla == DERECHA && x + 6 < 77) x++;
  124. if (tecla == ARRIBA && y > 4) y--;
  125. if (tecla == ABAJO && y + 3 < 33) y++;
  126. pintar();
  127. pintarCorazones();
  128. }
  129. }
  130. void NAVE::pintarCorazones() {
  131.  
  132. gotoxy(50, 2); printf("VIDAS %d", vidas);
  133. gotoxy(64, 2); printf("Salud");
  134. gotoxy(70, 2); printf(" ");
  135. for (int i = 0; i < corazones; i++) {
  136. gotoxy(70 + i, 2); printf("%c\r", 03);
  137. }
  138. }
  139. void NAVE::morir() {
  140. if (corazones == 0) {
  141. borrar();
  142. gotoxy(x, y); printf(" * ");
  143. gotoxy(x, y + 1); printf("** **");
  144. gotoxy(x, y + 2); printf(" * ");
  145. Sleep(200);
  146. borrar();
  147. gotoxy(x, y); printf("* * *");
  148. gotoxy(x, y + 1); printf(" * ");
  149. gotoxy(x, y + 2); printf("* * *");
  150. Sleep(200);
  151. borrar();
  152. vidas--;
  153. corazones = 3;
  154. pintarCorazones();
  155. pintar();
  156. }
  157.  
  158.  
  159.  
  160.  
  161. }
  162. void AST::pintar() {
  163. gotoxy(x, y); printf("%c", 'o');
  164. }
  165. void AST::mover() {
  166. gotoxy(x, y); printf(" ");
  167. y++;
  168. if (y > 32) {
  169. x = rand() % 71 + 4;
  170. y = 4;
  171. }
  172. pintar();
  173. }
  174. void AST::choque(class NAVE &N) {
  175. if (x >= N.X() && x < N.X() + 6 && y >= N.Y() && y <= N.Y() + 2) {
  176. N.pCorazon();
  177. borrar();
  178. N.pintar();
  179. N.pintarCorazones();
  180. x = rand() % 71 + 4;
  181. y = 4;
  182. }
  183. }
  184.  
  185. void AST::borrar() {
  186. gotoxy(x, y); printf(" ");
  187. }
  188.  
  189. void VIDA::pintar() {
  190. gotoxy(x, y); printf("%c", 3);
  191. }
  192. void VIDA::mover() {
  193. gotoxy(x, y); printf(" ");
  194. y++;
  195. if (y > 32) {
  196. x = rand() % 71 + 4;
  197. y = 4;
  198. }
  199. pintar();
  200. }
  201. void VIDA::choque(class NAVE &N) {
  202. if (x >= N.X() && x < N.X() + 6 && y >= N.Y() && y <= N.Y() + 2) {
  203. N.gCorazon();
  204. N.pintarCorazones();
  205. borrar();
  206. N.pintar();
  207. x = rand() % 71 + 4;
  208. y = 4;
  209. }
  210. }
  211. void VIDA::borrar() {
  212. gotoxy(x, y); printf(" ");
  213. }
  214. void BALA::mover() {
  215. gotoxy(x, y); printf(" ");
  216. y--;
  217. gotoxy(x, y); printf("*");
  218. }
  219. bool BALA::fuera() {
  220. if (y == 4) {
  221. return true;
  222. }
  223. else {
  224. return false;
  225. }
  226. }
  227. int main() {
  228. char tecla;
  229. do
  230. {
  231. ocultarCursor();
  232. pintarLimites();
  233. list<AST*> A;
  234. list<AST*>::iterator itA;
  235. for (int i = 0; i < 5; i++) {
  236. A.push_back(new AST(rand() % 75 + 3, rand() % 5 + 4));
  237. }
  238. NAVE N(15, 25, 3, 3);
  239. VIDA vit(15, 8);
  240. list<BALA*> B;
  241. list<BALA*>::iterator it;
  242. N.pintar();
  243. int puntos = 0;
  244. bool game_over = false;
  245. while (!game_over) {
  246. gotoxy(4, 2); printf("PUNTOS %d", puntos);
  247. if (kbhit()) {
  248. char tecla = getch();
  249. if (tecla == 'a') {
  250. B.push_back(new BALA(N.X() + 2, N.Y() - 1));
  251. }
  252. }
  253. for (it = B.begin(); it != B.end();) {
  254. (*it)->mover();
  255. if ((*it)->fuera()) {
  256. gotoxy((*it)>X(), (*it)>Y()); printf(" ");
  257. delete(*it);
  258. it = B.erase(it);
  259. }
  260. else { it++; }
  261. }
  262. N.mover();
  263. vit.mover(); vit.choque(N);
  264. for (itA = A.begin(); itA != A.end(); itA++) {
  265. (*itA)->mover();
  266. (*itA)->choque(N);
  267. }
  268. for (itA = A.begin(); itA != A.end(); itA++) {
  269. for (it = B.begin(); it != B.end();) {
  270. if ((*itA)>X() == (*it)>X() && ((*itA)>Y() + 1 == (*it)>Y() || (*itA)>Y() == (*it)>Y())) {
  271. gotoxy((*it)>X(), (*it)>Y()); printf(" ");
  272. delete (*it);
  273. it = B.erase(it);
  274. A.push_back(new AST(rand() % 74 + 3, 4));
  275. gotoxy((*itA)>X(), (*itA)>Y()); printf(" ");
  276. delete (*itA);
  277. itA = A.erase(itA);
  278. puntos = puntos + 5;
  279. }
  280. else { it++; }
  281.  
  282. }
  283. }
  284. if (N.VID() < 0)
  285. {
  286. game_over = true;
  287. }
  288. N.morir();
  289. Sleep(60);
  290. }
  291. gotoxy(4, 35); printf("\nGAME OVER\n");
  292. printf("JUGAR DE 9? [S/N]\n");
  293. do {
  294. scanf("%c", &tecla);
  295. fflush_in();
  296. tecla = towlower(tecla);
  297. if (tecla != 's' && tecla != 'n') {
  298. printf("Solo [S/N]");
  299. }
  300. } while (tecla != 's' && tecla != 'n');
  301. system("cls");
  302. } while (tecla != 'n');
  303. return 0;
  304. }&#65279;


« Última modificación: 14 Marzo 2016, 12:45 pm por engel lex » En línea

engel lex
Moderador Global
***
Desconectado Desconectado

Mensajes: 15.514



Ver Perfil
Re: Juego naves error código
« Respuesta #1 en: 14 Marzo 2016, 12:48 pm »

en informatica los errores son sumamente importantes, no son solo errores, lo que dice, importa, mucho... si dijeras lo que dice el error, no solo la linea, seria bueno... aunque podría decirte sospechar que el error es con conio.h.... es una librería privativa de MS y se desaconseja su uso


En línea

El problema con la sociedad actualmente radica en que todos creen que tienen el derecho de tener una opinión, y que esa opinión sea validada por todos, cuando lo correcto es que todos tengan derecho a una opinión, siempre y cuando esa opinión pueda ser ignorada, cuestionada, e incluso ser sujeta a burla, particularmente cuando no tiene sentido alguno.
ivancea96


Desconectado Desconectado

Mensajes: 3.412


ASMático


Ver Perfil WWW
Re: Juego naves error código
« Respuesta #2 en: 14 Marzo 2016, 15:11 pm »

Además, en la línea 270:
Código
  1. if ((*itA)>X() == (*it)>X()
Querrías decir (*it)->X(), no ">". Y así en todas las ocurrencias.
También en la línea 256.
En línea

Luffy97

Desconectado Desconectado

Mensajes: 15


Ver Perfil
Re: Juego naves error código
« Respuesta #3 en: 15 Marzo 2016, 10:18 am »

Si, el error es el que mencionas Ivan ;-).
Muchas Gracias por tu aprotacion, doy este tema por cerrado.
Gracias y un saludo . :silbar: :silbar: :silbar:
En línea

Páginas: [1] Ir Arriba Respuesta Imprimir 

Ir a:  

Mensajes similares
Asunto Iniciado por Respuestas Vistas Último mensaje
JUEGO NAVES MULTIJUGADOR
Juegos y Consolas
Zakt 1 2,468 Último mensaje 3 Diciembre 2006, 16:10 pm
por Division-x
Mi juego de naves en Java « 1 2 »
Java
Pakiyopgd 17 17,669 Último mensaje 26 Enero 2010, 22:52 pm
por Pakiyopgd
[Juego] Naves :D Estilo Galaga
Programación Visual Basic
79137913 9 10,581 Último mensaje 14 Diciembre 2010, 07:35 am
por BlackZeroX
Pequeño juego de naves:
Programación C/C++
Error 404: 2 8,270 Último mensaje 11 Diciembre 2014, 20:20 pm
por Error 404:
Juego de naves VBScript + HTA.
Scripting
John1Connor 2 2,850 Último mensaje 23 Junio 2015, 08:55 am
por тαптяα
WAP2 - Aviso Legal - Powered by SMF 1.1.21 | SMF © 2006-2008, Simple Machines