Advertisement
Guest User

game

a guest
Aug 2nd, 2015
236
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Lua 3.30 KB | None | 0 0
  1. local term = require("term")
  2. local io = require("io")
  3. local thread = require("thread")
  4. local fs = require("filesystem")
  5.  
  6. MestoN1 = "test   "  
  7. MestoO1 = 10
  8. MestoN2 = "Test   "
  9. MestoO2 = 8
  10. MestoN3 = "teSt   "
  11. MestoO3 = 6
  12. MestoN4 = "tesT   "
  13. MestoO4 = 4
  14. MestoN5 = "tEst   "
  15. MestoO5 = 2
  16.  
  17. function TRecord()
  18.  
  19.   term.clear()
  20.  
  21.   print('  <Таблица рекордов> \n')
  22.   print('Место |   Имя   | Результат')
  23.   print('  1.  |'..MestoN1.."  |  "..MestoO1)
  24.   print('  2.  |'..MestoN2.."  |  "..MestoO2)
  25.   print('  3.  |'..MestoN3.."  |  "..MestoO3)
  26.   print('  4.  |'..MestoN4.."  |  "..MestoO4)
  27.   print('  5.  |'..MestoN5.."  |  "..MestoO5)
  28.   print("Нажмите Enter для выхода в меню")
  29.   io.read()
  30.   term.clear()
  31.   MMenu()
  32. end
  33.  
  34. function Timer()
  35.   os.sleep(1)
  36.   if t ~= 0 then
  37.     t=t-1
  38.     Timer()
  39.   end
  40. end
  41.  
  42. function Game()
  43.   term.clear()
  44.   x = "random"
  45.   t = 5
  46.  
  47.   thread.init()
  48.   print('Уровень: '..lvl+1)
  49.   --print('Осталось '..t..' секунд')
  50.  
  51.   print('Наберите: '..x)
  52.   thread.create (Timer)
  53.   local y = io.read()
  54.   thread.killAll()
  55.  
  56.   if t == 0 then
  57.     term.clear()
  58.     print('Время истекло')
  59.     os.sleep(2)
  60.     POchki()
  61.   elseif x == y then
  62.     print('Поздравляю!\nСледующий уровень')
  63.     lvl = lvl+1
  64.     os.sleep(1)
  65.     Game()
  66.   else
  67.     term.clear()
  68.     print('Увы, вы проиграли на уровне '..lvl+1)
  69.     os.sleep(2)
  70.     POchki()
  71.   end
  72. end
  73.  
  74. function POchki()
  75.   if lvl < MestoO5 then
  76.     MMenu()
  77.   elseif lvl < MestoO4 then
  78.     print('Поздравляю вы заняли 5ое место!')
  79.     print('Введите свой ник:')
  80.     --MestoN5 = io.read(7)
  81.     local file = io.open("games.txt","w")
  82.     --file:seek("set(7,11)")
  83.     file:write(lvl)
  84.     file:close("games.txt")  
  85.     MMenu()
  86.   elseif lvl < MestoO3 then
  87.     print('Поздравляю вы заняи 4ое место!')
  88.     print('Введите свой ник:')
  89.     io.read(7)
  90.     MMenu()
  91.   elseif lvl < MestoO2 then
  92.     print('Поздравляю вы заняли 3е место!')
  93.     print('Введите свой ник:')
  94.     io.read(7)
  95.     MMenu()
  96.   elseif lvl < MestoO1 then
  97.     print('Поздравляю вы заняли 2ое место!')
  98.     print('Введите свой ник:')  
  99.     io.read(7)
  100.     MMenu()
  101.   else
  102.     print('Поздравляю вы заняли 1ое место!')
  103.     print('Введите свой ник:')
  104.     io.read(7)
  105.     MMenu()
  106.   end    
  107. end
  108.  
  109. function MMenu()
  110.   term.clear()
  111.   print ('  <Главное меню>\n [1] Новая игра\n [2] Таблица рекордов\n [3] Описание\n [4] Выход\n\n')
  112.  
  113.   a = io.read()
  114.  
  115.   if a == "1" then
  116.     print('Start Game!')
  117.     lvl =0
  118.     Game()
  119.   elseif a == "2" then
  120.     TRecord()
  121.   elseif a == "3" then
  122.     term.clear()
  123.     print('     <Описание>\nЗа отведенное время надо\nуспеть ввести нужный\nнабор символом, при успехе,\nвы перейдете на следующий\nуровень.')
  124.     io.read()
  125.     MMenu()
  126.   elseif a == "4" then
  127.     term.clear()
  128.     print("Спасибо за игру")
  129.     os.sleep(1)
  130.     term.clear()
  131.     os.exit()
  132.   else
  133.     term.clear()
  134.     print('Выберите один из пунктов (ввод цифры):')
  135.     MMenu()
  136.   end
  137. end
  138. MMenu()
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement