feat: created new project
This commit is contained in:
parent
859eb3b9d6
commit
e619d7e271
2
.gitignore
vendored
Normal file
2
.gitignore
vendored
Normal file
|
@ -0,0 +1,2 @@
|
|||
bin/
|
||||
build/
|
8
src/dice.c
Normal file
8
src/dice.c
Normal file
|
@ -0,0 +1,8 @@
|
|||
#include "dice.h"
|
||||
#include <stdlib.h>
|
||||
|
||||
int roll_die(struct roll_data data) {
|
||||
int min = data.count;
|
||||
int max = data.count * data.die - data.count;
|
||||
return min + (rand() % max);
|
||||
}
|
22
src/dice.h
Normal file
22
src/dice.h
Normal file
|
@ -0,0 +1,22 @@
|
|||
#ifndef DICE_H
|
||||
#define DICE_H
|
||||
|
||||
enum die {
|
||||
D4 = 4,
|
||||
D6 = 6,
|
||||
D8 = 8,
|
||||
D10 = 10,
|
||||
D12 = 12,
|
||||
D20 = 20,
|
||||
D100 = 100,
|
||||
COIN = 2,
|
||||
};
|
||||
|
||||
struct roll_data {
|
||||
int count;
|
||||
enum die die;
|
||||
};
|
||||
|
||||
int roll_die(struct roll_data data);
|
||||
|
||||
#endif // !DICE_H
|
6
src/interactive.c
Normal file
6
src/interactive.c
Normal file
|
@ -0,0 +1,6 @@
|
|||
#include "interactive.h"
|
||||
#include <stdio.h>
|
||||
|
||||
void interactive() {
|
||||
fprintf(stderr, "interactive mode not implemented\n");
|
||||
}
|
6
src/interactive.h
Normal file
6
src/interactive.h
Normal file
|
@ -0,0 +1,6 @@
|
|||
#ifndef DICE_INTERACTIVE_H
|
||||
#define DICE_INTERACTIVE_H
|
||||
|
||||
void interactive();
|
||||
|
||||
#endif // !DICE_INTERACTIVE_H
|
23
src/main.c
Normal file
23
src/main.c
Normal file
|
@ -0,0 +1,23 @@
|
|||
#include "dice.h"
|
||||
#include "interactive.h"
|
||||
#include "output.h"
|
||||
#include "parse.h"
|
||||
#include <stdbool.h>
|
||||
#include <stdlib.h>
|
||||
#include <time.h>
|
||||
|
||||
int main(int argc, char *argv[]) {
|
||||
srand(time(NULL));
|
||||
int mod;
|
||||
struct roll_data roll_data = { 1, D4 };
|
||||
if (argc == 1) {
|
||||
interactive();
|
||||
return 0;
|
||||
} else if (parse(argv[argc-1], &roll_data, &mod)) {
|
||||
print_roll(roll_data, mod, roll_die(roll_data));
|
||||
return 0;
|
||||
} else {
|
||||
print_help();
|
||||
return 0;
|
||||
}
|
||||
}
|
27
src/output.c
Normal file
27
src/output.c
Normal file
|
@ -0,0 +1,27 @@
|
|||
#include "output.h"
|
||||
#include <stdio.h>
|
||||
#include <stdlib.h>
|
||||
|
||||
static void print_mod(int mod) {
|
||||
if (mod > 0) {
|
||||
printf("+%d", abs(mod));
|
||||
} else if (mod < 0) {
|
||||
printf("%d", abs(mod));
|
||||
}
|
||||
}
|
||||
|
||||
void print_roll(struct roll_data data, int mod, int roll) {
|
||||
printf("rolled: %dd%d", data.count, data.die);
|
||||
print_mod(mod);
|
||||
printf(" (%d", roll);
|
||||
print_mod(mod);
|
||||
printf(")");
|
||||
}
|
||||
|
||||
void print_error(char const *error) {
|
||||
fprintf(stderr, "format incorrect: %s\n", error);
|
||||
}
|
||||
|
||||
void print_help() {
|
||||
fprintf(stderr, "help not implemented\n");
|
||||
}
|
10
src/output.h
Normal file
10
src/output.h
Normal file
|
@ -0,0 +1,10 @@
|
|||
#ifndef DICE_OUTPUT_H
|
||||
#define DICE_OUTPUT_H
|
||||
|
||||
#include "dice.h"
|
||||
|
||||
extern void print_roll(struct roll_data data, int mod, int roll);
|
||||
extern void print_format_error(char const *error);
|
||||
extern void print_help();
|
||||
|
||||
#endif // !DICE_OUTPUT_H
|
8
src/parse.c
Normal file
8
src/parse.c
Normal file
|
@ -0,0 +1,8 @@
|
|||
#include "parse.h"
|
||||
#include <stdbool.h>
|
||||
#include <stdio.h>
|
||||
|
||||
bool parse(char *die_arg, struct roll_data* o_data, int *o_mod) {
|
||||
fprintf(stderr, "parse not implemented\n");
|
||||
return false;
|
||||
}
|
10
src/parse.h
Normal file
10
src/parse.h
Normal file
|
@ -0,0 +1,10 @@
|
|||
#ifndef DICE_PARSE_H
|
||||
#define DICE_PARSE_H
|
||||
|
||||
#include <stdbool.h>
|
||||
struct roll_data;
|
||||
|
||||
extern bool parse(char *die_arg, struct roll_data* o_data, int *o_mod);
|
||||
|
||||
#endif // !DICE_PARSE_H
|
||||
|
Loading…
Reference in a new issue