Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- --Variables
- --Functions
- function init()
- drawMenu()
- menuInput = getMenuInput()
- if menuInput == "repeat" then
- init()
- end
- if menuInput == 1 then
- flipCoin()
- end
- if menuInput == 2 then
- rollDie()
- end
- if menuInput == 3 then
- throwCard()
- end
- if menuInput == 4 then
- exit()
- else
- init()
- end
- end
- function exit()
- term.clear()
- term.setCursorPos(6,1)
- term.setTextColor(colors.green)
- term.write("Thank you for using probablity simulator!")
- term.setCursorPos(6,2)
- term.write("By TNT_Nolan!")
- term.setCursorPos(1,3)
- end
- function startup()
- _img = paintutils.loadImage(shell.dir() .. "/probablitysimpaint")
- term.clear()
- term.setCursorPos(1,1)
- paintutils.drawImage(_img,1,1)
- term.setCursorPos(15,18)
- term.setTextColor(colors.green)
- term.setBackgroundColor(colors.black)
- term.write("Probablity Sim 0.2alpha by TNT_Nolan")
- sleep(2.5)
- init()
- end
- function drawMenu()
- term.clear()
- term.setCursorPos(11,1)
- term.setTextColor(colors.white)
- print("Probality Sim by TNT_Nolan")
- term.setCursorPos(1,3)
- print("[1] Flip a coin")
- term.setCursorPos(1,4)
- print("[2] Roll a die")
- term.setCursorPos(1,5)
- print("[3] Throw a card")
- term.setCursorPos(1,6)
- print("[4] Exit")
- end
- function getMenuInput()
- term.setCursorPos(1,19)
- term.setTextColor(colors.green)
- input = io.read()
- input = tonumber(input)
- if input > 0 and input < 5 then
- return input
- elseif input == 4 then
- return input
- else
- return "repeat"
- end
- end
- function flipCoin()
- term.clear()
- term.setCursorPos(15,1)
- term.setTextColor(colors.lime)
- term.write("Flip a coin")
- term.setCursorPos(1,18)
- term.write("Flip a coin? [y/n]: ")
- input = read()
- if input == "n" then
- return
- elseif input == "y" then
- chance = probablity("coin")
- else
- flipCoin()
- end
- if chance == "tails" then
- term.setCursorPos(16,5)
- term.write("(T)")
- term.setCursorPos(16,7)
- term.write("Tails")
- sleep(2)
- elseif chance == "heads" then
- term.setCursorPos(16,5)
- term.write("(H)")
- term.setCursorPos(16,7)
- term.write("Heads")
- sleep(2)
- end
- flipCoin()
- end
- function rollDie()
- term.clear()
- term.setCursorPos(15,1)
- term.setTextColor(colors.lime)
- term.write("Roll a die")
- term.setCursorPos(1,18)
- term.write("Roll a die? [y/n] ")
- input = read()
- if input == "n" then
- return
- elseif input == "y" then
- chance = probablity("die")
- else
- rollDie()
- end
- term.setCursorPos(1,5)
- if chance == 1 then
- print("+---+")
- print("| |")
- print("| o |")
- print("| |")
- print("+---+")
- print("One")
- elseif chance == 2 then
- print("+---+")
- print("|o |")
- print("| |")
- print("| o|")
- print("+---+")
- print("Two")
- elseif chance == 3 then
- print("+---+")
- print("| o|")
- print("| o |")
- print("|o |")
- print("+---+")
- print("Three")
- elseif chance == 4 then
- print("+---+")
- print("|o o|")
- print("| |")
- print("|o o|")
- print("+---+")
- print("Four")
- elseif chance == 5 then
- print("+---+")
- print("|o o|")
- print("| o |")
- print("|o o|")
- print("+---+")
- print("Five")
- elseif chance == 6 then
- print("+---+")
- print("|o o|")
- print("|o o|")
- print("|o o|")
- print("+---+")
- print("Six")
- end
- sleep(2)
- rollDie()
- end
- function throwCard()
- term.clear()
- term.setCursorPos(18,1)
- term.setTextColor(colors.lime)
- print("Throw a Card")
- term.setCursorPos(1,18)
- term.write("Throw a card? [y/n]: ")
- input = read()
- if input == "y" then
- cardnumber = probablity("cardnumber")
- elseif input == "n" then
- return
- else
- throwCard()
- end
- term.setCursorPos(1,6)
- if cardnumber == 2 then
- print("+----+")
- print("|2 2|")
- print("| |")
- print("|2 2|")
- print("+----+")
- elseif cardnumber == 3 then
- print("+----+")
- print("|3 3|")
- print("| |")
- print("|3 3|")
- print("+----+")
- elseif cardnumber == 4 then
- print("+----+")
- print("|4 4|")
- print("| |")
- print("|4 4|")
- print("+----+")
- elseif cardnumber == 5 then
- print("+----+")
- print("|5 5|")
- print("| |")
- print("|5 5|")
- print("+----+")
- elseif cardnumber == 6 then
- print("+----+")
- print("|6 6|")
- print("| |")
- print("|6 6|")
- print("+----+")
- elseif cardnumber == 7 then
- print("+----+")
- print("|7 7|")
- print("| |")
- print("|7 7|")
- print("+----+")
- elseif cardnumber == 8 then
- print("+----+")
- print("|8 8|")
- print("| |")
- print("|8 8|")
- print("+----+")
- elseif cardnumber == 9 then
- print("+----+")
- print("|9 9|")
- print("| |")
- print("|9 9|")
- print("+----+")
- elseif cardnumber == 10 then
- print("+----+")
- print("| |")
- print("| 10 |")
- print("| |")
- print("+----+")
- elseif cardnumber == 11 then
- print("+----+")
- print("|J J|")
- print("| |")
- print("|J J|")
- print("+----+")
- elseif cardnumber == 12 then
- print("+----+")
- print("|Q Q|")
- print("| |")
- print("|Q Q|")
- print("+----+")
- elseif cardnumber == 13 then
- print("+----+")
- print("|K K|")
- print("| |")
- print("|K K|")
- print("+----+")
- elseif cardnumber == 14 then
- print("+----+")
- print("| |")
- print("| A |")
- print("| |")
- print("+----+")
- end
- cardType = probablity("cardtype")
- if cardType == 1 then
- print("Clubs")
- end
- if cardType == 2 then
- print("Spades")
- end
- if cardType == 3 then
- print("Diamonds")
- end
- if cardType == 4 then
- print("Hearts")
- end
- sleep(2)
- throwCard()
- end
- function probablity(mode)
- if mode == "coin" then
- number = math.random(1,2)
- if number == 2 then
- return "heads"
- elseif number == 1 then
- return "tails"
- end
- end
- if mode == "die" then
- number = math.random(1,6)
- return number
- end
- if mode == "cardnumber" then
- number = math.random(2,14)
- return number
- end
- if mode == "cardtype" then
- number = math.random(1,4)
- return number
- end
- end
- startup()
Advertisement
Add Comment
Please, Sign In to add comment