//Linux dice roller for Dragons, Druids, and Dice
// version 1.2 2025

#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include <time.h>
#include "GDXlib.h"

void roll_one_four(void); 
void roll_one_six(void);
void roll_one_eight(void);
void roll_one_ten(void);
void roll_one_twelve(void);
void roll_one_twenty(void);
void roll_four_six(void);
void roll_two_twenty(void);
void roll_four_and_six(void);

//////////////////////////////////////////////////
// main
/////////////////////////////////////////////////
int main(int argc, char **argv){


  int button_01; //roll 4
  int button_02; //roll 6
  int button_03; //roll 8
  int button_04; //roll 10
  int button_05; //roll 12
  int button_06; //roll 20
  int button_07; //roll four 6d
  int button_08; //roll two 20d
  int button_09; //roll 4d and 6d

  x_open();

  /* create a new window */
  gdx_window("DDD Dice Roller",500,450);
  gdx_setwindowbg("images/dragon-n-dice.xpm",1);

  button_01 = gdx_button(5,25, "roll dice - one d4 ",roll_one_four);
  button_02 = gdx_button(5,50, "roll dice - one d6 ",roll_one_six);
  button_03 = gdx_button(5,75, "roll dice - one d8 ",roll_one_eight);
  button_04 = gdx_button(5,100,"roll dice - one d10",roll_one_ten);
  button_05 = gdx_button(5,125,"roll dice - one d12",roll_one_twelve);
  button_06 = gdx_button(5,150,"roll dice - one d20",roll_one_twenty);
  button_07 = gdx_button(5,175,"roll dice - four d6",roll_four_six);
  button_08 = gdx_button(5,200,"roll dice - two d20",roll_two_twenty);
  button_09 = gdx_button(5,225,"roll dice d4 and d6",roll_four_and_six);

  gdx_main();
  x_close();

  return(0);
}

void roll_one_four()
{
    int randomnumber;
    char msg[25];
    srand(time(NULL));
    randomnumber = ( rand() % 4) +1;
    sprintf(msg,"You rolled a %d from a d4!", randomnumber);
    x_msgbox(5,msg,"You rolled a single d4! ","fixed",50);
}

void roll_one_six()
{
    int randomnumber;
    char msg[25];
    srand(time(NULL));
    randomnumber = (rand() % 6) +1;
    sprintf(msg,"You rolled a %d from a d6!", randomnumber);
    x_msgbox(5,msg,"You rolled a single d6!","fixed",50);
}

void roll_one_eight()
{
    int randomnumber;
    char msg[25];
    srand(time(NULL));
    randomnumber = (rand() % 8) +1;
    sprintf(msg,"You rolled a %d from a d8!", randomnumber);
    x_msgbox(5,msg,"You rolled a single d8!","fixed",50);
}

void roll_one_ten()
{
    int randomnumber;
    char msg[25];
    srand(time(NULL));
    randomnumber = (rand() % 10) +1;
    sprintf(msg,"You rolled a %d from a 10d!", randomnumber);
    x_msgbox(5,msg,"You rolled a single d10!","fixed",50);
}

void roll_one_twelve()
{
    int randomnumber;
    char msg[25];
    srand(time(NULL));
    randomnumber = (rand() % 12) +1;
    sprintf(msg,"You rolled a %d from a d12!", randomnumber);
    x_msgbox(5,msg,"You rolled a single d12!","fixed",50);
}


void roll_one_twenty()
{
    int randomnumber;
    char msg[25];
    srand(time(NULL));
    randomnumber = (rand() % 20) +1;
    sprintf(msg,"You rolled a %d from a d20!", randomnumber);
    x_msgbox(5,msg,"You rolled a single d20!","fixed",50);
}

void roll_four_six()
{
    int randomnum1;
    int randomnum2;
    int randomnum3;
    int randomnum4;
    char msg[25];
    srand(time(NULL));
    randomnum1 = (rand() % 6) +1;
    randomnum2 = (rand() % 6) +1;
    randomnum3 = (rand() % 6) +1;
    randomnum4 = (rand() % 6) +1;
    sprintf(msg,"You rolled a %d, %d, %d, %d from four d6!", randomnum1,randomnum2,randomnum3,randomnum4);
    x_msgbox(5,msg,"You rolled four d6!","fixed",50);
}

void roll_two_twenty()
{
    int randomnum1;
    int randomnum2;
    char msg[25];
    srand(time(NULL));
    randomnum1 = (rand() % 20) +1;
    randomnum2 = (rand() % 20) +1;
    sprintf(msg,"You rolled a %d, %d from two d20!", randomnum1,randomnum2);
    x_msgbox(5,msg,"You rolled two d20!","fixed",50);
}

void roll_four_and_six()
{
    int randomnum1;
    int randomnum2;
    char msg[25];
    srand(time(NULL));
    randomnum1 = (rand() % 4) +1;
    randomnum2 = (rand() % 6) +1;
    sprintf(msg,"You rolled a %d and %d from d4 and d6!", randomnum1,randomnum2);
    x_msgbox(5,msg,"You rolled a d4 and d6!","fixed",50);
}
