#include<iostream> #include<stdio.h> #include<windows.h> #include<conio.h> #include<stdlib.h> using namespace std; char caracter = 'x'; int x = 40; // Posición inicial en x int y = 12; // Posición inicial en y int tamañox = 0; int tamañoy = 0; int opcion = 0; int puntos; int posx = 0; int posy = 0; int jugar = 0; char temporal; int puntajemaximo = 0; #pragma warning(disable : 4996) #define ARRIBA 72 #define IZQUIERDA 75 #define DERECHA 77 #define ABAJO 80 #define ESC 27 char tecla; int dir = 3; int velocidad; int xinicio = 10, yinicio = 10; void gotoxy(int x1, int y1) //en las funciones simpre ponemos void //las funciones las podemos llamar en cualquier parte //del programa { HANDLE hcon; hcon = GetStdHandle(STD_OUTPUT_HANDLE); COORD dwPos; dwPos.X = x1; dwPos.Y = y1; SetConsoleCursorPosition(hcon, dwPos); } void pantalla() { cout << " xxxx\n"; cout << " x xx\n"; cout << " x xxxxxx\n"; cout << " x xxxxxxx\n"; cout << " xx xxxxxxxx\n"; cout << " x x xxxxxxxx\n"; cout << "x x xxxxxx\n"; cout << "x x x\n"; cout << "x x x\n"; cout << "x x x\n"; cout << "x x x\n"; cout << "x x xx x\n"; cout << "x x x x x\n"; cout << "x x x x x\n"; cout << " x x x x x\n"; cout << " xx x x x\n"; cout << " xx xx\n"; } void nombre() { cout << " x x \n"; cout << " x x x \n"; cout << " x x x \n"; cout << " x x x x x xx xxx xxx \n"; cout << " x x Xxxxxx xxxxx x x x x \n"; cout << " xxxxx x x x x xx x x \n"; cout << " x x X x x x x xxx xxx \n"; cout << " x x X x x x x x x \n"; cout << " x x x x x x x x x \n"; cout << " x x x x xxxxx x xxx xxx \n"; } void delay(int secs) { for (int i = (time(NULL) + secs); time(NULL) != i; time(NULL)); } void salir() { cout << " xxxxxx \n"; cout << " x x x \n"; cout << " x x x x x \n"; cout << " x x xx x x xxxx x x x xxx \n"; cout << " x x x x x x x x x x \n"; cout << " x xx xx xxxxxxx x x xxxxxxx xxx \n"; cout << " x x x x x x x x x x \n"; cout << " x x x x x x x x xxxx x x x xxx \n"; cout << " \n"; cout << " \n"; } void cuerpo() { for (int a = 0; a <= 60; a++) { gotoxy(a + xinicio, yinicio); cout << "_"; } for (int a = 0; a <= 20; a++) { gotoxy(xinicio, a + yinicio); cout << "|"; } for (int a = 0; a <= 60; a++) { gotoxy(a + xinicio, 30); cout << "_"; } for (int a = 0; a <= 20; a++) { gotoxy(70, a + yinicio); cout << "|"; } } void teclear() { if (kbhit()) { tecla = getch(); switch (tecla) { case ARRIBA: if (dir != 2) dir = 1; break; case ABAJO: if (dir != 1) dir = 2; break; case DERECHA: if (dir != 4) dir = 3; break; case IZQUIERDA: if (dir != 3) dir = 4; break; } } } void punteo() { if ((x == posx) && (y == posy)) { puntos++; posx = 50 + rand() % 150; posy = 50 + rand() % 150; } gotoxy(posx, posy); cout << "0"; gotoxy(10, 10); cout << "0"; gotoxy(posx, posy); cout << "punteo:" << puntos; } int main() { inicio: system("color 09"); pantalla(); delay(5); system("cls"); nombre(); delay(5); system("cls"); system("cls"); cout << "1.jugar\n"; cout << "2.puntajemaximo\n"; cout << "3.salir\n"; cin >> opcion; switch (opcion) { case 1: menujuego: system("cls"); // Oculta el cursor CONSOLE_CURSOR_INFO cursorInfo; cursorInfo.dwSize = 100; cursorInfo.bVisible = FALSE; SetConsoleCursorInfo(GetStdHandle(STD_OUTPUT_HANDLE), &cursorInfo); while (true) { // Dibuja el carácter en la posición actual gotoxy(x, y); std::cout << caracter << std::flush; // Lee la tecla presionada // Borra el carácter actual gotoxy(x, y); std::cout << " " << std::flush; if (kbhit()) { char tecla = getch(); if (tecla == 'a')temporal = 'a'; if (tecla == 'd')temporal = 'd'; if (tecla == 's')temporal = 's'; if (tecla == 'w')temporal = 'w'; } // Mueve el carácter según la tecla presionada /* switch (tecla) { case 'w': temporal = 'w'; //y--; break; case 's': temporal='s'; //y++; break; case 'a': temporal='a'; //x--; break; case 'd': temporal='d'; //x++; break; default: break; }*/ if (temporal == 'a') { x--; gotoxy(x, y); cout << "x"; delay(1); Sleep(velocidad); system("cls"); } if (temporal == 'd') { x++; gotoxy(x, y); cout << "x"; delay(1); Sleep(velocidad); system("cls"); } if (temporal == 'w') { y--; gotoxy(x, y); cout << "x"; Sleep(velocidad); delay(1); system("cls"); } if (temporal == 's') { y++; gotoxy(x, y); cout << "x"; delay(1); Sleep(velocidad); system("cls"); } // Ajusta las coordenadas si se exceden los límites de la consola /*if (x < 0) x = 0; if (x >= 80) x = 79; if (y < 0) y = 0; if (y >= 25) y = 24;*/ } break; case 2: menupuntagemaximo: goto inicio; case 3: salir(); } }
typings for: def add(a, b): return a + b ``` def add(a: int, b: int) -> int: return a + b ``` typings for: #include<iostream> #include<stdio.h> #include<windows.h> #include<conio.h> #include<stdlib.h> using namespace std; char caracter = 'x'; int x = 40; // Posición inicial en x int y = 12; // Posición inicial en y int tamañox = 0; int tamañoy = 0; int opcion = 0; int puntos; int posx = 0; int posy = 0; int jugar = 0; char temporal; int puntajemaximo = 0; #pragma warning(disable : 4996) #define ARRIBA 72 #define IZQUIERDA 75 #define DERECHA 77 #define ABAJO 80 #define ESC 27 char tecla; int dir = 3; int velocidad; int xinicio = 10, yinicio = 10; void gotoxy(int x1, int y1) //en las funciones simpre ponemos void //las funciones las podemos llamar en cualquier parte //del programa { HANDLE hcon; hcon = GetStdHandle(STD_OUTPUT_HANDLE); COORD dwPos; dwPos.X = x1; dwPos.Y = y1; SetConsoleCursorPosition(hcon, dwPos); } void pantalla() { cout << " xxxx\n"; cout << " x xx\n"; cout << " x xxxxxx\n"; cout << " x xxxxxxx\n"; cout << " xx xxxxxxxx\n"; cout << " x x xxxxxxxx\n"; cout << "x x xxxxxx\n"; cout << "x x x\n"; cout << "x x x\n"; cout << "x x x\n"; cout << "x x x\n"; cout << "x x xx x\n"; cout << "x x x x x\n"; cout << "x x x x x\n"; cout << " x x x x x\n"; cout << " xx x x x\n"; cout << " xx xx\n"; } void nombre() { cout << " x x \n"; cout << " x x x \n"; cout << " x x x \n"; cout << " x x x x x xx xxx xxx \n"; cout << " x x Xxxxxx xxxxx x x x x \n"; cout << " xxxxx x x x x xx x x \n"; cout << " x x X x x x x xxx xxx \n"; cout << " x x X x x x x x x \n"; cout << " x x x x x x x x x \n"; cout << " x x x x xxxxx x xxx xxx \n"; } void delay(int secs) { for (int i = (time(NULL) + secs); time(NULL) != i; time(NULL)); } void salir() { cout << " xxxxxx \n"; cout << " x x x \n"; cout << " x x x x x \n"; cout << " x x xx x x xxxx x x x xxx \n"; cout << " x x x x x x x x x x \n"; cout << " x xx xx xxxxxxx x x xxxxxxx xxx \n"; cout << " x x x x x x x x x x \n"; cout << " x x x x x x x x xxxx x x x xxx \n"; cout << " \n"; cout << " \n"; } void cuerpo() { for (int a = 0; a <= 60; a++) { gotoxy(a + xinicio, yinicio); cout << "_"; } for (int a = 0; a <= 20; a++) { gotoxy(xinicio, a + yinicio); cout << "|"; } for (int a = 0; a <= 60; a++) { gotoxy(a + xinicio, 30); cout << "_"; } for (int a = 0; a <= 20; a++) { gotoxy(70, a + yinicio); cout << "|"; } } void teclear() { if (kbhit()) { tecla = getch(); switch (tecla) { case ARRIBA: if (dir != 2) dir = 1; break; case ABAJO: if (dir != 1) dir = 2; break; case DERECHA: if (dir != 4) dir = 3; break; case IZQUIERDA: if (dir != 3) dir = 4; break; } } } void punteo() { if ((x == posx) && (y == posy)) { puntos++; posx = 50 + rand() % 150; posy = 50 + rand() % 150; } gotoxy(posx, posy); cout << "0"; gotoxy(10, 10); cout << "0"; gotoxy(posx, posy); cout << "punteo:" << puntos; } int main() { inicio: system("color 09"); pantalla(); delay(5); system("cls"); nombre(); delay(5); system("cls"); system("cls"); cout << "1.jugar\n"; cout << "2.puntajemaximo\n"; cout << "3.salir\n"; cin >> opcion; switch (opcion) { case 1: menujuego: system("cls"); // Oculta el cursor CONSOLE_CURSOR_INFO cursorInfo; cursorInfo.dwSize = 100; cursorInfo.bVisible = FALSE; SetConsoleCursorInfo(GetStdHandle(STD_OUTPUT_HANDLE), &cursorInfo); while (true) { // Dibuja el carácter en la posición actual gotoxy(x, y); std::cout << caracter << std::flush; // Lee la tecla presionada // Borra el carácter actual gotoxy(x, y); std::cout << " " << std::flush; if (kbhit()) { char tecla = getch(); if (tecla == 'a')temporal = 'a'; if (tecla == 'd')temporal = 'd'; if (tecla == 's')temporal = 's'; if (tecla == 'w')temporal = 'w'; } // Mueve el carácter según la tecla presionada /* switch (tecla) { case 'w': temporal = 'w'; //y--; break; case 's': temporal='s'; //y++; break; case 'a': temporal='a'; //x--; break; case 'd': temporal='d'; //x++; break; default: break; }*/ if (temporal == 'a') { x--; gotoxy(x, y); cout << "x"; delay(1); Sleep(velocidad); system("cls"); } if (temporal == 'd') { x++; gotoxy(x, y); cout << "x"; delay(1); Sleep(velocidad); system("cls"); } if (temporal == 'w') { y--; gotoxy(x, y); cout << "x"; Sleep(velocidad); delay(1); system("cls"); } if (temporal == 's') { y++; gotoxy(x, y); cout << "x"; delay(1); Sleep(velocidad); system("cls"); } // Ajusta las coordenadas si se exceden los límites de la consola /*if (x < 0) x = 0; if (x >= 80) x = 79; if (y < 0) y = 0; if (y >= 25) y = 24;*/ } break; case 2: menupuntagemaximo: goto inicio; case 3: salir(); } } ```