Advertisement
Martmists

PocketPC.lua

Mar 21st, 2016
337
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Lua 3.85 KB | None | 0 0
  1. function MainScreen()
  2.     Clear()
  3.  
  4.     term.setBackgroundColor(colors.black)
  5.     term.setCursorPos(1,1)
  6.     print("Frequency: "..Port)
  7.    
  8.     term.setBackgroundColor(colors.red)
  9.     for I = 1, 26 do
  10.         term.setCursorPos(I,19)
  11.         term.write(" ")
  12.     end
  13.     term.setCursorPos(12,19)
  14.     term.write("Exit")
  15.    
  16.    
  17.     term.setBackgroundColor(colors.green)
  18.     for I = 1, 26 do
  19.         term.setCursorPos(I,2)
  20.         term.write(" ")
  21.     end
  22.     term.setCursorPos(10,2)
  23.     term.write("Log In")
  24.    
  25.     for I = 1, 26 do
  26.         term.setCursorPos(I,4)
  27.         term.write(" ")
  28.     end
  29.     term.setCursorPos(5,4)
  30.     term.write("Create New Account")
  31. end
  32.  
  33. function Clear()
  34.     term.setBackgroundColor(colors.black)
  35.     shell.run("clear")
  36. end
  37.  
  38. function Init()
  39.     shell.run("clear")
  40.     loop = true
  41.     Mode = "MainMode"
  42.     modem = peripheral.wrap("back")
  43.     ID = os.getComputerID()
  44.     Port = ID + 12345
  45.     modem.open(Port)
  46. end
  47.  
  48. function MenuLogin()
  49.     Clear()
  50.     modem.transmit(12345, Port, ID)
  51.     print("Please enter your password.")
  52.     Pass = read("*")
  53.     modem.transmit(12345, Port, Pass)
  54.     event, side, x, y, success = os.pullEvent("modem_message")
  55.     if success == "true" then
  56.         print("Login successful.")
  57.         Mode = "LoggedIn"
  58.     else
  59.         print("Login Failed.")
  60.     end
  61.     sleep(1)
  62. end
  63.  
  64. function MenuNewAcc()
  65.     Clear()
  66.     modem.transmit(12345, Port, ID)
  67.     print("Requesting new account...")
  68.     print("Please set a password: ")
  69.     Pass = read("*")
  70.     modem.transmit(12345, Port, Pass)
  71.     event, side, x, y, message = os.pullEvent("modem_message")
  72.     if message == "Used" then
  73.         print("There already is an account for this pc.")
  74.     else
  75.         print("Created new account!")
  76.     end
  77.     sleep(1)
  78. end
  79.  
  80. function LoggedInScreen()
  81.     print("Receiving currency...")
  82.     modem.transmit(12345, Port, "getCurrency")
  83.     modem.transmit(12345, Port, ID)
  84.     event, side, x, y, currency = os.pullEvent("modem_message")
  85.     Clear()
  86.  
  87.     term.setBackgroundColor(colors.gray)
  88.     term.setCursorPos(1,1)
  89.     print("Frequency: "..Port.."              ")
  90.     print("Currency: "..currency.."               ")
  91.     print("ID: "..ID.."                        ")
  92.    
  93.     term.setBackgroundColor(colors.red)
  94.     for I = 1, 26 do
  95.         term.setCursorPos(I,19)
  96.         term.write(" ")
  97.     end
  98.     term.setCursorPos(11,19)
  99.     term.write("Log Out")
  100.    
  101.    
  102.     term.setBackgroundColor(colors.green)
  103.     for I = 1, 26 do
  104.         term.setCursorPos(I,5)
  105.         term.write(" ")
  106.     end
  107.     term.setCursorPos(6,5)
  108.     term.write("Update Currency")
  109.    
  110.     for I = 1, 26 do
  111.         term.setCursorPos(I,7)
  112.         term.write(" ")
  113.     end
  114.     term.setCursorPos(10,7)
  115.     term.write("Transfer")
  116. end
  117.  
  118. function MenuTransfer()
  119.     Clear()
  120.     sleep(0.3)
  121.     modem.transmit(12345, Port, "Transfer")
  122.     sleep(0.3)
  123.     modem.transmit(12345, Port, ID)
  124.     print("Please select ID to send to:")
  125.     ToUser = read()
  126.     modem.transmit(12345, Port, ToUser)
  127.     print("Amount to transfer: ")
  128.     Amount = read()
  129.     modem.transmit(12345, Port, Amount)
  130.     event, side, x,y, message = os.pullEvent("modem_message")
  131.     if message == "NotEnough" then
  132.         print("Not enough Currency.")
  133.     elseif message == "InvalidUser" then
  134.         print("Invalid User ID.")
  135.     else
  136.         print("Successful transfer of "..Amount.." to "..ToUser)
  137.     end
  138.     sleep(1)
  139. end
  140.  
  141. function Main()
  142.     Init()
  143.     while loop do
  144.         if Mode == "MainMode" then
  145.             MainScreen()
  146.         elseif Mode == "LoggedIn" then
  147.             LoggedInScreen()
  148.         end
  149.        
  150.         event, button, x, y = os.pullEvent("mouse_click")
  151.        
  152.         if Mode == "MainMode" then
  153.             if y == 2 then
  154.                 modem.transmit(12345, Port, "LogIn")
  155.                 MenuLogin()
  156.             elseif y == 4 then
  157.                 modem.transmit(12345, Port, "CreateNew")
  158.                 MenuNewAcc()
  159.             elseif y == 19 then
  160.                 loop = false
  161.                 modem.close(Port)
  162.             end
  163.         elseif Mode == "LoggedIn" then
  164.             if y == 5 then
  165.                 modem.transmit(12345, Port, "getCurrency")
  166.                 sleep(0.3)
  167.                 modem.transmit(12345, Port, ID)
  168.                 event, side, x, y, currency = os.pullEvent("modem_message")
  169.             elseif y == 7 then
  170.                 MenuTransfer()
  171.             elseif y == 19 then
  172.                 Mode = "MainMode"
  173.             end
  174.         end
  175.     end
  176. end
  177.  
  178. Main() 
  179. Clear()
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement