Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- lang={
- ru={
- rock= "[ камень ]",
- scissors="[ножницы ]",
- paper= "[ бумага ]",
- rock2="камень",
- scissors2="ножницы",
- paper2="бумага",
- win1="выиграл игрок 1: ",
- win2="выиграл игрок 2: ",
- wins="побед: ",
- draw="НИЧЬЯ!!",
- },
- en={
- rock= "[ rock ]",
- scissors="[scissors]",
- paper= "[ paper ]",
- rock="rock",
- scissors="scissors",
- paper="paper",
- win1="WIN player 1: ",
- win2="WIN player 2: ",
- wins="wins: ",
- draw="DRAW!!",
- }
- }
- slang="ru"
- local gpu=require("component").gpu
- local event=require("event")
- require("term").clear()
- local gameCount=2
- local obj={}
- local player={}
- function testClick(self,x,y)
- return (x>=self.x)and(y>=self.y)and(x<self.x+self.w)and(y<self.y+self.h)
- end
- function offObj()
- return false
- end
- function newButton(x,y,w,h,id)
- table.insert(obj,{x=x,y=y,w=w,h=h,isClicked=testClick,id=id})
- end
- function drawPlayer(x,y,id)
- newButton(x,y+1,10,1,id)
- newButton(x,y+2,10,1,id)
- newButton(x,y+3,10,1,id)
- gpu.fill(x,y,10,4," ")
- gpu.set(x,y,player[id].name)
- gpu.set(x,y+1,lang[slang]["rock"])
- gpu.set(x,y+2,lang[slang]["scissors"])
- gpu.set(x,y+3,lang[slang]["paper"])
- gpu.set(x,y+4,lang[slang]["wins"]..player[id].win)
- end
- gpu.setBackground(0x999999)
- gpu.fill(1,1,10,4," ")
- gpu.fill(15,1,10,4," ")
- newButton(1,1,10,4)
- newButton(15,1,10,4)
- isRunning=true
- tmp=2
- while isRunning do
- _,_,x,y,_,name=event.pull("touch")
- for i=1,#obj do
- if obj[i]:isClicked(x,y) then
- player[i]={}
- player[i].name=name
- player[i].bit=-1
- player[i].win=0
- gpu.setBackground(0x009900)
- gpu.fill(obj[i].x,obj[i].y,obj[i].w,obj[i].h," ")
- gpu.set(obj[i].x,obj[i].y,player[i].name)
- obj[i].isClicked=offObj
- tmp=tmp-1
- end
- end
- if tmp==0 then
- isRunning=false
- end
- end
- gpu.setBackground(0x000000)
- --os.exit()
- --for _=1,gameCount do
- while (player[1].win~=2)and(player[2].win~=2) do
- obj={}
- require("term").clear()
- drawPlayer(1,1,1)
- drawPlayer(15,1,2)
- isRunning=true
- tmp=0
- while isRunning do
- _,_,x,y,_,name=event.pull("touch")
- for i=1,#obj do
- if obj[i]:isClicked(x,y) then
- --print(i,obj[i].id)
- if name==player[obj[i].id].name then
- tmp=tmp+1
- -- gpu.set(149,49,i.."")
- pos=(i-1)%3+1
- player[obj[i].id].bit=pos
- pos=math.floor((i-1)/3)
- if pos==0 then
- gpu.fill(1,2,10,3," ")
- else
- gpu.fill(15,2,10,3," ")
- end
- obj[pos*3+1].isClicked=offObj;obj[pos*3+2].isClicked=offObj;obj[pos*3+3].isClicked=offObj
- end
- end
- end
- if tmp==2 then
- isRunning=false
- end
- end
- --print(player[1].bit,player[2].bit)
- require("term").clear()
- if player[1].bit==player[2].bit then
- print(lang[slang]["draw"])
- --elseif ((player[1].bit==1)and(player[2].bit==2))or((player[1].bit==2)and(player[1])
- elseif (player[1].bit==player[2].bit-1)or(player[1].bit==player[2].bit+2)then
- print(lang[slang]["win1"]..player[1].name)
- player[1].win=player[1].win+1
- else
- print(lang[slang]["win2"]..player[2].name)
- player[2].win=player[2].win+1
- end
- ms={lang[slang]["rock2"],lang[slang]["scissors2"],lang[slang]["paper2"]}
- print(ms[player[1].bit],ms[player[2].bit])
- event.pull("key_down")
- end
- if player[1].win>player[2].win then
- io.write(lang[slang]["win1"])
- else
- io.write(lang[slang]["win2"])
- end
- io.write(player[1].win.." VS "..player[2].win)
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement