local mapa = { 0, 0, 0, 0, 0, 0, 0, 0, 0 } do local d = {'AutoShaman', 'AutoNewGame', 'AutoTimeLeft', 'AfkDeath', 'AutoScore'} for i=1, #d do tfm.exec['disable'..d[i]]() end end local xml = [[

]] --[[0 = vazio, 1 = xis, 2 = bolinha]] local jogadores = {} --são 2 jogadores setmetatable(jogadores, {__index = function() return '[ espaço ]' end}) --quem começa? aleatório? nem xis nem bolinha deve começar por padrão --divisão por fases --[[ 1 = escolha de jogadores 2 = jogada 3 = checar jogada 4 = fim ]] eventPlayerDied = tfm.exec.respawnPlayer local checarGanhador = function() --jogador 1 (x) for i=1, #mapa do if i/3 == math.abs(i/3) then if mapa[i] == 1 and mapa[i+1] == 1 and mapa[i+2] == 1 then return 1 end end if mapa[i] == 1 and mapa[i+3] == 1 and mapa[i+6] == 1 then return 1 end if i == 1 then if mapa[i] == 1 and mapa[i+4] == 1 and mapa[i+8] == 1 then return 1 end end if i == 7 then if mapa[i] == 1 and mapa[i-2] == 1 and mapa[i-4] == 1 then return 1 end end end --jogador 2 (o) for i=1, #mapa do if i/3 == math.abs(i/3) then if mapa[i] == 2 and mapa[i+1] == 2 and mapa[i+2] == 2 then return 2 end end if mapa[i] == 2 and mapa[i+3] == 2 and mapa[i+6] == 2 then return 2 end if i == 1 then if mapa[i] == 2 and mapa[i+4] == 2 and mapa[i+8] == 2 then return 2 end end if i == 7 then if mapa[i] == 2 and mapa[i-2] == 2 and mapa[i-4] == 2 then return 2 end end end return false end local analisarJogador = function(n) end ui.addTextArea(-1, '', nil, 400-110, 185-110, 220, 220, -1, -1) for i=1, 3 do ui.addTextArea(i, (''):format(tostring(i)), nil, 400-170+(80*i), 185-130+40, 20, 20, -1, -1) end for i=1, 3 do ui.addTextArea(i+3, (''):format(tostring(i+3)), nil, 400-170+(80*i), 185-130+120, 20, 20, -1, -1) end for i=1, 3 do ui.addTextArea(i+6, (''):format(tostring(i+6)), nil, 400-170+(80*i), 185-130+200, 20, 20, -1, -1) end local vez = 1 local corDaJogada = function() if vez == 1 then return 0xFF9999 else return 0x9999FF end end local u eventTextAreaCallback = function(id, p, n) if p == u or mapa[tonumber(id)] ~= 0 or p ~= jogadores[vez] then return end ui.addTextArea(id, '?', nil, 9999, 99999, 20, 20, -1, -1) if tonumber(id) < 4 then ui.addTextArea(id, (vez == 1 and 'X' or 'O'), nil, 400-170+(80*id), 185-130+40, 20, 20, corDaJogada(), corDaJogada(), 1) elseif tonumber(id) < 7 then ui.addTextArea(id, (vez == 1 and 'X' or 'O'), nil, 400-170+(80*(id-3)), 185-130+120, 20, 20, corDaJogada(), corDaJogada(), 1) else ui.addTextArea(id, (vez == 1 and 'X' or 'O'), nil, 400-170+(80*(id-6)), 185-130+200, 20, 20, corDaJogada(), corDaJogada(), 1) end mapa[tonumber(id)] = vez if vez == 1 then vez = 2 else vez = 1 end u = p print(checarGanhador()) end tfm.exec.newGame(xml) ui.setMapName('Velha 2') corDeEspaco = 'BABD2F' local makeMap = function(p) ui.addTextArea(11, ("

%s"):format(jogadores[1]), p, 73-50, 360, 100, 20, nil, nil, 0, false) ui.addTextArea(12, ("

%s"):format(jogadores[2]), p, 725-50, 360, 100, 20, nil, nil, 0, false) end local analisarJogador = function(p) makeMap(p) system.bindKeyboard(p, 32, true, true) end for k in next, tfm.get.room.playerList do analisarJogador(k) end makeMap() eventKeyboard = function(p, k, _, x) if x < 103 and x > 47 and jogadores[1] == '[ espaço ]' and p ~= jogadores[2] then jogadores[1] = p makeMap() end if x < 758 and x > 688 and jogadores[2] == '[ espaço ]' and p ~= jogadores[1] then jogadores[2] = p makeMap() end end