-
Notifications
You must be signed in to change notification settings - Fork 0
/
editor.c
74 lines (66 loc) · 2.21 KB
/
editor.c
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
/* Thomas Stoeckert
COP 3223H - Final Project
Editor.c contains the main loop for the editor mode
*/
#include "editor.h"
#include "data.h"
#include "io.h"
#include "verbs.h"
#include <ctype.h>
#include <stdlib.h>
void editorLoop(void){
struct room * currentRoom;
struct world gamedata;
char choice;
// Prompt user for either a new or an old file
printf("Welcome to the CText Editor. Would you like to open an existing world or create a new one?\n(e/n): ");
scanf("%c", &choice);
choice = tolower(choice);
clearBuffer();
while(choice != 'e' && choice != 'n'){
printf("Invalid choice. Please try again.\n");
scanf("%c", &choice);
choice = tolower(choice);
clearBuffer();
}
if(choice == 'e'){
// User is opening an existing world. Behave much like a player.
FILE * ifp = openFileFromUserPrompt();
gamedata = loadWorldFromFile(ifp);
} else {
struct room basicRoom = initRoom(0);
gamedata = initWorld();
gamedata.worldRooms.roomData = rAppend(gamedata.worldRooms.roomData, basicRoom);
gamedata.worldRooms.numRooms++;
}
gamedata.playing = 1;
gamedata.mode = 'm';
system("cls");
while(gamedata.playing){
printf("\n----- Editor (mode: %c) ------\n", gamedata.mode);
currentRoom = getCurrentRoom(gamedata.worldRooms, gamedata.currentRoomId);
switch(gamedata.mode){
default:
printRoomVerbose((*currentRoom));
break;
case 'r':
printf("Currently in room ID %d\n", currentRoom->id);
printRoomsVerbose(gamedata.worldRooms);
break;
case 'i':
printf("Item Prototypes: \n");
printItemsVerbose(gamedata.itemPrototypes);
printf("Items in current room: \n");
printItemsVerbose(currentRoom->inventory);
break;
case 'd':
printPathsVerbose(currentRoom->paths);
break;
case 'c':
printCombosVerbose(gamedata.recipes);
break;
}
handleEditorVerb(&gamedata);
//gamedata.playing = 0;
}
}