add inventory
This commit is contained in:
parent
7279afeb4c
commit
88e49d7ec8
9 changed files with 79 additions and 17 deletions
36
src/main.c
36
src/main.c
|
@ -1,9 +1,9 @@
|
|||
#include "command.h"
|
||||
#include "loader.h"
|
||||
#include <stdint.h>
|
||||
#include <stdio.h>
|
||||
#include <stdlib.h>
|
||||
#include <string.h>
|
||||
#include "command.h"
|
||||
#include "loader.h"
|
||||
|
||||
#define MAX_BUF_LENGTH 1024
|
||||
#define MAX_COMBO_LENGTH 1024
|
||||
|
@ -16,23 +16,45 @@ int main(int argc, char *argv[]) {
|
|||
char *command_re = calloc(MAX_BUF_LENGTH, sizeof(char));
|
||||
char **sort_tmp = calloc(MAX_COMBO_LENGTH, sizeof(char **));
|
||||
|
||||
load_elements(elements, "combos.txt");
|
||||
load_elements(elements, "bin/combos.txt", 0);
|
||||
load_elements(inv, "bin/inv.txt", 1);
|
||||
|
||||
printf("Welcome to Elemental on Command Line!\n");
|
||||
while (1) {
|
||||
// todo: separate into functions
|
||||
|
||||
command_re = get_command(command, command_re, sort_tmp);
|
||||
printf("\n");
|
||||
fgets(command, MAX_BUF_LENGTH - 1, stdin);
|
||||
int slashRan = slash_command(command,inv);
|
||||
if (slashRan) continue;
|
||||
|
||||
int combos = get_command(command, command_re, sort_tmp);
|
||||
|
||||
int failed = 0;
|
||||
for (int i = 0; i < combos; i++) {
|
||||
uintptr_t result;
|
||||
hashmap_get(inv, sort_tmp[i], strlen(sort_tmp[i]) - 1, &result);
|
||||
if (result != 1) {
|
||||
printf("You don't have %s.\n", sort_tmp[i]);
|
||||
failed = 1;
|
||||
continue;
|
||||
}
|
||||
}
|
||||
|
||||
if (failed) continue;
|
||||
|
||||
uintptr_t result;
|
||||
hashmap_get(elements, command_re, strlen(command_re), &result);
|
||||
|
||||
printf("%s\n",command_re);
|
||||
|
||||
if (result == 0) {
|
||||
printf("You didn't make anything.\n");
|
||||
continue;
|
||||
}
|
||||
printf("You made %s!\n", (char *)result);
|
||||
|
||||
char *res_str = (char *)result;
|
||||
|
||||
hashmap_set(inv, res_str, strlen(res_str) - 1, (uintptr_t)1);
|
||||
printf("You made %s!\n", res_str);
|
||||
}
|
||||
|
||||
// free(command);
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue