Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #include <stdio.h>
- #include <stdlib.h>
- #include "fogefoge.h"
- #include "mapa.h"
- MAPA m;
- POSICAO heroi;
- int acabou() {
- return 0;
- }
- int ehDirecao(char direcao) {
- return
- direcao == 'a' ||
- direcao == 'w' ||
- direcao == 's' ||
- direcao == 'd';
- }
- void move(char direcao) {
- if(!ehDirecao(direcao))
- return;
- int proximox = heroi.x;
- int proximoy = heroi.y;
- switch(direcao) {
- case 'a':
- proximoy--;
- break;
- case 'w':
- proximox--;
- break;
- case 's':
- proximox++;
- break;
- case 'd':
- proximoy++;
- break;
- }
- if(!ehValida(&m, proximox, proximoy))
- return;
- if(!ehVazia(&m, proximox, proximoy))
- return;
- andanomapa(&m, heroi.x, heroi.y, proximox, proximoy);
- heroi.x = proximox;
- heroi.y = proximoy;
- }
- int main() {
- lemapa(&m);
- encontramapa(&m, &heroi, '@');
- do {
- imprimemapa(&m);
- char comando;
- scanf(" %c", &comando);
- move(comando);
- } while (!acabou());
- liberamapa(&m);
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement