Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #include <stdio.h>
- #include <stdlib.h>
- #include <string.h>
- int luzfound = 0, score = 0; // a luz nao foi encontrada ainda, vai ser mudado para 1 quando for.
- struct celula {
- int tipo;
- int cheiroFraco;
- int cheiroMedio;
- int cheiroForte;
- int brisaFraca;
- int brisaMedia;
- int brisaForte;
- };
- 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.
- steps--;
- //acrescentar funcao para andar aqui utilizando dir, acrescentar if para paredes
- if (dir == 'w'){
- l--;
- }
- if (dir == 'w'){
- l++;
- }
- if (dir == 'a'){
- c--;
- }
- if (dir == 's'){
- c++;
- }
- if(l < 0){
- printf("Movimento invalido!");
- l++;
- }
- if(c < 0){
- printf("Movimento invalido!");
- c++;
- }
- if(l > )
- if (l == 0 && c == 0 && luzfound == 1){
- printf("Voce saiu do mundo de Wumpus a salvo!");
- score += 1000;
- steps = 1000
- }
- if (M[i][j].tipo == 1){
- printf("Voce encontrou um abismo!");
- score -= 1000;
- steps = 0;
- l = c = 0; //volta para o inicio
- }
- if (M[i][j].tipo == 2){
- printf("Voce encontrou um monstro!");
- score -=10000;
- step = 0;
- l = c = 0; //volta para o inicio
- }
- if (M[i][j].tipo == 3){
- printf("Parabens, voce encontrou a luz");
- score += 1000;
- luzfound = 1;
- }
- if(steps != 0){
- scanf("%d")
- walk(dir,l,c,steps);
- }
- }
- int readString(char *s) {
- char ch, first = 1;
- for (;;) {
- ch = getchar();
- if (ch == '\n') return 1; //final de linha
- if (ch == ' ') {
- if (first) {
- getchar();
- return 1; //final de linha
- }
- *s = 0;
- return 0; //final da palavra
- }
- first = 0;
- *s++ = ch;
- }
- }
- int main() {
- int l,c;
- scanf("%d %d%*c", &l, &c);
- struct celula M[l][c];
- int steps = l*c;
- for (int i=0; i<l; ++i) { //leitura da matriz ja colocando as sensacoes
- for (int j=0; j<c; ++j) {
- memset(M[i]+j, 0, sizeof(struct celula)); //equivalente memset(&M[i][j], 0, sizeof(celula));
- for (;;) {
- char s[1000];
- if (readString(s)) break;
- if (!strcmp(s, "b")) {
- M[i][j].brisaFraca += 1;
- } else if (!strcmp(s, "bB")) {
- M[i][j].brisaMedia += 1;
- } else if (!strcmp(s, "B")) {
- M[i][j].brisaForte += 1;
- }
- if (!strcmp(s, "c")) {
- M[i][j].cheiroFraco += 1;
- } else if (!strcmp(s, "cC")) {
- M[i][j].cheiroMedio += 1;
- } else if (!strcmp(s, "C")) {
- M[i][j].cheiroForte += 1;
- }
- if (!strcmp(s, "A")) {
- M[i][j].tipo += 1; // existe abismo no local
- } else if (!strcmp(s, "M")) {
- M[i][j].tipo += 2; //existe o monstro no local
- } else if (!strcmp(s, "L")) {
- M[i][j].tipo += 3; //existe luz/ouro no local
- }
- }
- 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);
- }
- }
- char dir;
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement