commit 8bc8bf81adca11adbd8398d7680127cff05629c2 Author: PreacherDHM Date: Mon Jun 2 17:09:47 2025 -0700 first diff --git a/CMakeLists.txt b/CMakeLists.txt new file mode 100644 index 0000000..3ec27bf --- /dev/null +++ b/CMakeLists.txt @@ -0,0 +1,13 @@ +cmake_minimum_required(VERSION 3.30.0) + +project(DiceRoller VERSION 0.1) + +set(CMAKE_CXX_STANDARD 20) +set(CMAKE_CXX_STANDARD_REQUIRED ON) + +set(CMAKE_COLOR_MAKEFILE ON) +set(CMAKE_COLOR_DIAGNOSTICS ON) +set(CMAKE_EXPORT_COMPILE_COMMANDS ON) + +add_subdirectory(source) +add_subdirectory(external) diff --git a/README.md b/README.md new file mode 100644 index 0000000..e69de29 diff --git a/source/CMakeLists.txt b/source/CMakeLists.txt new file mode 100644 index 0000000..dd26ef6 --- /dev/null +++ b/source/CMakeLists.txt @@ -0,0 +1,6 @@ +# ADD SOURCES HERE +set(SOURCE_FILES + main.c +) + +add_executable(roll ${SOURCE_FILES}) diff --git a/source/main.c b/source/main.c new file mode 100644 index 0000000..2d65e2b --- /dev/null +++ b/source/main.c @@ -0,0 +1,62 @@ +/* ############################################################################# + * # DiceRoller + * This Program will alow you to role a dice or die using the scmatics such + * as 1d6, 5d20, 1d100, d20 + * + * AUTHER: PreacherDHM + * DATE: 06/02/25 + * ############################################################################# + */ + + +#include +#include +#include +#include + +/* GetDice(char* format) + * + * This will return the value of the rolled dice. + */ +int GetDice(const char* format) { + int size = strlen(format); + int seperator = 0; + int resolt = 0; + unsigned int seed = time(0); + char c_amount[30] = { '\0' }; + char c_dice[30] = { '\0' }; + + for(int i = 0; i < size; i++) { + if(format[i] != 'd') + continue; + seperator = i; + break; + } + if(seperator == 0) + return -1; + + strncpy(c_amount, format,seperator); + strcpy(c_dice, &format[seperator + 1]); + + int amount = atoi(c_amount); + int dice = atoi(c_dice); + int r = 0; + for (int i = 0; i < amount; i++) { + r = rand_r(&seed) % (dice - 1 + 1) + 1; + resolt += r; + } + + return resolt; +} + +int main (int argc, char *argv[]) { + int roled; + for(int i = 1; i < argc; i++) { + roled = GetDice(argv[i]); + if(roled <= 0) { + printf("FORMAT ERROR\n"); return -1; + } + printf("%s: Roled a %d\n",argv[i], GetDice(argv[i])); + } + return 0; +}