Guest User

High Roller by SuicidalSTDz

a guest
Apr 12th, 2013
179
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Lua 3.39 KB | None | 0 0
  1. --[[Logo]]--
  2. local logo = {
  3.     " _____ _     _      _____     _ _         ",
  4.     "|  |  |_|___| |_   | __  |___| | |___ ___ ",
  5.     "|     | | . |   |  |    -| . | | | -_|  _|",
  6.     "|__|__|_|_  |_|_|  |__|__|___|_|_|___|_|  ",
  7.     "        |___|                             ",
  8.     " _____     ",
  9.     "| __  |_ _ ",
  10.     "| __ -| | |",
  11.     "|_____|_  |",
  12.     "      |___|",
  13.     "  _____     _     _   _     _ _____ _____ ____      ",
  14.     " |   __|_ _|_|___|_|_| |___| |   __|_   _|    \\ ___ ",
  15.     " |__   | | | |  _| | . | .'| |__   | | | |  |  |- _|",
  16.     " |_____|___|_|___|_|___|__,|_|_____| |_| |____/|___|"
  17. }
  18.  
  19. --[[Define the dice in a table]]--
  20. local dice = {
  21.     [1] = {
  22.         "*-------*",
  23.         "|       |",
  24.         "|   *   |",
  25.         "|       |",
  26.         "*-------*"
  27.     },
  28.     [2] = {
  29.         "*-------*",
  30.         "| *     |",
  31.         "|       |",
  32.         "|     * |",
  33.         "*-------*"
  34.     },
  35.     [3] = {
  36.         "*-------*",
  37.         "|     * |",
  38.         "|   *   |",
  39.         "| *     |",
  40.         "*-------*"
  41.     },
  42.     [4] = {
  43.         "*-------*",
  44.         "| *   * |",
  45.         "|       |",
  46.         "| *   * |",
  47.         "*-------*"
  48.     },
  49.     [5] = {
  50.         "*-------*",
  51.         "| *   * |",
  52.         "|   *   |",
  53.         "| *   * |",
  54.         "*-------*"
  55.     },
  56.     [6] = {
  57.         "*-------*",
  58.         "| *   * |",
  59.         "| *   * |",
  60.         "| *   * |",
  61.         "*-------*"
  62.     }
  63. }
  64.      
  65. --[[Get the width and height of the terminal/screen]]--
  66. local w,h = term.getSize()
  67.  
  68. --[[Define the varaible 'win']]--
  69. local wins = 0
  70.      
  71. --[[Define a 'center text' function]]--
  72. local function center(text,y)
  73.     term.setCursorPos(((w-#text)/2)+1,y)
  74.     term.write(text)
  75. end
  76.      
  77. --[[Defining a function to print the logo]]--
  78. local function printLogo()
  79.     term.clear()
  80.     term.setCursorPos(1,1)
  81.     local y = (h/5)
  82.     local diff = y
  83.     for _,v in pairs(logo) do
  84.         center(v,diff)
  85.         diff = (diff+1)
  86.     end
  87.     sleep(3)
  88. end
  89.  
  90. --[[Define a function to catch any errors]]--
  91. local function err(path)
  92.     local ok,err = pcall(path)
  93.     if not ok then
  94.         term.clear()
  95.         center("An error has occured!",1)
  96.         center(err,h/2)
  97.         center("Press any key to continue",h)
  98.     end
  99.     os.pullEvent("key")
  100.     term.clear()
  101.     term.setCursorPos(1,1)
  102.     return
  103. end
  104.    
  105. --[[Define the 'dice roll' function]]--
  106. local function roll()
  107.     while true do
  108.         repeat
  109.             local y = (h/2)-2
  110.             os.startTimer(0.001)
  111.             ev,p1 = os.pullEvent()
  112.             term.clear()
  113.             center("Press the 'tilde' key to stop the dice!",1)
  114.             center("High Roller is coded by SuicidalSTDz!",19)
  115.             center("Wins: "..wins,15)
  116.             randomNum = math.random(1,6)
  117.             for _,v in pairs(dice[randomNum]) do
  118.                 term.setCursorPos(((w-9)/2)+1,y)
  119.                 term.write(v)
  120.                 y = (y+1)
  121.             end
  122.         until ev == "key" and p1 == 41
  123.         if randomNum == 6 then
  124.             wins = (wins+1)
  125.         end
  126.         term.setCursorPos(1,15)
  127.         term.clearLine()
  128.         center("Wins: "..wins,15)
  129.         term.setCursorPos(1,2)
  130.         term.clearLine()
  131.         center("Press any other key to exit",2)
  132.         center("Press the 'tilde' key to roll the dice!",1)
  133.         repeat
  134.             _,p1 = os.pullEvent("key")
  135.             if p1 ~= 41 then
  136.                 term.clear()
  137.                 term.setCursorPos(1,1)
  138.                 os.run({},"rom/programs/shell")
  139.             end
  140.         until p1 == 41
  141.     end
  142. end
  143.  
  144. --[[Print the contents of the table 'logo' using the function I defined earlier]]--
  145. printLogo()
  146.  
  147. --[[Call the 'roll' function]]--
  148. err(roll)
Advertisement
Add Comment
Please, Sign In to add comment