Advertisement
Guest User

Untitled

a guest
Mar 31st, 2015
219
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 0.91 KB | None | 0 0
  1. #include <stdio.h>
  2. #include <stdlib.h>
  3. #include "fogefoge.h"
  4. #include "mapa.h"
  5.  
  6. MAPA m;
  7. POSICAO heroi;
  8.  
  9.  
  10. int acabou() {
  11. return 0;
  12. }
  13.  
  14. int ehDirecao(char direcao) {
  15. return
  16. direcao == 'a' ||
  17. direcao == 'w' ||
  18. direcao == 's' ||
  19. direcao == 'd';
  20. }
  21.  
  22. void move(char direcao) {
  23.  
  24. if(!ehDirecao(direcao))
  25. return;
  26.  
  27. int proximox = heroi.x;
  28. int proximoy = heroi.y;
  29.  
  30. switch(direcao) {
  31. case 'a':
  32. proximoy--;
  33. break;
  34. case 'w':
  35. proximox--;
  36. break;
  37. case 's':
  38. proximox++;
  39. break;
  40. case 'd':
  41. proximoy++;
  42. break;
  43. }
  44.  
  45. if(!ehValida(&m, proximox, proximoy))
  46. return;
  47.  
  48. if(!ehVazia(&m, proximox, proximoy))
  49. return;
  50.  
  51. andanomapa(&m, heroi.x, heroi.y, proximox, proximoy);
  52. heroi.x = proximox;
  53. heroi.y = proximoy;
  54. }
  55.  
  56. int main() {
  57.  
  58. lemapa(&m);
  59. encontramapa(&m, &heroi, '@');
  60.  
  61. do {
  62. imprimemapa(&m);
  63.  
  64. char comando;
  65. scanf(" %c", &comando);
  66.  
  67. move(comando);
  68.  
  69. } while (!acabou());
  70.  
  71. liberamapa(&m);
  72. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement