Advertisement
nRikee

[Kata] PiedraPapelTijerasLagartoSpock

Jan 21st, 2014
82
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Lua 1.99 KB | None | 0 0
  1. --[[----------------------------------------------
  2.             Vocabulary and logic
  3. ----------------------------------------------]]--
  4. voc = { 'piedra', 'papel', 'tijeras', 'lagarto', 'spock' }
  5. who =
  6.     {
  7.         tijeras = { papel   = 'Tijeras cortan papel',
  8.                     lagarto = 'Tijeras decapitan al lagarto'},
  9.         papel   = { piedra  = 'Papel cubre a piedra',
  10.             spock   = 'Papel desautoriza a Spock'},
  11.         piedra  = { lagarto = 'Piedra aplasta a lagarto',
  12.                     tijeras = 'Piedra aplasta las tijeras'},
  13.         lagarto = { spock   = 'Lagarto envenena a Spock',
  14.                     papel   = 'Lagarto se come el papel'},
  15.         spock   = { tijeras = 'Spock destroza las tijeras',
  16.                     piedra  = 'Spock vaporiza la piedra'}
  17.     }
  18.  
  19. --[[----------------------------------------------
  20.             Main activity
  21. ----------------------------------------------]]--
  22. math.randomseed( os.time() )
  23. print ( 'Choose one: \n'    ..
  24.             '\tPiedra\n'    ..
  25.             '\tPapel\n'     ..
  26.             '\tTijeras\n'   ..
  27.             '\tLagarto\n'   ..
  28.             '\tSpock' )
  29.  
  30. user    = string.lower  ( io.read( '*line' ) )
  31. cpu     = math.random   ( 0, 4 )
  32. cpu     = voc [ cpu ]
  33.  
  34. if user == cpu then
  35.     print 'Empate'
  36. else
  37.     if who [ cpu ][ user ] ~= nil then
  38.         print ( who [ cpu ] [ user ] )
  39.     else
  40.         print ( who [ user ] [ cpu ] )
  41.     end
  42. end
  43.  
  44. --[[----------------------------------------------
  45.     How to read from console:
  46. --------------------------------------------------
  47.     var = io.read ( arg ) -- where arg is:
  48.     "*all"      reads the whole file
  49.     "*line"     reads the next line
  50.     "*number"   reads a number
  51.     num         reads a string with up to num characters
  52. ----------------------------------------------]]--
  53.  
  54. --[[----------------------------------------------
  55.     Random number:
  56. --------------------------------------------------
  57.     math.randomseed ( arg )
  58.     math.random     ( min, max )
  59.     -- arg is the seed
  60. ----------------------------------------------]]--
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement