Hello, I'm a real noob in C programming, started about 2 months ago. I'm posting in this section because I'm not sure if my problem is advanced/specific enough to be in the game section.
So, I have this school project where I have to recreate a modified version of the game "Hunt the Wumpus". In this version here what has to happen.
- There will be 3 abysses, 1 Wumpus and 1 treasure. If you fall on a abyss location or enter the wumpus location, you die.
- Score : You have one arrow, using it to kill the wumpus. It's used by throwing the arrow in the adjacent place. You get the treasure by going in its location.
Kill Wumpus : +10k points.
Get treasure : +1k points.
Die : -1k points.
Escape the cave : +1k points. (Return to location [0][0]
Walk one step : -1 point.
-Senses:
If the player is one house away from an abyss or wumpus, he will feel a strong breeze or stench ( B, C). Two houses or diagonal = medium ( Bb, Cc ). Three houses = week ( b, c ).
So getting to my problems. I'm kinda lost on how to initialize the players, creating a function for the senses and throwing the arrow.
A friend told me to take a look at a Mine field in c program and use it as a base. So this is basically what I've done until now.
Code:#include <stdio.h> #include <stdlib.h> #include <string.h> #define MAX 1000 typedef struct WumpusWorld{ int array[12][12]; //Stores the interface int arrayB[12][12]; //Stores the world int wumpus; //Stores the monster int arrow; //Stores arrow int gold; //Stores treasure int abyss; //Stores number of abyss int steps; //Stores number of steps }World; //--------------------------------------------------------------------------------------------- //Function to retrieve players choice. Used to start and exit game. //--------------------------------------------------------------------------------------------- int choice(){ int option; do{ fflush(stdin); scanf("%d", &option); if(option < 1 || option > 3) { printf("Option not valid. Try again."); } } while(option < 1 || option > 3); return option; } // End of choice function //--------------------------------------------------------------------------------------------- //Fuction for initial menu //--------------------------------------------------------------------------------------------- int menu1(){ int option = 0; printf("------------------------------------\n"); printf("|\t\t\t\t\t\|\n"); printf("|\tWelcome to the World of Wumpus!\t|\n"); printf("|\t 1-Play 2-Exit \t|\n"); printf("------------------------------------\n\n"); option = choice(); return option; } //Function end //--------------------------------------------------------------------------------------------- //Functions trasforms int to char //--------------------------------------------------------------------------------------------- int intchar ( int i){ switch (i){ case 0: return '0'; case 1: return '1'; case 2: return '2'; case 3: return '3'; case 4: return '4'; case 5: return '5'; case 6: return '6'; case 7: return '7'; case 8: return '8'; case 9: return '9'; } } //--------------------------------------------------------------------------------------------- //Function to print array //--------------------------------------------------------------------------------------------- void Prints(int cont){ int i,j,lin,col; printf("\t 1 2 3 4 5 6 7 8 9 10\n") for(i = 0; i < 10;i++){ printf("%d", i); printf("\t"); for(j = 0; j < 10;j++){ printf("[%c]", World[cont].array[i][j]); printf("\n"); } printf("\n[ ]Empty\t [x]Current Position\t [?]Unexplored\t 99 - Exit\n\n"); } }// end of print function //--------------------------------------------------------------------------------------------- //Function to generate random abyss positions //--------------------------------------------------------------------------------------------- void abyssraffle(int c){ int lin,col,arm; int qnt = 0; srand(time(NULL)); do{ do{ lin=rand()%9+1; col=rand()%9+1; if(World[c].arrayB[lin][col]==9){ arm = -1; }else{ World[c].arrayB[lin][col]=9; arm = 0; } }while(arm==-1); qnt++; }while(qnt<World[c].abyss); } //--------------------------------------------------------------------------------------------- //Function to generate wumpus in random position //--------------------------------------------------------------------------------------------- void abysswumpus(int w){ int lin,col,wum; int qnt = 0; srand(time(NULL)); do{ do{ lin=rand()%9+1; col=rand()%9+1; if(World[w].arrayB[lin][col]==9){ wum = -1; }else{ World[w].arrayB[lin][col]=9; wum = 0; } }while(wum==-1); qnt++; }while(qnt<World[w].wumpus); } //--------------------------------------------------------------------------------------------- //Fucnction to start array empty //--------------------------------------------------------------------------------------------- void start(int cont){ int i,j; //Starts world with -1 to indicate empty for(i = 0;i < 12;i++) for(j = 0;j < 12;j++) World[cont].arrayB[i][j]=-1; for(i = 0;i < 12;i++) //Starts interface for(j = 0;j < 12;j++) World[cont].array[i][j]='?'; } //--------------------------------------------------------------------------------------------- //Fucnction to move player ( Doubts starting here ) //--------------------------------------------------------------------------------------------- char move(){ char input; while (input != 27) { input = getch(); switch (input) { case 119: World.array[][]=array[a][b-1]='x'; World.arrayB[][]=array[a][b-1]=//?; break; case 115: World.array[][]=array[a][b+1]='x'; World.arrayB[][]=array[a][b+1]=//?; break; case 97: World.array[][]=array[a-1][b]='x'; World.arrayB[][]=array[a-1][b]=//?; break; case 100: World.array[][]=array[a+1][b]='x'; World.arrayB[][]=array[a+1][b]=//?; break; } }