Advertisement
Guest User

Untitled

a guest
Jun 19th, 2019
125
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 2.56 KB | None | 0 0
  1. #include<stdio.h>
  2. #include<windows.h>
  3. #include<conio.h>
  4. #include<time.h>
  5. #include<stdlib.h>
  6. #include<iostream>
  7. #define ARRIBA 72
  8. #define IZQUIERDA 75
  9. #define DERECHA 77
  10. #define ABAJO 80
  11. #define FILAS 29 //29
  12. #define COLUMNAS 74 //74
  13. using namespace std;
  14.  
  15. int tablero[FILAS][COLUMNAS]={0};
  16. int i=0,j=0,posy=4;
  17. int x=3,y=4,puntox,puntoy;
  18. void gotoxy(int x, int y);
  19. void pintar_limites();
  20. void Movimiento();
  21. void OcultarCursor();
  22. void pintar_tablero();
  23.  
  24. int main () {
  25. system ("MODE 100,40");
  26. srand(time(0));
  27. pintar_limites();
  28. pintar_tablero();
  29. Movimiento();
  30. }
  31.  
  32.  
  33. void pintar_tablero(){
  34. for(i=0;i<FILAS;i++){
  35. gotoxy(3,posy);
  36. posy++;
  37. for(j=0;j<COLUMNAS;j++){
  38. tablero[i][j]=rand()%19;
  39. switch(tablero[i][j]){
  40. case 0:cout<<"V";break; //Vidas
  41. case 1:cout<<"M";break;//Enemigos
  42. case 2:cout<<"X";break;//Puntos
  43. case 3:
  44. case 4:
  45. case 5:
  46. case 6:
  47. case 7:
  48. case 8:
  49. case 9:
  50. case 10:
  51. case 11:
  52. case 12:
  53. case 13:cout<<" ";break;
  54. case 14:
  55. case 15:
  56. case 16:
  57. case 17:
  58. case 18:cout<<char(178);break;//Bloques
  59. }
  60. }
  61. cout<<endl;
  62. }
  63. }
  64.  
  65. void pintar_limites(){
  66. for(int i=2;i<78;i++){
  67. gotoxy(i,3);printf("%c",205);
  68. gotoxy(i,33);printf("%c",205);
  69. }
  70.  
  71. for (int i=4;i<33;i++){
  72. gotoxy(2,i);printf("%c",186);
  73. gotoxy(77,i);printf("%c",186);
  74. }
  75.  
  76. gotoxy(2,3);printf("%c",201);
  77. gotoxy(2,33);printf("%c",200);
  78. gotoxy(77,3);printf("%c",187);
  79. gotoxy(77,33);printf("%c",188);
  80. }
  81.  
  82. void Movimiento(){
  83. OcultarCursor();
  84.  
  85. bool game_over=false;
  86. while(!game_over){
  87. gotoxy(x,y);
  88. printf("%c",250);
  89. if(kbhit()){
  90. char tecla=getch();
  91. gotoxy(x,y);
  92. printf(" ");
  93. //Teclas asignadas de movimiento y limitantes del laberinto
  94. if (tecla == IZQUIERDA && x>3) x--;
  95. if (tecla == DERECHA && x<76) x++;
  96. if (tecla == ARRIBA && y>4 ) y--;
  97. if (tecla == ABAJO && y<32) y++;
  98. }
  99. gotoxy(0,0);
  100. 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.
  101. }
  102. }
  103.  
  104. void OcultarCursor(){
  105. HANDLE hCon;
  106. hCon=GetStdHandle(STD_OUTPUT_HANDLE);
  107. CONSOLE_CURSOR_INFO cci;
  108. cci.dwSize=100;
  109. cci.bVisible=FALSE;
  110. SetConsoleCursorInfo(hCon,&cci);
  111. }
  112.  
  113. void gotoxy(int x, int y)
  114. {
  115. HANDLE hCon;
  116. COORD dwPos;
  117.  
  118. dwPos.X = x;
  119. dwPos.Y = y;
  120. hCon = GetStdHandle(STD_OUTPUT_HANDLE);
  121. SetConsoleCursorPosition(hCon,dwPos);
  122. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement