Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #include <iostream>
- #include <string>
- #include <windows.h>
- #include <conio.h>
- #include <stdlib.h>
- using namespace std;
- using namespace System;
- #define Arriba 72
- #define Abajo 80
- #define Izquierda 75
- #define Derecha 77
- #define Esc 27
- short dir = 3;
- short x, y;
- short X, Y;
- char tecla;
- struct FROG {
- short x = 20;
- short y = 23;
- void guardar_posicion(short X, short Y) {
- X = x;
- Y = y;
- }
- void pintarFrog() {
- Console::SetCursorPosition(x, y); printf("%c", 254);
- }
- void borrarFrog(short x, short y) {
- Console::SetCursorPosition(x, y); printf(" ");
- }
- void mover(short dx, short dy) {
- x += dx;
- y += dy;
- Console::SetCursorPosition(dx, dy);
- }
- };
- struct TRONCO {
- float left;
- float right;
- float top;
- float bottom;
- void mostrarPosicion() {
- cout << char(35) << endl;
- }
- };
- void pintar() {
- for (int f = 1; f <= 25; f++) {
- for (short c = 1; c <= 50; c++) {
- if (((f == 1) || (f == 25)) && ((c != 1) && (c != 50)))
- cout << char(205);
- else if (((c == 1) || (c == 50)) && ((f != 1) && (f != 25)))
- cout << char(186);
- else if ((f == 1) && (c == 1))
- cout << char(201);
- else if ((f == 1) && (c == 50))
- cout << char(187);
- else if ((f == 25) && (c == 1))
- cout << char(200);
- else if ((f == 25) && (c == 50))
- cout << char(188);
- else
- cout << " ";
- }cout << endl;
- }
- }
- void teclear(FROG &frog) {
- if (_kbhit()) {
- tecla = _getch();
- switch (tecla) {
- case Arriba: frog.mover(0, -1); break;
- case Abajo: frog.mover(0, 1); break;
- case Derecha: frog.mover(1, 0); break;
- case Izquierda: frog.mover(-1, 0); break;
- }
- }
- }
- void OcultaCursor() {
- CONSOLE_CURSOR_INFO cci = { 100, FALSE };
- SetConsoleCursorInfo(GetStdHandle(STD_OUTPUT_HANDLE), &cci);
- }
- bool game_over(short x, short y) {
- if (x == 1 || x == 50 || y == 1 || y == 25) return FALSE;
- //if (x == carX && y == carY) return FALSE;
- return TRUE;
- }
- int main() {
- FROG frog;
- OcultaCursor();
- pintar();
- while (tecla != Esc && (game_over(frog.x, frog.y))) {
- frog.borrarFrog(frog.x, frog.y);
- frog.guardar_posicion(frog.x, frog.y);
- frog.borrarFrog(frog.x, frog.y);
- frog.pintarFrog();
- teclear(frog);
- _sleep(120);
- }
- system("pause>null");
- return 0;
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement