Browse Source

Tidied up the comments

master
tinfoilcat 3 years ago
parent
commit
60ed831485
  1. 25
      adv.c

25
adv.c

@ -16,10 +16,8 @@
#define _NEWLINE 10 #define _NEWLINE 10
#define _SPACEBAR 32 #define _SPACEBAR 32
/* Ett äventyrligt test /*
adv - text based adventure. See changelog for details and ideas for future work
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", char *roomName[16] = {"hallen", "ett vardagsrum", "Rum 2", "Rum 3",
@ -28,7 +26,7 @@ char *roomName[16] = {"hallen", "ett vardagsrum", "Rum 2", "Rum 3",
"Rum 12", "Rum 13", "Rum 14", "Rum 15"}; "Rum 12", "Rum 13", "Rum 14", "Rum 15"};
char *roomDesc[16] = { "Det ligger en ful matta på golvet. \nDet luktar ättika..", 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."}; "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 */ short int roomExits[16] = {15,15,15,15, /* Binary information about available exits */
15,15,15,15, /* 1000 - north, 0100 - east, 0010 - south, 0001 - west */ 15,15,15,15, /* 1000 - north, 0100 - east, 0010 - south, 0001 - west */
15,15,15,15, 15,15,15,15,
15,15,15,15}; 15,15,15,15};
@ -37,7 +35,7 @@ short int commandParts;
char command[5][16]; char command[5][16];
short int currentRoom; short int currentRoom;
short int looking; /* 0 - north, 1 - south, 2- west, 3 - east */ short int looking; /* Will hold direction in the same format as directions */
int main () { int main () {
startup(); startup();
@ -66,7 +64,7 @@ int enterRoom () {
} }
int prompt () { int prompt () {
char input[40]; // Stoppa allt i variabeln input char input[40]; /* Hold user input */
printf("Vad vill du göra?\n"); printf("Vad vill du göra?\n");
fgets(input,40,stdin); fgets(input,40,stdin);
@ -74,23 +72,23 @@ int prompt () {
commandParts=0; commandParts=0;
int i=0; int i=0;
int ltr=0; // Position för bokstaven i ordet int ltr=0; /* Position marker for the word being processed */
while (i<sizeof(input)) { while (i<sizeof(input)) {
switch (input[i]) { switch (input[i]) {
case _NEWLINE: // Ta bort \n, terminera nuvarande variabel med NULL, avsluta insamling av ord case _NEWLINE: /* Remove \n, terminate word with null, stop collecting words */
command[commandParts][ltr] = 0; command[commandParts][ltr] = 0;
i=sizeof(input); i=sizeof(input);
break; break;
case _SPACEBAR: // Upptäck mellanslag, terminera nuvarande variabel med NULL, påbörja nytt ord case _SPACEBAR: /* Find spaces, terminate word with null, move on to next word */
command[commandParts][ltr] = 0; command[commandParts][ltr] = 0;
commandParts++; commandParts++;
ltr=0; ltr=0;
break; break;
default: // Lägg bokstaven till befintligt ord default: /* Append letter to current word */
command[commandParts][ltr] = input[i]; command[commandParts][ltr] = input[i];
ltr++; ltr++;
break; break;
@ -165,12 +163,13 @@ int commandMove () {
return 0; return 0;
} }
/* I framtiden ska denna funktion kika på roomExits utifrån önskad riktning */ /* Future use - use this function to check roomExits according to direction of looking */
int canigo(int direction) { /* 0 - forward, 1 - backward, 2 - left, 3 - right */ int canigo(int direction) { /* 0 - forward, 1 - backward, 2 - left, 3 - right */
/* Got en bitwise jämförelse av önskad riktning och roomExit här. Glöm inte att omvandla riktning till ett passande tal (1,2,4,8) */ /* Do a bitwise comparison of rotaded movement and roomExits */
return 1; return 1;
} }
/* hjälp command */
int help() { int help() {
printf("- - ! Tillgängliga kommandon: \ngå (framåt / bakåt / vänster / höger) \n\n- - ! SLUT PÅ HJÄLP\n"); printf("- - ! Tillgängliga kommandon: \ngå (framåt / bakåt / vänster / höger) \n\n- - ! SLUT PÅ HJÄLP\n");
return 0; return 0;

Loading…
Cancel
Save