-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathmain.c
145 lines (129 loc) · 6.28 KB
/
main.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
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
#include <stdio.h>
#include <stdlib.h>
#include "src/ADT/mesinkarakter/mesinkarakter.h"
#include "src/ADT/mesinkata/mesinkata.h"
#include "src/ADT/array/array.h"
#include "src/ADT/stack/stack.h"
#include "src/ADT/queue/queue.h"
#include "src/functions.h"
#include "src/commands.h"
int main() {
// KAMUS LOKAL
Word command1, command2; // INPUT USER BERUPA COMMAND
int inputint; // INPUT USER BERUPA INTEGER
TabWord games; // Array untuk menyimpan game yang tersedia
Queue antrian_game; // Queue untuk menyimpan antrian game ketika BNMO berjalan
Map scoreboards[101]; // List of map untuk menyimpan scoreboard setiap game
Stack history; // Penyimpan riwayat permainan yang dimainkan
boolean loop= true;
int i, len;
// ALGORITMA
// Mengosongkan Array untuk games dan Queue untuk antrian game
clearScreen();
printf("______ __ _____ ________ ______ ___________ _______________ ___ _____ ________ \n");
printf("\\ \\__ /\\__ / __ / ____ / __ / __ / ____ __ / \\ / __ \\ ____ \n");
printf(" \\ \\ / \\__/ __ / /___ / __ / ______ / / / __ / \\/ __ \\ \\___ \n");
printf(" \\ \\/ \\/ __ / ____ / __ / /_____ / / / __ / /\\ /\\ __ \\ ____ \n");
printf(" \\ /\\ __ / /___ / ____ / __ / /___/ __ / / \\ / \\ __ \\ \\___ \n");
printf(" \\___/__\\____ /_______ /________ /_________ /_____________ /___/ \\/ \\_____ \\_______ \n");
printf(" BNMO | KELOMPOK 7 \n ");
printf("\n");
printf("(START) Start a new game | (LOAD \"namafile\") Load your previous data | (HELP) Help | (QUIT) Quit\n");
MakeEmpty(&games);
CreateQueue(&antrian_game);
MakeEmptyMapList (scoreboards, 101);
CreateEmptyStack(&history);
while (loop) {
printf("\n---- ENTER COMMAND : ");
scan("%c %c", &command1, &command2, &inputint);
if (ValidateCommand(command1, "START")) { // INPUT ADALAH START
C_START(command1,&games);
splashScreen();
printf("File konfigurasi sistem berhasil dibaca. BNMO berhasil dijalankan.\n");
loop = false;
// DisplayArray(games);
}
else if (ValidateCommand(command1, "LOAD")) { // INPUT ADALAH LOAD
LOAD(command2, &games, &history, scoreboards);
if (games.Neff == 0) printf("Save file tidak ditemukan, silahkan masukkan nama file yang benar.\n");
else {
splashScreen();
printf("Save file berhasil dibaca. BNMO berhasil dijalankan.\n");
loop = false;
}
}
else if(ValidateCommand(command1,"HELP")){ // INPUT ADALAH HELP
help();
}
else if(ValidateCommand(command1,"QUIT")){ // INPUT ADALAH QUIT
loop = false;
}
else{ // INPUT GAJELAS
printf("Command tidak dikenali, silahkan masukkan command yang valid.\n");
}
}
loop = true;
if (!ValidateCommand(command1,"QUIT")){
while(loop){
printf("\n===== ENTER COMMAND : ");
scan("%c %c %d", &command1, &command2, &inputint);
if(ValidateCommand(command1,"HELP")){ // INPUT ADALAH HELP
splashScreen();
help();
}
else if(ValidateCommand(command1,"CREATE") && ValidateCommand(command2,"GAME")) { // INPUT ADALAH CREATE GAME
splashScreen();
CREATEGAME(&games);
}
else if(ValidateCommand(command1,"LIST") && ValidateCommand(command2,"GAME")) { // INPUT ADALAH LIST GAME
splashScreen();
list_game(games);
}
else if(ValidateCommand(command1,"DELETE") && ValidateCommand(command2,"GAME")) { // INPUT ADALAH DELETE GAME
splashScreen();
DELETEGAME(&games,antrian_game,&history,scoreboards);
}
else if(ValidateCommand(command1,"QUEUE") && ValidateCommand(command2,"GAME")) { // INPUT ADALAH QUEUE GAME
splashScreen();
QUEUEGAME(games,&antrian_game);
}
else if(ValidateCommand(command1,"PLAY") && ValidateCommand(command2,"GAME")) { // INPUT ADALAH PLAY GAME
splashScreen();
PLAYGAME(games,&antrian_game,&history,scoreboards);
}
else if(ValidateCommand(command1,"SKIP") && ValidateCommand(command2,"GAME")) { // INPUT ADALAH SKIP GAME
splashScreen();
SKIPGAME(games,&antrian_game, inputint, &history, scoreboards);
}
else if(ValidateCommand(command1,"SAVE")) { // INPUT ADALAH SAVE
splashScreen();
SAVE(games, command2, history, scoreboards);
}
else if(ValidateCommand(command1,"SCOREBOARD")) {
splashScreen();
SCOREBOARD(scoreboards, games);
}
else if(ValidateCommand(command1,"RESET") && ValidateCommand(command2, "SCOREBOARD")) {
splashScreen();
RESETSCOREBOARD(scoreboards, games);
}
else if(ValidateCommand(command1,"HISTORY")) {
splashScreen();
HISTORY(games, &history, katatoint(command2));
}
else if(ValidateCommand(command1,"RESET") && ValidateCommand(command2, "HISTORY")) {
splashScreen();
RESETHISTORY(&history, games);
}
else if(ValidateCommand(command1,"QUIT")) { // INPUT ADALAH QUIT
loop = false;
}
else{ // IMPUT GAK JELAS
printf("Command tidak dikenali, silahkan masukkan command yang valid.\n");
}
}
}
// quit
printf("\n\nAnda keluar dari game BNMO.\nBye bye ...");
return 0;
}