diff --git a/Makefile b/Makefile new file mode 100644 index 0000000..8aebf3c --- /dev/null +++ b/Makefile @@ -0,0 +1,10 @@ +GCC=/usr/bin/gcc +FLAGS= +TARGET=adv +OBJ=adv.o + +$(TARGET): $(OBJ) + $(GCC) $(FLAGS) $(OBJ) -o $(TARGET) + +$(OBJ): $(TARGET).c + $(GCC) $(FLAGS) -c $(TARGET).c diff --git a/adv.c b/adv.c new file mode 100644 index 0000000..fa4a2fc --- /dev/null +++ b/adv.c @@ -0,0 +1,177 @@ +#include +#include + +#define _DEBUGGING 0 + +#define _NORTH 8 +#define _EAST 4 +#define _SOUTH 2 +#define _WEST 1 + +#define _FORWARD 8 +#define _RIGHT 4 +#define _BACKWARD 2 +#define _LEFT 1 + +#define _NEWLINE 10 +#define _SPACEBAR 32 + +/* Ett äventyrligt test + + 27/8-2022 - initial program. Chopping up input + 9/10-2022 - actual program. Added parsing of input, move & help command, and idea of exits and directions +*/ + +char *roomName[16] = {"hallen", "ett vardagsrum", "Rum 2", "Rum 3", + "Rum 4", "Rum 5", "Rum 6", "Rum 7", + "Rum 8", "Rum 9", "Rum 10", "Rum 11", + "Rum 12", "Rum 13", "Rum 14", "Rum 15"}; +char *roomDesc[16] = { "Det ligger en ful matta på golvet. \nDet luktar ättika..", + "En TV står och brusar bredvid en bokhylla.\nTapeterna på väggen ramlar nästan av."}; +short int roomExits[16] = {15,15,15,15, /* Binär information om utgångar. 1111 (15) = alla riktningar, osv */ + 15,15,15,15, /* 1000 - north, 0100 - east, 0010 - south, 0001 - west */ + 15,15,15,15, + 15,15,15,15}; + +short int commandParts; +char command[5][16]; + +short int currentRoom; +short int looking; /* 0 - north, 1 - south, 2- west, 3 - east */ + +int main () { + startup(); + + while(1) { + enterRoom(); + prompt(); + parseCommand(); + } +} + +int startup () { + printf("***************************\n"); + printf("* E T T Ä V E N T Y R *\n"); + printf("***************************\n\n\n"); + + printf("Du står utanför ett hus och sparkar in dörren.\nDen går itu och du går in...\n\n"); + looking = _NORTH; /* Utgå från rum 13 och titta norrut */ + currentRoom = 13; + return 0; +} + +int enterRoom () { + printf("- - Du är i %s\n\n", roomName[currentRoom]); + printf("%s \n\n", roomDesc[currentRoom]); +} + +int prompt () { + char input[40]; // Stoppa allt i variabeln input + + printf("Vad vill du göra?\n"); + fgets(input,40,stdin); + printf("\n"); + + commandParts=0; + int i=0; + int ltr=0; // Position för bokstaven i ordet + + while (i