Advertisement
Guest User

Untitled

a guest
Oct 22nd, 2019
113
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.01 KB | None | 0 0
  1. #include <iostream>
  2. #include <ctype.h>
  3. #include <conio.h>
  4. #include <time.h>
  5. using namespace std;
  6. using namespace System;
  7. #define ARRIBA 72
  8. #define ABAJO 80
  9. #define IZQUIERDA 75
  10. #define DERECHA 77
  11. typedef struct personaje {
  12. int x=40;
  13. int y=80;
  14. int pasos=0;
  15.  
  16. void animar(char direccion) {
  17. borrar();
  18. mover(direccion);
  19. dibujar();
  20. };
  21. void borrar() {
  22. Console::SetCursorPosition(x, y);
  23. cout << " ";
  24. };
  25. void mover(char direccion) {
  26. switch (direccion){
  27. case ARRIBA: y--;pasos++; break;
  28. case ABAJO: y++;pasos++; break;
  29. case IZQUIERDA: x--;pasos++; break;
  30. case DERECHA: x++;pasos++; break;
  31. }
  32. };
  33. void dibujar() {
  34. Console::SetCursorPosition(x, y);
  35. cout << " | ";
  36. };
  37. };
  38. void jugar() {
  39. personaje p;
  40. bool continuar = true;
  41. while (continuar) {
  42. if (kbhit()) {
  43. char direccion = getch();
  44. p.animar(direccion);
  45. }
  46. if (p.x==80) {
  47. p.x--;
  48. }
  49. if (p.x == 2) {
  50. p.x++;
  51. }
  52. }
  53. }
  54. int main() {
  55. Console::CursorVisible=false;
  56. jugar();
  57. return 0;
  58. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement