Post by Mark Dunham on Mar 30, 2018 20:31:11 GMT -5
This is the code for a Dungeons and Dragons dice roller. It is one of the first programs I created and I am still thinking about refactoring the code to make it more efficient.
nomainwin
WindowWidth = 550
WindowHeight = 410
UpperLeftX = int((DisplayWidth - WindowWidth) / 2)
UpperLeftY = int((DisplayHeight - WindowHeight) / 2)
d4Total = 0
d6Total = 0
d8Total = 0
d10Total = 0
d12Total = 0
d20Total = 0
d100Total = 0
statictext #main.statictext1, "Dice Type", 26, 16, 72, 20
statictext #main.statictext2, "No. of Dice", 118, 16, 88, 20
statictext #main.statictext3, "Modifier +/-", 214, 16, 96, 20
statictext #main.statictext4, "Result", 446, 16, 48, 20
'FOUR SIDED DICE
statictext #main.statictext5, "D4", 46, 41, 16, 20
textbox #main.numD4, 134, 36, 25, 25
checkbox #main.checkboxD4pos, "+", [checkboxD4posSet], [d4ModReset], 248, 41, 24, 20
checkbox #main.checkboxD4neg, "-", [checkboxD4negSet], [d4ModReset], 272, 41, 24, 20
textbox #main.d4Mod, 214, 36, 25, 25
button #main.button10, "Roll", [d4Roll], UL, 326, 36, 75, 25
textbox #main.d4Result, 430, 36, 75, 25
'SIX SIDED DICE
statictext #main.statictext12, "D6", 46, 71, 16, 20
textbox #main.numD6, 134, 66, 25, 25
checkbox #main.checkboxD6pos, "+", [checkboxD6posSet], [d6ModReset], 248, 71, 24, 20
checkbox #main.checkboxD6neg, "-", [checkboxD6negSet], [d6ModReset], 272, 71, 24, 20
textbox #main.d6Mod, 214, 66, 25, 25
button #main.button17, "Roll", [d6Roll], UL, 326, 66, 75, 25
textbox #main.d6Result, 430, 66, 75, 25
'EIGHT SIDED DICE
statictext #main.statictext19, "D8", 46, 101, 16, 20
textbox #main.numD8, 134, 96, 25, 25
checkbox #main.checkboxD8pos, "+", [checkboxD8posSet], [d8ModReset], 248, 101, 24, 20
checkbox #main.checkboxD8neg, "-", [checkboxD8negSet], [d8ModReset], 272, 101, 24, 20
textbox #main.d8Mod, 214, 96, 25, 25
button #main.button24, "Roll", [d8Roll], UL, 326, 96, 75, 25
textbox #main.d8Result, 430, 96, 75, 25
'TEN SIDED DICE
statictext #main.statictext26, "D10", 46, 131, 24, 20
textbox #main.numD10, 134, 126, 25, 25
checkbox #main.checkboxD10pos, "+", [checkboxD10posSet], [d10ModReset], 248, 131, 24, 20
checkbox #main.checkboxD10neg, "-", [checkboxD10negSet], [d10ModReset], 272, 131, 24, 20
textbox #main.d10Mod, 214, 126, 25, 25
button #main.d10Roll, "Roll", [d10Roll], UL, 326, 126, 75, 25
textbox #main.d10Result, 430, 126, 75, 25
'TWELVE SIDED DICE
statictext #main.statictext33, "D12", 46, 161, 24, 20
textbox #main.numD12, 134, 156, 25, 25
checkbox #main.checkboxD12pos, "+", [checkboxD12posSet], [d12ModReset], 248, 161, 24, 20
checkbox #main.checkboxD12neg, "-", [checkboxD12negSet], [d12ModReset], 272, 161, 24, 20
textbox #main.d12Mod, 214, 156, 25, 25
button #main.button38, "Roll", [d12Roll], UL, 326, 156, 75, 25
textbox #main.d12Result, 430, 156, 75, 25
'TWENTY SIDED DICE
statictext #main.statictext40, "D20", 46, 191, 24, 20
textbox #main.numD20, 134, 186, 25, 25
checkbox #main.checkboxD20pos, "+", [checkboxD20posSet], [d20ModReset], 248, 191, 24, 20
checkbox #main.checkboxD20neg, "-", [checkboxD20negSet], [d20ModReset], 272, 191, 24, 20
textbox #main.d20Mod, 214, 186, 25, 25
button #main.button45, "Roll", [d20Roll], UL, 326, 186, 75, 25
textbox #main.d20Result, 430, 186, 75, 25
'HUNDRED SIDED DICE
statictext #main.statictext47, "D100", 46, 221, 32, 20
textbox #main.numD100, 134, 216, 25, 25
checkbox #main.checkboxD100pos, "+", [checkboxD100posSet], [d100ModReset], 248, 221, 24, 20
checkbox #main.checkboxD100neg, "-", [checkboxD100negSet], [d100ModReset], 272, 221, 24, 20
textbox #main.d100Mod, 214, 216, 25, 25
button #main.button52, "Roll", [d100Roll], UL, 326, 216, 75, 25
textbox #main.d100Result, 430, 216, 75, 25
open "Dice Roller" for window_nf as #main
print #main, "font ms_sans_serif 8 bold"
print #main, "trapclose [quit]"
print #main.numD4, "1"
print #main.numD6, "1"
print #main.numD8, "1"
print #main.numD10, "1"
print #main.numD12, "1"
print #main.numD20, "1"
print #main.numD100, "1"
goto [startTip]
[main.inputLoop] 'wait here for input event
wait
'*************************************************************************************
'*************************************************************************************
[checkboxD4posSet] 'Perform action for the checkbox
d4Total = 0
print #main.checkboxD4neg, "reset"
print #main.d4Mod, "!contents? d4Mod"
d4Total = d4Total + d4Mod
wait
[checkboxD4negSet] 'Perform action for the checkbox
d4Total = 0
print #main.checkboxD4pos, "reset"
print #main.d4Mod, "!contents? d4Mod"
d4Total = d4Total - d4Mod
wait
[d4ModReset] 'Perform action for the checkbox uncheck
print #main.d4Mod, " "
d4Mod = 0
d4Total = 0
goto [main.inputLoop]
[d4Roll] 'Perform action for the button
print #main.numD4, "!contents? d4Rolls"
'd4 = int(rnd(1) * 4) + 1
'print #main.d4Result, d4Total + d4
d4Temp = 0
for i = 1 to d4Rolls
if i <= d4Rolls then
d4 = int(rnd(1) * 4) + 1
d4Temp = d4Temp + d4
end if
next i
print #main.d4Result, d4Total + d4Temp
wait
'*************************************************************************************
'*************************************************************************************
[checkboxD6posSet]
d6Total = 0
print #main.checkboxD6neg, "reset"
print #main.d6Mod, "!contents? d6Mod"
d6Total = d6Total + d6Mod
wait
[checkboxD6negSet]
d6Total = 0
print #main.checkboxD6pos, "reset"
print #main.d6Mod, "!contents? d6Mod"
d6Total = d6Total - d6Mod
wait
[d6ModReset]
print #main.d6Mod, " "
d6Mod = 0
d6Total = 0
goto [main.inputLoop]
[d6Roll]
print #main.numD6, "!contents? d6Rolls"
d6Temp = 0
for i = 1 to d6Rolls
if i <= d6Rolls then
d6 = int(rnd(1) * 6) + 1
d6Temp = d6Temp + d6
end if
next i
print #main.d6Result, d6Total + d6Temp
wait
'*************************************************************************************
'*************************************************************************************
[checkboxD8posSet]
d8Total = 0
print #main.checkboxD8neg, "reset"
print #main.d8Mod, "!contents? d8Mod"
d8Total = d8Total + d8Mod
wait
[checkboxD8negSet]
d8Total = 0
print #main.checkboxD8pos, "reset"
print #main.d8Mod, "!contents? d8Mod"
d8Total = d8Total - d8Mod
wait
[d8ModReset]
print #main.d8Mod, " "
d8Mod = 0
d8Total = 0
goto [main.inputLoop]
[d8Roll]
print #main.numD8, "!contents? d8Rolls"
d8Temp = 0
for i = 1 to d8Rolls
if i <= d8Rolls then
d8 = int(rnd(1) * 8) + 1
d8Temp = d8Temp + d8
end if
next i
print #main.d8Result, d8Total + d8Temp
wait
'*************************************************************************************
'*************************************************************************************
[checkboxD10posSet]
d10Total = 0
print #main.checkboxD10neg, "reset"
print #main.d10Mod, "!contents? d10Mod"
d10Total = d10Total + d10Mod
wait
[checkboxD10negSet]
d10Total = 0
print #main.checkboxD10pos, "reset"
print #main.d10Mod, "!contents? d10Mod"
d10Total = d10Total - d10Mod
wait
[d10ModReset]
print #main.d10Mod, " "
d10Mod = 0
d10Total = 0
goto [main.inputLoop]
[d10Roll]
print #main.numD10, "!contents? d10Rolls"
d10Temp = 0
for i = 1 to d10Rolls
if i <= d10Rolls then
d10 = int(rnd(1) * 10) + 1
d10Temp = d10Temp + d10
end if
next i
print #main.d10Result, d10Total + d10Temp
wait
'*************************************************************************************
'*************************************************************************************
[checkboxD12posSet]
d12Total = 0
print #main.checkboxD12neg, "reset"
print #main.d12Mod, "!contents? d12Mod"
d12Total = d12Total + d12Mod
wait
[checkboxD12negSet]
d12Total = 0
print #main.checkboxD12pos, "reset"
print #main.d12Mod, "!contents? d12Mod"
d12Total = d12Total - d12Mod
wait
[d12ModReset]
print #main.d12Mod, " "
d12Mod = 0
d12Total = 0
goto [main.inputLoop]
[d12Roll]
print #main.numD12, "!contents? d12Rolls"
d12Temp = 0
for i = 1 to d12Rolls
if i <= d12Rolls then
d12 = int(rnd(1) * 12) + 1
d12Temp = d12Temp + d12
end if
next i
print #main.d12Result, d12Total + d12Temp
wait
'*************************************************************************************
'*************************************************************************************
[checkboxD20posSet]
d20Total = 0
print #main.checkboxD20neg, "reset"
print #main.d20Mod, "!contents? d20Mod"
d20Total = d20Total + d20Mod
wait
[checkboxD20negSet]
d20Total = 0
print #main.checkboxD20pos, "reset"
print #main.d20Mod, "!contents? d20Mod"
d20Total = d20Total - d20Mod
wait
[d20ModReset]
print #main.d20Mod, " "
d20Mod = 0
d20Total = 0
goto [main.inputLoop]
[d20Roll]
print #main.numD20, "!contents? d20Rolls"
d20Temp = 0
for i = 1 to d20Rolls
if i <= d20Rolls then
d20 = int(rnd(1) * 20) + 1
d20Temp = d20Temp + d20
end if
next i
print #main.d20Result, d20Total + d20Temp
wait
'*************************************************************************************
'*************************************************************************************
[checkboxD100posSet]
d100Total = 0
print #main.checkboxD100neg, "reset"
print #main.d100Mod, "!contents? d100Mod"
d100Total = d100Total + d100Mod
wait
[checkboxD100negSet]
d100Total = 0
print #main.checkboxD100pos, "reset"
print #main.d100Mod, "!contents? d100Mod"
d100Total = d100Total - d100Mod
wait
[d100ModReset]
print #main.d100Mod, " "
d100Mod = 0
d100Total = 0
goto [main.inputLoop]
[d100Roll]
print #main.numD100, "!contents? d100Rolls"
d100Temp = 0
for i = 1 to d100Rolls
if i <= d100Rolls then
d100 = int(rnd(1) * 100) + 1
d100Temp = d100Temp + d100
end if
next i
print #main.d100Result, d100Total + d100Temp
wait
'*************************************************************************************
'*************************************************************************************
[startTip]
WindowWidth = 320
WindowHeight = 240
UpperLeftX = int((DisplayWidth - WindowWidth) / 2)
UpperLeftY = int((DisplayHeight - WindowHeight) / 2)
statictext #tips.sttxt1, "When adding or subtracting a modifier put the", 10, 10, 300, 20
statictext #tips.sttxt2, "modifier number in before checking the plus or", 10, 30, 300, 20
statictext #tips.sttxt3, "minus checkbox.", 10, 50, 300, 20
statictext #tips.sttxt4, "This is a limitation I am working to find a", 10, 70, 300, 20
statictext #tips.sttxt5, "solution for a future update.", 10, 90, 300, 20
open "Tip:" for window as #tips
print #tips, "font ms_sans_serif 8 bold"
print #tips, "trapclose [startTip.quit]"
wait
[startTip.quit]
close #tips
goto [main.inputLoop]
[quit]
close #main
end