Commit 3abb741d authored by Chris's avatar Chris
Browse files

all functionality up to this point is demo functionality

parent f4214265
Loading
Loading
Loading
Loading
+9 −0
Original line number Diff line number Diff line
@@ -2,6 +2,7 @@

#include "utils.h"

#include <stdlib.h>
#include <time.h> // timespec struct

// get random value from device
@@ -16,3 +17,11 @@ void sleep_ms(const unsigned int ms) {
    ts.tv_nsec = (ms % 1000) * 1000000;
    nanosleep(&ts, NULL);
}

void clear_screen() {
    #ifdef _WIN32
        system("cls");
    #else
        system("clear");
    #endif
}
+1 −0
Original line number Diff line number Diff line
@@ -8,5 +8,6 @@

FILE *get_urandom();
void sleep_ms(unsigned int ms);
void clear_screen();

#endif //UTILS_H
+22 −14
Original line number Diff line number Diff line
@@ -7,36 +7,44 @@
// Chris Morris
// MIT License

int main() {
void do_demo_dice_rolls(game_context *ctx, unsigned int *next_roll); // this is specifically to show 2 demo rolls, with one hold

int main(void) {
	game_context ctx;
	// initialize random device for game state
	ctx.random_device_fd = get_urandom();
	int next_roll[NUM_DICE];

	clear_screen();

	printf("yaht.c\n");

	// un-hold all dice
	clear_held_values(&ctx);

	// do_demo_dice_rolls(&ctx, next_roll); // if you want to see a little demo

	fclose(ctx.random_device_fd);
	return 0;
}

void do_demo_dice_rolls(game_context *ctx, unsigned int *next_roll) {
	// first roll
	roll_and_print(&ctx, next_roll, 0);
	roll_and_print(ctx, next_roll, 0);

	sleep_ms(1000);

	// set some dice held (debug)
	set_die_held(&ctx, 0, 1);
	set_die_held(&ctx, 1, 1);
	set_die_held(&ctx, 4, 1);
	set_die_held(ctx, 0, 1);
	set_die_held(ctx, 1, 1);
	set_die_held(ctx, 4, 1);
	// set_die_held(&ctx, 5, 1); // tests edge case

	roll_and_print(&ctx, next_roll, 0);
	roll_and_print(ctx, next_roll, 0);

	// sanity check that we're actually saving to game state in the roll_and_print()
	// for (int i = 0; i < NUM_DICE; i++) {
	// 	printf("%d ", ctx.game_state.dice[i].value);
	// }
	// printf("\n");

	fclose(ctx.random_device_fd);
	return 0;
	for (int i = 0; i < NUM_DICE; i++) {
		printf("%d ", ctx->game_state.dice[i].value);
	}
	printf("\n");
}