Commit fcda9916 authored by Chris's avatar Chris
Browse files

fixed ODR for graphics code

parent bbd5d088
Loading
Loading
Loading
Loading
+32 −33
Original line number Diff line number Diff line
// graphics.c
#include "graphics.h"

// void print_single_die(int die_value) {
// 	// override invalid values with a blank die (DICE[0])
// 	if (die_value < 0 || die_value > DICE_ARRAY_LENGTH) {
// 		die_value = 0;
// 	}
// 
// 	for (int i = 0; i < DIE_VERTICAL_LENGTH; i++) {
// 		printf("%s\n", DICE[die_value][i]);
// 	}
// }
// 
// void print_multiple_dice(int *die_values, int n, int animated) {
// 	// if animation is not desired, just print out the die values
// 	for (int which_row = 0; which_row < DIE_VERTICAL_LENGTH; which_row++) {
// 		for (int j = 0; j < n; j++) {
// 			int which_die = die_values[j];
// 			printf("%s  ", DICE[which_die][which_row]);
// 		}
// 		printf("\n");
// 	}
// }
// 
// // to only be called after print_multiple_dice()
// void clear_dice() {
// 	// move cursor up
// 	// for (int i = 0; i < DIE_VERTICAL_LENGTH + 1; i++) {
// 	for (int i = 0; i < DIE_VERTICAL_LENGTH; i++) {
// 		printf("\033[A"); // move cursor up one line
// 	}
// 	// move cursor all the way to the left
// 	printf("\r");
// 	// printf("Hello world!\n");
// }
void print_single_die(int die_value) {
	// override invalid values with a blank die (DICE[0])
	if (die_value < 0 || die_value > DICE_ARRAY_LENGTH) {
		die_value = 0;
	}

	for (int i = 0; i < DIE_VERTICAL_LENGTH; i++) {
		printf("%s\n", DICE[die_value][i]);
	}
}

void print_multiple_dice(int *die_value, int n, int animated) {
	for (int which_row = 0; which_row < DIE_VERTICAL_LENGTH; which_row++) {
		for (int j = 0; j < n; j++) {
			int which_die = die_value[j];
			printf("%s  ", DICE[which_die][which_row]);
		}
		printf("\n");
	}
}

// to only be called after print_multiple_dice()
void clear_dice() {
	// move cursor up
	// for (int i = 0; i < DIE_VERTICAL_LENGTH + 1; i++) {
	for (int i = 0; i < DIE_VERTICAL_LENGTH; i++) {
		printf("\033[A"); // move cursor up one line
	}
	// move cursor all the way to the left
	printf("\r");
}
+34 −36
Original line number Diff line number Diff line
@@ -7,10 +7,10 @@
#include <stdio.h>
#include <stdarg.h>

const int DIE_VERTICAL_LENGTH = 6;
const int DICE_ARRAY_LENGTH = 7;
static const int DIE_VERTICAL_LENGTH = 6;
static const int DICE_ARRAY_LENGTH = 7;

char *DICE[7][6] = {
static const char *DICE[7][6] = {
	{	
		" +-------+ ",
		" |       | ",
@@ -75,38 +75,36 @@ void print_single_die(int die_value);
void print_multiple_dice(int *die_value, int n, int animated);
void clear_dice();

// todo move the below to its own source file

void print_single_die(int die_value) {
	// override invalid values with a blank die (DICE[0])
	if (die_value < 0 || die_value > DICE_ARRAY_LENGTH) {
		die_value = 0;
	}

	for (int i = 0; i < DIE_VERTICAL_LENGTH; i++) {
		printf("%s\n", DICE[die_value][i]);
	}
}

void print_multiple_dice(int *die_value, int n, int animated) {
	for (int which_row = 0; which_row < DIE_VERTICAL_LENGTH; which_row++) {
		for (int j = 0; j < n; j++) {
			int which_die = die_value[j];
			printf("%s  ", DICE[which_die][which_row]);
		}
		printf("\n");
	}
}

// to only be called after print_multiple_dice()
void clear_dice() {
	// move cursor up
	// for (int i = 0; i < DIE_VERTICAL_LENGTH + 1; i++) {
	for (int i = 0; i < DIE_VERTICAL_LENGTH; i++) {
		printf("\033[A"); // move cursor up one line
	}
	// move cursor all the way to the left
	printf("\r");
}
// void print_single_die(int die_value) {
// 	// override invalid values with a blank die (DICE[0])
// 	if (die_value < 0 || die_value > DICE_ARRAY_LENGTH) {
// 		die_value = 0;
// 	}
// 
// 	for (int i = 0; i < DIE_VERTICAL_LENGTH; i++) {
// 		printf("%s\n", DICE[die_value][i]);
// 	}
// }
// 
// void print_multiple_dice(int *die_value, int n, int animated) {
// 	for (int which_row = 0; which_row < DIE_VERTICAL_LENGTH; which_row++) {
// 		for (int j = 0; j < n; j++) {
// 			int which_die = die_value[j];
// 			printf("%s  ", DICE[which_die][which_row]);
// 		}
// 		printf("\n");
// 	}
// }
// 
// // to only be called after print_multiple_dice()
// void clear_dice() {
// 	// move cursor up
// 	// for (int i = 0; i < DIE_VERTICAL_LENGTH + 1; i++) {
// 	for (int i = 0; i < DIE_VERTICAL_LENGTH; i++) {
// 		printf("\033[A"); // move cursor up one line
// 	}
// 	// move cursor all the way to the left
// 	printf("\r");
// }

#endif //GRAPHICS_H_
+464 B (17.1 KiB)

File changed.

No diff preview for this file type.