#include <stdio.h>#include <Windows.h>#include <conio.h>#define ARRIBA 72#define IZQUIERDA 75#define DERECHA 77#define ABAJO 80//funcion de ocultacion del cursorvoid ocultar_cursor(){ HANDLE hCon; hCon = GetStdHandle(STD_OUTPUT_HANDLE); CONSOLE_CURSOR_INFO cursor; cursor.dwSize = 2; cursor.bVisible = FALSE; SetConsoleCursorInfo(hCon,&cursor);}//funcion de posicionvoid gotoxy (int x, int y){ HANDLE hCon; hCon = GetStdHandle(STD_OUTPUT_HANDLE); COORD posicion; posicion.X = x; posicion.Y = y; SetConsoleCursorPosition (hCon, posicion);}int main(){ ocultar_cursor(); nave objeto; objeto.nave_parametros(7,7); objeto.pintar(); bool game_over = false; while(!game_over){ objeto.mover(); Sleep(30); } return 0;}//inicio de la clase y relacionadosclass nave{ int x, y;public: void nave_parametros(int _x, int _y); void pintar(); void borrar(); void mover ();};void nave::nave_parametros(int _x, int _y){ x = _x; y = _y;}void nave::pintar(){ gotoxy(x,y); printf(" %c",30); gotoxy(x,y+1); printf(" %c%c%c",40,207,41); gotoxy(x,y+2); printf("%c%c %c%c",30,190,190,30);}void nave::borrar(){ gotoxy(x,y); printf(" "); gotoxy(x,y+1); printf(" "); gotoxy(x,y+2); printf(" ");}void nave::mover(){ if (kbhit()){ char tecla = getch(); borrar(); if (tecla == IZQUIERDA) x--; if (tecla == DERECHA) x++; if (tecla == ARRIBA) y--; if (tecla == ABAJO) y++; pintar(); }}//final de la clase y relacionados
#include <stdio.h>#include <Windows.h>#include <conio.h>#define ARRIBA 72#define IZQUIERDA 75#define DERECHA 77#define ABAJO 80//funcion de ocultacion del cursorvoid ocultar_cursor(){ HANDLE hCon; hCon = GetStdHandle(STD_OUTPUT_HANDLE); CONSOLE_CURSOR_INFO cursor; cursor.dwSize = 2; cursor.bVisible = FALSE; SetConsoleCursorInfo(hCon,&cursor);}//funcion de posicionvoid gotoxy (int x, int y){ HANDLE hCon; hCon = GetStdHandle(STD_OUTPUT_HANDLE); COORD posicion; posicion.X = x; posicion.Y = y; SetConsoleCursorPosition (hCon, posicion);}class nave{ int x, y;public: void nave_parametros(int _x, int _y); void pintar(); void borrar(); void mover ();};int main(){ ocultar_cursor(); nave objeto; objeto.nave_parametros(7,7); objeto.pintar(); bool game_over = false; while(!game_over){ objeto.mover(); Sleep(30); } return 0;}//inicio de la clase y relacionadosvoid nave::nave_parametros(int _x, int _y){ x = _x; y = _y;}void nave::pintar(){ gotoxy(x,y); printf(" %c",30); gotoxy(x,y+1); printf(" %c%c%c",40,207,41); gotoxy(x,y+2); printf("%c%c %c%c",30,190,190,30);}void nave::borrar(){ gotoxy(x,y); printf(" "); gotoxy(x,y+1); printf(" "); gotoxy(x,y+2); printf(" ");}void nave::mover(){ if (kbhit()){ char tecla = getch(); borrar(); if (tecla == IZQUIERDA) x--; if (tecla == DERECHA) x++; if (tecla == ARRIBA) y--; if (tecla == ABAJO) y++; pintar(); }}