Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #include<stdio.h>
- #include<windows.h>
- #include<conio.h>
- #include<time.h>
- #include<stdlib.h>
- #include<iostream>
- #define ARRIBA 72
- #define IZQUIERDA 75
- #define DERECHA 77
- #define ABAJO 80
- #define FILAS 29 //29
- #define COLUMNAS 74 //74
- using namespace std;
- int tablero[FILAS][COLUMNAS]={0};
- int i=0,j=0,posy=4;
- int x=3,y=4,puntox,puntoy;
- void gotoxy(int x, int y);
- void pintar_limites();
- void Movimiento();
- void OcultarCursor();
- void pintar_tablero();
- int main () {
- system ("MODE 100,40");
- srand(time(0));
- pintar_limites();
- pintar_tablero();
- Movimiento();
- }
- void pintar_tablero(){
- for(i=0;i<FILAS;i++){
- gotoxy(3,posy);
- posy++;
- for(j=0;j<COLUMNAS;j++){
- tablero[i][j]=rand()%19;
- switch(tablero[i][j]){
- case 0:cout<<"V";break; //Vidas
- case 1:cout<<"M";break;//Enemigos
- case 2:cout<<"X";break;//Puntos
- case 3:
- case 4:
- case 5:
- case 6:
- case 7:
- case 8:
- case 9:
- case 10:
- case 11:
- case 12:
- case 13:cout<<" ";break;
- case 14:
- case 15:
- case 16:
- case 17:
- case 18:cout<<char(178);break;//Bloques
- }
- }
- cout<<endl;
- }
- }
- void pintar_limites(){
- for(int i=2;i<78;i++){
- gotoxy(i,3);printf("%c",205);
- gotoxy(i,33);printf("%c",205);
- }
- for (int i=4;i<33;i++){
- gotoxy(2,i);printf("%c",186);
- gotoxy(77,i);printf("%c",186);
- }
- gotoxy(2,3);printf("%c",201);
- gotoxy(2,33);printf("%c",200);
- gotoxy(77,3);printf("%c",187);
- gotoxy(77,33);printf("%c",188);
- }
- void Movimiento(){
- OcultarCursor();
- bool game_over=false;
- while(!game_over){
- gotoxy(x,y);
- printf("%c",250);
- if(kbhit()){
- char tecla=getch();
- gotoxy(x,y);
- printf(" ");
- //Teclas asignadas de movimiento y limitantes del laberinto
- if (tecla == IZQUIERDA && x>3) x--;
- if (tecla == DERECHA && x<76) x++;
- if (tecla == ARRIBA && y>4 ) y--;
- if (tecla == ABAJO && y<32) y++;
- }
- gotoxy(0,0);
- cout<<"X: "<<x<<"Y: "<<y<<"Valor: "<<tablero[i][j];//La parte de tablero i,j la intenté poner como tablero[x][y], pero me daba unos valores muy altos que no correspondían a lo que necesito saber.
- }
- }
- void OcultarCursor(){
- HANDLE hCon;
- hCon=GetStdHandle(STD_OUTPUT_HANDLE);
- CONSOLE_CURSOR_INFO cci;
- cci.dwSize=100;
- cci.bVisible=FALSE;
- SetConsoleCursorInfo(hCon,&cci);
- }
- void gotoxy(int x, int y)
- {
- HANDLE hCon;
- COORD dwPos;
- dwPos.X = x;
- dwPos.Y = y;
- hCon = GetStdHandle(STD_OUTPUT_HANDLE);
- SetConsoleCursorPosition(hCon,dwPos);
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement