Advertisement
Es7evam

ICC1,T1

Apr 18th, 2016
73
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C++ 3.59 KB | None | 0 0
  1. #include <stdio.h>
  2. #include <stdlib.h>
  3. #include <string.h>
  4.  
  5. int luzfound = 0, score = 0; // a luz nao foi encontrada ainda, vai ser mudado para 1 quando for.
  6. struct celula {
  7.     int tipo;
  8.     int cheiroFraco;
  9.     int cheiroMedio;
  10.     int cheiroForte;
  11.     int brisaFraca;
  12.     int brisaMedia;
  13.     int brisaForte;
  14. };
  15. int walk(char dir, int l, int c, int steps){ //passa a direcao para andar (w,a,s,d) , a posicao l (linhas) e c (colunas) e o numero de passos.
  16.     steps--;
  17.     //acrescentar funcao para andar aqui utilizando dir, acrescentar if para paredes
  18.     if (dir == 'w'){
  19.         l--;
  20.     }
  21.     if (dir == 'w'){
  22.         l++;
  23.     }
  24.     if (dir == 'a'){
  25.         c--;
  26.     }
  27.     if (dir == 's'){
  28.         c++;
  29.     }
  30.     if(l < 0){
  31.         printf("Movimento invalido!");
  32.         l++;
  33.     }
  34.     if(c < 0){
  35.         printf("Movimento invalido!");
  36.         c++;
  37.     }
  38.     if(l > )
  39.    
  40.    
  41.     if (l == 0 && c == 0 && luzfound == 1){
  42.         printf("Voce saiu do mundo de Wumpus a salvo!");
  43.         score += 1000;
  44.         steps = 1000
  45.     }
  46.     if (M[i][j].tipo == 1){
  47.         printf("Voce encontrou um abismo!");
  48.         score -= 1000;
  49.         steps = 0;
  50.         l = c = 0; //volta para o inicio
  51.     }
  52.     if (M[i][j].tipo == 2){
  53.         printf("Voce encontrou um monstro!");
  54.         score -=10000;
  55.         step = 0;
  56.         l = c = 0; //volta para o inicio
  57.     }
  58.     if (M[i][j].tipo == 3){
  59.         printf("Parabens, voce encontrou a luz");
  60.         score += 1000;
  61.         luzfound = 1;
  62.     }
  63.     if(steps != 0){
  64.         scanf("%d")
  65.         walk(dir,l,c,steps);
  66.     }
  67. }
  68.  
  69. int readString(char *s) {
  70.     char ch, first = 1;
  71.     for (;;) {
  72.         ch = getchar();
  73.         if (ch == '\n') return 1; //final de linha
  74.         if (ch == ' ') {
  75.             if (first) {
  76.                 getchar();
  77.                 return 1; //final de linha
  78.             }
  79.             *s = 0;
  80.             return 0; //final da palavra
  81.         }
  82.         first = 0;
  83.         *s++ = ch;
  84.     }
  85. }
  86.  
  87. int main() {
  88.     int l,c;
  89.     scanf("%d %d%*c", &l, &c);
  90.     struct celula M[l][c];
  91.     int steps = l*c;
  92.     for (int i=0; i<l; ++i) { //leitura da matriz ja colocando as sensacoes
  93.         for (int j=0; j<c; ++j) {
  94.             memset(M[i]+j, 0, sizeof(struct celula)); //equivalente memset(&M[i][j], 0, sizeof(celula));
  95.  
  96.             for (;;) {
  97.                 char s[1000];
  98.                 if (readString(s)) break;
  99.  
  100.                 if (!strcmp(s, "b")) {
  101.                     M[i][j].brisaFraca += 1;
  102.                 } else if (!strcmp(s, "bB")) {
  103.                     M[i][j].brisaMedia += 1;
  104.                 } else if (!strcmp(s, "B")) {
  105.                     M[i][j].brisaForte += 1;
  106.                 }
  107.  
  108.                 if (!strcmp(s, "c")) {
  109.                     M[i][j].cheiroFraco += 1;
  110.                 } else if (!strcmp(s, "cC")) {
  111.                     M[i][j].cheiroMedio += 1;
  112.                 } else if (!strcmp(s, "C")) {
  113.                     M[i][j].cheiroForte += 1;
  114.                 }
  115.  
  116.                 if (!strcmp(s, "A")) {
  117.                     M[i][j].tipo += 1; // existe abismo no local
  118.                 } else if (!strcmp(s, "M")) {
  119.                     M[i][j].tipo += 2; //existe o monstro no local
  120.                 } else if (!strcmp(s, "L")) {
  121.                     M[i][j].tipo += 3; //existe luz/ouro no local
  122.                 }
  123.             }
  124.  
  125.             printf("[%d %d %d %d %d %d %d]\n", M[i][j].tipo, M[i][j].brisaFraca, M[i][j].brisaMedia, M[i][j].brisaForte, M[i][j].cheiroFraco, M[i][j].cheiroMedio, M[i][j].cheiroForte);
  126.         }
  127.     }
  128.     char dir;
  129.    
  130. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement