Advertisement
Guest User

startup

a guest
Jul 23rd, 2014
220
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Lua 2.56 KB | None | 0 0
  1. function save(table, name)
  2.   local file = fs.open(name, "w")
  3.   file.write(textutils.serialize(table))
  4.   file.close()
  5. end
  6. function load(name)
  7.   local file = fs.open(name, "r")
  8.   local data = file.readAll()
  9.   file.close()
  10.   return textutils.unserialize(data)
  11. end
  12. function winnings(amount, result, rand)
  13.   print(rand)
  14.   if (result == 1) then
  15.     money[c_User] = money[c_User] + amount + amount
  16.     print("well done")
  17.     print("you won "..amount)
  18.     print("you now have "..money[c_User])
  19.   elseif (result == 0) then
  20.     print("unlucky")
  21.     print("you lost "..amount)
  22.     print("you now have "..money[c_User])
  23.   end
  24. save(money, money)
  25. end
  26. print("Welcome to Casino v0.1.1")
  27. local user = {llama = "i awesome"}
  28. local money = {llama = 100}
  29. check = 1
  30. while (check == 1) do
  31.   print("Username: ")
  32.   userin = read()
  33.   print("Password: ")
  34.   passin = read("*")
  35.   if (user[userin] == passin) then
  36.     c_User = userin
  37.     check = 0
  38.   end
  39. end
  40. print("What to do?")
  41. print("gamble -gamble-")
  42. print("display balance -display-")
  43. print("logout -logout-")
  44. input = read()
  45. if (input == "gamble") then
  46.   print("how much do you want to bet?")
  47.   amount = read()
  48.   if (amount > money[c_User]) then
  49.   print("You don't have enough money")
  50.   else
  51.   money[c_User] = money[c_User] - amount
  52.   print("What Game?")
  53.   print(" ")
  54.   print("Basic Virtual Roulette -roulette-")
  55.   print("To Be Added")
  56.   print("cancel -cancel-")
  57.   save(money, money)
  58.   game = read()
  59.   if (game == "roulette") then
  60.     print("Yay, lets play roulette")
  61.     print("You can guess higher or lower than 18, or guess a single number")
  62.     print("Please enter higher, lower or number")
  63.     roulette = read()
  64.     rand = math.random(36)
  65.     if (roulette == "higher") then
  66.       if (rand > 18) then
  67.         winnings(amount, 1, rand)
  68.       else
  69.         winnings(amount, 0, rand)
  70.       end
  71.     elseif (roulette == "lower") then
  72.       if (rand < 18) then
  73.         winnings(amount, 1, rand)
  74.       else
  75.         winnings(amount, 0, rand)
  76.       end
  77.     elseif (roulette == "number") then
  78.       print("What number do you want to guess")
  79.       roulette_Guess = read()
  80.       if (roulette_guess == rand) then
  81.         thing = amount * 35
  82.         winnings(thing, 1, rand)
  83.       else
  84.         winnings(amount, 0, rand)
  85.       end
  86.     end
  87.   end
  88.   elseif (game == "cancel") then
  89.     money[c_User] = money[c_User] + amount
  90.     save(money, money)
  91.   end
  92. elseif (input == "display") then
  93.   print("Your Balance Is: ")
  94.   print(money[c_User])
  95. elseif (input == "logout") then
  96.   save(money, money)
  97.   save(user, user)
  98. end
  99. end
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement