Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- local com = require("component")
- local gpu = com.gpu
- local term = require("term")
- local color = require("colors")
- local comp = require("computer")
- local kb = require("keyboard")
- local OldW,OldH = gpu.getResolution()
- local OldB = gpu.getBackground()
- local OldF = gpu.getForeground()
- term.clear()
- gpu.setBackground(color.black,true)
- gpu.setForeground(color.white,true)
- gpu.setResolution(10,5)
- gpu.fill(3,2,6,3," ")
- function textbox(xPos,yPos,text)
- term.setCursor(xPos,yPos)
- term.write(text)
- end
- ::Again::
- --Переменные--
- local Steps = {}
- local PS = "X"
- local BS = "O"
- local SD = false
- gpu.setBackground(0x000000)
- gpu.setForeground(0xFFFFFF)
- term.clear()
- gpu.setBackground(0x008705)
- gpu.fill(1,5,2,1," ")
- gpu.setBackground(0xa31800)
- gpu.fill(9,5,2,1," ")
- gpu.setBackground(0xFFFFFF)
- gpu.setForeground(0x000000)
- gpu.fill(3,2,6,3," ")
- ::Single::
- while true do
- local typeT,_,x,y,button,nick = comp.pullSignal(0,"touch")
- --ВЫИГРЫШ ИГРОКА--
- --Диагональ--
- if Steps[1] == PS and Steps[5] == PS and Steps[9] == PS then
- gpu.setBackground(0x008705)
- gpu.fill(3,2,2,1," ")
- gpu.fill(5,3,2,1," ")
- gpu.fill(7,4,2,1," ")
- goto Wait
- end
- if Steps[3] == PS and Steps[5] == PS and Steps[7] == PS then
- gpu.setBackground(0x008705)
- gpu.fill(7,2,2,1," ")
- gpu.fill(5,3,2,1," ")
- gpu.fill(3,4,2,1," ")
- goto Wait
- end
- --Горизонталь--
- if Steps[1] == PS and Steps[2] == PS and Steps[3] == PS then
- gpu.setBackground(0x008705)
- gpu.fill(3,2,2,1," ")
- gpu.fill(5,2,2,1," ")
- gpu.fill(7,2,2,1," ")
- goto Wait
- end
- if Steps[4] == PS and Steps[5] == PS and Steps[6] == PS then
- gpu.setBackground(0x008705)
- gpu.fill(3,3,2,1," ")
- gpu.fill(5,3,2,1," ")
- gpu.fill(7,3,2,1," ")
- goto Wait
- end
- if Steps[7] == PS and Steps[8] == PS and Steps[9] == PS then
- gpu.setBackground(0x008705)
- gpu.fill(3,4,2,1," ")
- gpu.fill(5,4,2,1," ")
- gpu.fill(7,4,2,1," ")
- goto Wait
- end
- --Вертикаль--
- if Steps[1] == PS and Steps[4] == PS and Steps[7] == PS then
- gpu.setBackground(0x008705)
- gpu.fill(3,2,2,1," ")
- gpu.fill(3,3,2,1," ")
- gpu.fill(3,4,2,1," ")
- goto Wait
- end
- if Steps[2] == PS and Steps[5] == PS and Steps[8] == PS then
- gpu.setBackground(0x008705)
- gpu.fill(5,2,2,1," ")
- gpu.fill(5,3,2,1," ")
- gpu.fill(5,4,2,1," ")
- goto Wait
- end
- if Steps[3] == PS and Steps[6] == PS and Steps[9] == PS then
- gpu.setBackground(0x008705)
- gpu.fill(7,2,2,1," ")
- gpu.fill(7,3,2,1," ")
- gpu.fill(7,4,2,1," ")
- goto Wait
- end
- --ВЫИГРЫШ БОТА--
- --Диагональ--
- if Steps[1] == BS and Steps[5] == BS and Steps[9] == BS then
- gpu.setBackground(0xa31800)
- gpu.fill(3,2,2,1," ")
- gpu.fill(5,3,2,1," ")
- gpu.fill(7,4,2,1," ")
- goto Wait
- end
- if Steps[3] == BS and Steps[5] == BS and Steps[7] == BS then
- gpu.setBackground(0xa31800)
- gpu.fill(7,2,2,1," ")
- gpu.fill(5,3,2,1," ")
- gpu.fill(3,4,2,1," ")
- goto Wait
- end
- --Горизонталь--
- if Steps[1] == BS and Steps[2] == BS and Steps[3] == BS then
- gpu.setBackground(0xa31800)
- gpu.fill(3,2,2,1," ")
- gpu.fill(5,2,2,1," ")
- gpu.fill(7,2,2,1," ")
- goto Wait
- end
- if Steps[4] == BS and Steps[5] == BS and Steps[6] == BS then
- gpu.setBackground(0xa31800)
- gpu.fill(3,3,2,1," ")
- gpu.fill(5,3,2,1," ")
- gpu.fill(7,3,2,1," ")
- goto Wait
- end
- if Steps[7] == BS and Steps[8] == BS and Steps[9] == BS then
- gpu.setBackground(0xa31800)
- gpu.fill(3,4,2,1," ")
- gpu.fill(5,4,2,1," ")
- gpu.fill(7,4,2,1," ")
- goto Wait
- end
- --Вертикаль--
- if Steps[1] == BS and Steps[4] == BS and Steps[7] == BS then
- gpu.setBackground(0xa31800)
- gpu.fill(3,2,2,1," ")
- gpu.fill(3,3,2,1," ")
- gpu.fill(3,4,2,1," ")
- goto Wait
- end
- if Steps[2] == BS and Steps[5] == BS and Steps[8] == BS then
- gpu.setBackground(0xa31800)
- gpu.fill(5,2,2,1," ")
- gpu.fill(5,3,2,1," ")
- gpu.fill(5,4,2,1," ")
- goto Wait
- end
- if Steps[3] == BS and Steps[6] == BS and Steps[9] == BS then
- gpu.setBackground(0xa31800)
- gpu.fill(7,2,2,1," ")
- gpu.fill(7,3,2,1," ")
- gpu.fill(7,4,2,1," ")
- goto Wait
- end
- if typeT == "touch" then
- Steps[1] = gpu.get(3,2) --Первая строка
- Steps[2] = gpu.get(5,2)
- Steps[3] = gpu.get(7,2)
- Steps[4] = gpu.get(3,3) --Вторая строка
- Steps[5] = gpu.get(5,3)
- Steps[6] = gpu.get(7,3)
- Steps[7] = gpu.get(3,4) --Третья строка
- Steps[8] = gpu.get(5,4)
- Steps[9] = gpu.get(7,4)
- --Выход--
- if x >= 9 and x < 11 and y == 5 then
- goto Exit
- end
- --Заного--
- if x >= 1 and x < 3 and y == 5 then
- goto Again
- end
- --Ход игрока--
- if x >= 3 and x < 5 and y == 2 then
- if Steps[1] ~= BS then
- textbox(3,2,PS)
- SD = true
- end
- elseif x >= 5 and x < 7 and y == 2 then
- if Steps[2] ~= BS then
- textbox(5,2,PS)
- SD = true
- end
- elseif x >= 7 and x < 9 and y == 2 then
- if Steps[3] ~= BS then
- textbox(7,2,PS)
- SD = true
- end
- elseif x >= 3 and x < 5 and y == 3 then --Вторая строка
- if Steps[4] ~= BS then
- textbox(3,3,PS)
- SD = true
- end
- elseif x >= 5 and x < 7 and y == 3 then
- if Steps[5] ~= BS then
- textbox(5,3,PS)
- SD = true
- end
- elseif x >= 7 and x < 9 and y == 3 then
- if Steps[6] ~= BS then
- textbox(7,3,PS)
- SD = true
- end
- elseif x >= 3 and x < 5 and y == 4 then --Третья строка
- if Steps[7] ~= BS then
- textbox(3,4,PS)
- SD = true
- end
- elseif x >= 5 and x < 7 and y == 4 then
- if Steps[8] ~= BS then
- textbox(5,4,PS)
- SD = true
- end
- elseif x >= 7 and x < 9 and y == 4 then
- if Steps[9] ~= BS then
- textbox(7,4,PS)
- SD = true
- end
- end
- --Ход бота--
- local botStep = math.random(1,9)
- if SD then
- SD = false
- for i = 1,9 do
- if Steps[botStep] == " " then
- if botStep == 1 then
- textbox(3,2,BS)
- break
- elseif botStep == 2 then
- textbox(5,2,BS)
- break
- elseif botStep == 3 then
- textbox(7,2,BS)
- break
- elseif botStep == 4 then
- textbox(3,3,BS)
- break
- elseif botStep == 5 then
- textbox(5,3,BS)
- break
- elseif botStep == 6 then
- textbox(7,3,BS)
- break
- elseif botStep == 7 then
- textbox(3,4,BS)
- break
- elseif botStep == 8 then
- textbox(5,4,BS)
- break
- elseif botStep == 9 then
- textbox(7,4,BS)
- break
- end
- else
- botStep = math.random(1,9)
- end
- end
- end
- end
- end
- ::Wait::
- while true do
- local typeT,_,x,y,button,nick = comp.pullSignal(0,"touch")
- if typeT == "touch" then
- if x >= 1 and x < 3 and y == 5 then
- goto Again
- end
- if x >= 9 and x < 11 and y == 5 then
- break
- end
- end
- end
- ::Exit::
- gpu.setBackground(OldB,false)
- gpu.setForeground(OldF,false)
- gpu.setResolution(OldW,OldH)
- term.clear()
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement