Advertisement
Guest User

Tic Tac Mouse v. 1.3

a guest
Feb 20th, 2014
69
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Lua 5.39 KB | None | 0 0
  1. function start()
  2.  -- Jeu complet (modérateur, joueurs au hasard, etc.) --
  3.  
  4.  modo = "Pseudo"
  5.  texteg = "Tu es le joueur qui jouera avec les"
  6.  wintxt = "Le gagnant de cette partie est"
  7.  t = -0.5 -- Ne touchez pas !
  8.  tfm.exec.setGameTime (900, init)
  9.  version = "v. 1.3"
  10.  joueur_tourX = true
  11.  joueur_tourO = false
  12.  joueurs = {}
  13.  for name, pseudo in pairs(tfm.get.room.playerList) do
  14.   table.insert(joueurs, name)
  15.  end
  16.  
  17.  if joueurs[2] == nil then
  18.   print("<R>Vous êtes seul, vous ne pouvez pas jouer, désolé.")
  19.  else
  20.   joueur_hasardX = joueurs[math.random(#joueurs)]
  21.   joueur_hasardO = joueurs[math.random(#joueurs)]
  22.   game = {}
  23.   ui.addTextArea (0, "<p align='center'>"..texteg.." X </p", ""..joueur_hasardX.."",  13, 21, 776, 17, 0x000001, 0xffffff, 1.0, true)
  24.   ui.addTextArea (0, "<p align='center'>"..texteg.." O </p", ""..joueur_hasardO.."",  13, 21, 776, 17, 0x000001, 0xffffff, 1.0, true)
  25.   ui.addTextArea (1, "O", nil,  268, 103, 146, 146, 0xffffff, 0xffffff, 1.0, true)
  26.   ui.addTextArea (2, "<P align='center'>-- Tic Tac Mousse by Izzeberg --<br>-- "..version.." --<br> C'est le joueur avec les X qui commence !<br>"..joueur_hasardO.."(O) vs "..joueur_hasardX.."(X) <P>", nil, 514, 70, 197, 70, 0x000001, 0xffffff, 1.0, true)
  27.   ui.addTextArea(3, "<P align='center'><a href ='event:osco'>Nouvelle partie </a>", nil, 15, 375, 100, 19, 0x000001, 0xffffff, 1.0, true)
  28.   ui.addTextArea(110, "<br><a href='event:1c'>    .   </a>", nil, 268, 103, 42, 42, 0x000001, 0xffffff, 1.0, true)
  29.   ui.addTextArea(120, "<br><a href='event:2c'>    .   </a>", nil, 320, 103, 42, 42, 0x000001, 0xffffff, 1.0, true)
  30.   ui.addTextArea(130, "<br><a href='event:3c'>    .   </a>", nil, 372, 103, 42, 42, 0x000001, 0xffffff, 1.0, true)
  31.   ui.addTextArea(140, "<br><a href='event:4c'>    .   </a>", nil, 268, 155, 42, 42, 0x000001, 0xffffff, 1.0, true)
  32.   ui.addTextArea(150, "<br><a href='event:5c'>    .   </a>", nil, 320, 155, 42, 42, 0x000001, 0xffffff, 1.0, true)
  33.   ui.addTextArea(160, "<br><a href='event:6c'>    .   </a>", nil, 372, 155, 42, 42, 0x000001, 0xffffff, 1.0, true)
  34.   ui.addTextArea(170, "<br><a href='event:7c'>    .   </a>", nil, 268, 207, 42, 42, 0x000001, 0xffffff, 1.0, true)
  35.   ui.addTextArea(180, "<br><a href='event:8c'>    .   </a>", nil, 320, 207, 42, 42, 0x000001, 0xffffff, 1.0, true)
  36.   ui.addTextArea(190, "<br><a href='event:9c'>    .   </a>", nil, 372, 207, 42, 42, 0x000001, 0xffffff, 1.0, true)
  37.   samePlayerVerify()
  38.  end
  39. end
  40.  
  41. function click(textAreaId, name, x, y, other)
  42.  if name == joueur_hasardX then
  43.   if joueur_tourX == true then
  44.    game[other] = "X"
  45.    ui.addTextArea(textAreaId, "<br>    X   ", nil, x, y, 42, 42, 0x000001, 0xffffff, 1.0, true)
  46.    joueur_tourX = false
  47.    joueur_tourO = true
  48.    gameVerify()
  49.   end
  50.  elseif name == joueur_hasardO then
  51.   if joueur_tourO == true then
  52.    game[other] = "O"
  53.    ui.addTextArea(textAreaId, "<br>    O   ", nil, x, y, 42, 42, 0x000001, 0xffffff, 1.0, true)
  54.    joueur_tourO = false
  55.    joueur_tourX = true
  56.    gameVerify()
  57.   end
  58.  end
  59. end
  60.  
  61. function samePlayerVerify()
  62.  if joueur_hasardO == joueur_hasardX then
  63.   start()
  64.  end
  65. end
  66.  
  67. function eventTextAreaCallback(textAreaId, name, callback)
  68.  if callback == "1c" then
  69.   click(110,name,268,103,1)
  70.  elseif callback == "2c" then
  71.   click(120,name,320,103,2)
  72.  elseif callback == "3c" then
  73.   click(130,name,372,103,3)
  74.  elseif callback == "4c" then
  75.   click(140,name,268,155,4)
  76.  elseif callback == "5c" then
  77.   click(150,name,320,155,5)
  78.  elseif callback == "6c" then
  79.   click(160,name,372,155,6)
  80.  elseif callback == "7c" then
  81.   click(170,name,268,207,7)
  82.  elseif callback == "8c" then
  83.   click(180,name,320,207,8)
  84.  elseif callback == "9c" then
  85.   click(190,name,372,207,9)
  86.  elseif callback == "osco" then
  87.   if name == ""..modo.."" then
  88.   start()
  89.   end
  90.  end
  91. end
  92.  
  93. function gameVerify()
  94.  for other,nb in pairs({1,2,3,4,5,6,7,8,9}) do
  95.   if game[other] == nil then
  96.   else
  97.    gameVerify2("X")
  98.    gameVerify2("O")
  99.   end
  100.  end
  101. end
  102.  
  103. function gameVerify2(value)
  104.  if game[1] == value and game[2] == value and game[3] == value then
  105.   win(value)
  106.  elseif game[4] == value and game[5] == value and game[6] == value then
  107.   win(value)
  108.  elseif game[7] == value and game[8] == value and game[9] == value then
  109.   win(value)
  110.  elseif game[1] == value and game[4] == value and game[7] == value then
  111.   win(value)
  112.  elseif game[2] == value and game[5] == value and game[8] == value then
  113.   win(value)
  114.  elseif game[3] == value and game[6] == value and game[9] == value then
  115.   win(value)
  116.  elseif game[1] == value and game[5] == value and game[9] == value then
  117.   win(value)
  118.  elseif game[3] == value and game[5] == value and game[7] == value then
  119.   win(value)
  120.  else
  121.   if win == false then
  122.    win("nul")
  123.   end
  124.  end
  125. end
  126.  
  127. function win(value)
  128.  if value == "X" then
  129.   win = true
  130.   ui.addTextArea (0, "<font color='#000000'><p align='center'>"..wintxt.." "..joueur_hasardX.."</p>", nil,  13, 21, 776, 17, 0xffff00, 0x000001, 1.0, true)
  131.   t = 10.5
  132.  elseif value == "O" then
  133.   win = true
  134.   ui.addTextArea (0, "<font color='#000000'><p align='center'>"..wintxt.." "..joueur_hasardO.."</p>", nil,  13, 21, 776, 17, 0xffff00, 0x000001, 1.0, true)
  135.   t = 10.5
  136.  elseif value == "nul" then
  137.   ui.addTextArea (0, "<font color='#000000'><p align='center'>Partie nul</p>", nil,  13, 21, 776, 17, 0xffff00, 0x000001, 1.0, true)
  138.   t = 10.5
  139.  end
  140. end
  141.  
  142. function eventLoop()
  143.  t = t - 0.5
  144.  if t == 0.5 then
  145.   start()
  146.  end
  147. end
  148.  
  149. start()
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement