Advertisement
Guest User

startup

a guest
May 1st, 2016
92
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Lua 7.81 KB | None | 0 0
  1. IDTerminal = 909
  2. rednet.open("back")
  3. local psd = ""
  4. local motdepasse = ""
  5. local hideMdp = ""
  6. local CompteValider=false
  7. local historique = {}
  8. local solde = 0
  9. local Action="Connection"
  10. local nomTransfer = ""
  11. local sommeTransfer = 0
  12.  
  13. function Deconnection()
  14. info = {Act="Deconnection"}
  15. infos = textutils.serialise(info)
  16. rednet.send(IDTerminal,infos)
  17. end
  18.  
  19. function updateInfo()
  20. info = {Act="ActualiserC",Proprio=psd}
  21. infos = textutils.serialise(info)
  22. rednet.send(IDTerminal, infos)
  23. os.pullEvent("updateInfoReceive")
  24. end
  25.  
  26. function unfocusText()
  27. event, button, x, y = os.pullEvent("mouse_click")
  28. os.queueEvent("key",28)
  29. sleep(0.01)
  30. os.queueEvent("mouse_click",button,x,y)
  31. os.queueEvent("unfocusText")
  32. end
  33.  
  34.  
  35. function DrawMenuTransfers()
  36. shell.run("clear")
  37. img = paintutils.loadImage("MenuTransfers")
  38. paintutils.drawImage(img,1,1)
  39. term.setCursorPos(2,1)
  40. term.setBackgroundColor(colors.gray)
  41. term.setTextColor(colors.yellow)
  42. print("Bienvenue "..psd..", Votre solde : "..solde)
  43. term.setCursorPos(5,3)
  44. term.setBackgroundColor(colors.lightGray)
  45. term.setTextColor(colors.black)
  46. print("*J/E : "..nomTransfer)
  47. term.setCursorPos(40,3)
  48. print(sommeTransfer)
  49. term.setCursorPos(41,5)
  50. term.setBackgroundColor(colors.green)
  51. term.setTextColor(colors.yellow)
  52. print("Valider")
  53. term.setBackgroundColor(colors.lightGray)
  54. term.setCursorPos(5,5)
  55. print("Historique :")
  56. term.setCursorPos(41,15)
  57. term.setBackgroundColor(colors.orange)
  58. print("Annuler")
  59. term.setCursorPos(41,17)
  60. term.setBackgroundColor(colors.red)
  61. print("Retour")
  62. term.setCursorPos(4,17)
  63. term.setTextColor(colors.black)
  64. term.setBackgroundColor(colors.white)
  65. print("*J/E = Joueur/Entreprise")
  66. term.setTextColor(colors.yellow)
  67. term.setBackgroundColor(colors.gray)
  68. drawHistorique(4,6,10)
  69. end
  70.  
  71. function DrawMenuEntreprise()
  72. img = paintutils.loadImage("MenuEntreprise")
  73. paintutils.drawImage(img,1,1)
  74. term.setCursorPos(3,4)
  75. term.setTextColor(colors.yellow)
  76. term.setBackgroundColor(colors.lightGray)
  77. print("Cree Entreprise")
  78. term.setCursorPos(3,6)
  79. print("Retirer Entreprise")
  80. term.setCursorPos(3,8)
  81. print("Ajouter Membres")
  82. term.setCursorPos(3,10)
  83. print("Retirer Membres")
  84. end
  85.  
  86. function DrawMenuConnection()
  87. shell.run("clear")
  88. img = paintutils.loadImage("MenuConnection")
  89. paintutils.drawImage(img,1,1)
  90. term.setCursorPos(2,1)
  91. term.setTextColor(colors.yellow)
  92. term.setBackgroundColor(colors.gray)
  93. print("Bienvenue sur l'ATM de la banque")
  94. term.setTextColor(colors.black)
  95. term.setBackgroundColor(colors.lightGray)
  96. term.setCursorPos(12,8)
  97. print("Pseudo : "..psd)
  98. term.setCursorPos(14,11)
  99. hideMdp = ""
  100. for i =1,#motdepasse do
  101. hideMdp = hideMdp.."*"
  102. end
  103. print("Code : "..hideMdp)
  104. term.setTextColor(colors.yellow)
  105. term.setCursorPos(13,13)
  106. term.setBackgroundColor(colors.red)
  107. print("Annuler")
  108. term.setCursorPos(31,13)
  109. term.setBackgroundColor(colors.lime)
  110. print("Valider")
  111. term.setTextColor(colors.black)
  112. end
  113.  
  114. function drawHistorique(x,y,lignesMax)
  115. for i = 0, lignesMax do
  116. term.setCursorPos(x,y+i)
  117. if historique[#historique-i] == nil then
  118. else
  119. print(historique[#historique-i])
  120. end
  121. end
  122. end
  123.  
  124. function DrawMenuPrincipal()
  125. img = paintutils.loadImage("MenuPrincipal")
  126. paintutils.drawImage(img,1,1)
  127. term.setCursorPos(2,1)
  128. term.setTextColor(colors.yellow)
  129. term.setBackgroundColor(colors.gray)
  130. print("Bienvenue "..psd..", Votre solde : "..solde)
  131. term.setBackgroundColor(colors.lightGray)
  132. term.setCursorPos(15,4)
  133. print("Historique : ")
  134. term.setCursorPos(3,4)
  135. print("Transferer")
  136. term.setCursorPos(3,6)
  137. print("Entreprise")
  138. term.setCursorPos(41,17)
  139. term.setBackgroundColor(colors.red)
  140. print("Quitter")
  141. term.setBackgroundColor(colors.lightGray)
  142. term.setTextColor(colors.yellow)
  143. term.setCursorPos(14,17)
  144. print(" Effacer l'Historique")
  145. term.setBackgroundColor(colors.gray)
  146. term.setTextColor(colors.yellow)
  147. drawHistorique(14,5,10)
  148. end
  149.  
  150. function MenuAff()
  151. if Action == "Connection" then
  152. DrawMenuConnection()
  153. elseif Action == "MenuPrincipal" then
  154. DrawMenuPrincipal()
  155. elseif Action == "MenuTransfers" then
  156. DrawMenuTransfers()
  157. elseif Action == "MenuEntreprise" then
  158. DrawMenuEntreprise()
  159. end
  160. end
  161.  
  162. function startup()
  163. Deconnection()
  164. MenuAff()
  165. while true do
  166. event, p1, p2, p3 = os.pullEvent()
  167. if event == "mouse_click" then
  168. term.setTextColor(colors.black)
  169. print("X:"..p2.." Y:"..p3)
  170. if Action == "Connection" then
  171. if p2 >= 28 and p2 <= 39 and p3 == 13 then
  172. info = {Act="Connection",Pseudo=psd,Mdp=motdepasse}
  173. infos = textutils.serialise(info)
  174. rednet.send(IDTerminal, infos)
  175. elseif p2 >= 20 and p2 <= 39 and p3 == 8 then
  176. function PseudoRead()
  177. psd=""
  178. MenuAff()
  179. term.setCursorPos(21,8)
  180. term.setBackgroundColor(colors.lightGray)
  181. write("")
  182. psd = read()
  183. os.queueEvent("mouse_click",1,0,0)
  184. end
  185. parallel.waitForAll(PseudoRead, unfocusText)
  186. elseif p2 >= 20 and p2 <= 39 and p3 == 11 then
  187. function mdpRead()
  188. motdepasse=""
  189. MenuAff()
  190. term.setCursorPos(21,11)
  191. term.setBackgroundColor(colors.lightGray)
  192. write("")
  193. motdepasse = read("*")
  194. os.queueEvent("mouse_click",1,0,0)
  195. end
  196. parallel.waitForAll(mdpRead,unfocusText)
  197. elseif p2 >= 11 and p2 <= 22 and p3 == 13 then
  198. psd=""
  199. motdepasse=""
  200. CompteValider=false
  201. historique={}
  202. solde=0
  203. sommeTransfer = 0
  204. nomTransfer = ""
  205. MenuAff()
  206. end
  207. elseif Action == "MenuPrincipal" then
  208. if p2 >= 2 and p2 <= 12 and p3 == 4 then
  209. Action = "MenuTransfers"
  210. updateInfo()
  211. elseif p2 >= 2 and p2 <= 12 and p3 == 6 then
  212. Action = "MenuEntreprise"
  213. updateInfo()
  214. elseif p2 >= 14 and p2 <= 34 and p3 == 17 then
  215. info = {Act="EffHistorique",Pseudo=psd}
  216. infos = textutils.serialise(info)
  217. rednet.send(IDTerminal, infos)
  218. elseif p2 >= 40 and p2 <= 48 and p3 == 17 then
  219. Action = "Connection"
  220. Deconnection()
  221. psd=""
  222. motdepasse=""
  223. CompteValider=false
  224. historique = {}
  225. solde = 0
  226. nomTransfer = ""
  227. sommeTransfer = 0
  228. MenuAff()
  229. end
  230. elseif Action == "MenuTransfers" then
  231. if p2 >= 40 and p2 <= 48 and p3 == 17 then
  232. Action = "MenuPrincipal"
  233. updateInfo()
  234. elseif p2 >= 11 and p2 <= 38 and p3 == 3 then
  235. nomTransfer = ""
  236. updateInfo()
  237. function ReadNom()
  238. term.setCursorPos(12,3)
  239. term.setBackgroundColor(colors.lightGray)
  240. term.setTextColor(colors.black)
  241. write("")
  242. nomTransfer = read()
  243. os.queueEvent("mouse_click",1,0,0)
  244. end
  245. parallel.waitForAll(ReadNom,unfocusText)
  246. elseif p2 >= 40 and p2 <= 48 and p3 == 3 then
  247. local nSomme = ""
  248. sommeTransferSave = sommeTransfer
  249. sommeTransfer = ""
  250. updateInfo()
  251. sommeTransfer = sommeTransferSave
  252. function ReadSomme()
  253. term.setCursorPos(40,3)
  254. term.setBackgroundColor(colors.lightGray)
  255. term.setTextColor(colors.black)
  256. write("")
  257. nSomme = read()
  258. os.queueEvent("mouse_click",1,0,0)
  259. end
  260. parallel.waitForAll(ReadSomme,unfocusText)
  261. if tonumber(nSomme) then
  262. sommeTransfer = nSomme + 0
  263. if sommeTransfer+0 > solde+0 then
  264. sommeTransfer = solde+0
  265. end
  266. end
  267. MenuAff()
  268. elseif p2 >= 40 and p2 <= 48 and p3 == 15 then
  269. sommeTransfer= 0
  270. nomTransfer = ""
  271. updateInfo()
  272. elseif p2 >= 40 and p2 <= 48 and p3 == 5 then
  273. info = {Act="Transfer",Proprio=psd,Destinataire=nomTransfer,Somme=sommeTransfer}
  274. infos = textutils.serialise(info)
  275. rednet.send(IDTerminal, infos)
  276. end
  277. end
  278. end
  279. end
  280. end
  281.  
  282. function Reception()
  283. while true do
  284. ID, info = rednet.receive()
  285. print(ID)
  286. if ID == IDTerminal then
  287. infos = textutils.unserialise(info)
  288. if infos.Act == "CompteValide" then
  289. CompteValider=true
  290. Action="MenuPrincipal"
  291. solde = infos.Solde
  292. historique = textutils.unserialise(infos.Historique)
  293. MenuAff()
  294. elseif infos.Act == "CompteNValide" then
  295. CompteValider=false
  296. Action="Connection"
  297. term.setCursorPos(11,15)
  298. term.setTextColor(colors.red)
  299. term.setBackgroundColor(colors.white)
  300. print("Mauvais Pseudo/Mot de passe !")
  301. elseif infos.Act== "Actualiser" then
  302. solde = infos.Solde
  303.  
  304. historique = textutils.unserialise(infos.Historique)
  305. MenuAff()
  306. os.queueEvent("updateInfoReceive")
  307. end
  308. end
  309. end
  310. end
  311.  
  312. function diskEject()
  313. while true do
  314. event, side = os.pullEvent("disk")
  315. disk.eject(side)
  316. end
  317. end
  318.  
  319. parallel.waitForAll(startup,Reception,diskEject)
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement