SHOW:
|
|
- or go back to the newest paste.
1 | - | bground=0x292929 |
1 | + | bground=0x292929 |
2 | - | player1Pos={1,1} |
2 | + | player1Pos={1,1} |
3 | - | player2Pos={1,15} |
3 | + | player2Pos={1,15} |
4 | - | colorDraw=0xffff00 |
4 | + | colorDraw=0xffff00 |
5 | - | colorWin=0x00aa00 |
5 | + | colorWin=0x00aa00 |
6 | - | colorLose=0xff0000 |
6 | + | colorLose=0xff0000 |
7 | - | |
7 | + | |
8 | - | lang={ |
8 | + | lang={ |
9 | - | ru={ |
9 | + | ru={ |
10 | - | rock= "[ камень ]", |
10 | + | rock= "[ камень ]", |
11 | - | scissors="[ножницы ]", |
11 | + | scissors="[ножницы ]", |
12 | - | paper= "[ бумага ]", |
12 | + | paper= "[ бумага ]", |
13 | - | rock2="камень", |
13 | + | rock2="камень", |
14 | - | scissors2="ножницы", |
14 | + | scissors2="ножницы", |
15 | - | paper2="бумага", |
15 | + | paper2="бумага", |
16 | - | win1="выиграл игрок 1: ", |
16 | + | win1="выиграл игрок 1: ", |
17 | - | win2="выиграл игрок 2: ", |
17 | + | win2="выиграл игрок 2: ", |
18 | - | wins="побед: ", |
18 | + | wins="побед: ", |
19 | - | draw="НИЧЬЯ!!", |
19 | + | draw="НИЧЬЯ!!", |
20 | - | }, |
20 | + | }, |
21 | - | en={ |
21 | + | en={ |
22 | - | rock= "[ rock ]", |
22 | + | rock= "[ rock ]", |
23 | - | scissors="[scissors]", |
23 | + | scissors="[scissors]", |
24 | - | paper= "[ paper ]", |
24 | + | paper= "[ paper ]", |
25 | - | rock="rock", |
25 | + | rock="rock", |
26 | - | scissors="scissors", |
26 | + | scissors="scissors", |
27 | - | paper="paper", |
27 | + | paper="paper", |
28 | - | win1="WIN player 1: ", |
28 | + | win1="WIN player 1: ", |
29 | - | win2="WIN player 2: ", |
29 | + | win2="WIN player 2: ", |
30 | - | wins="wins: ", |
30 | + | wins="wins: ", |
31 | - | draw="DRAW!!", |
31 | + | draw="DRAW!!", |
32 | - | } |
32 | + | } |
33 | - | } |
33 | + | } |
34 | - | slang="ru" |
34 | + | slang="en" |
35 | - | char={ |
35 | + | char={ |
36 | - | f="█", --full |
36 | + | f="█", --full |
37 | - | d="▄", --down |
37 | + | d="▄", --down |
38 | - | u="▀", --up |
38 | + | u="▀", --up |
39 | - | } |
39 | + | } |
40 | - | |
40 | + | |
41 | - | tex={ |
41 | + | --------------------------------------------- |
42 | - | rock={--symbol fore back |
42 | + | local gpu=require("component").gpu |
43 | - | " ▄▄ ", |
43 | + | function centerText(x,y,w,text) |
44 | - | " ▄█████ ", |
44 | + | gpu.set(x+math.floor(w/2-string.len(text)/2),y,text) |
45 | - | " ▄███████ ", |
45 | + | end |
46 | - | " ▀██████▀ ", |
46 | + | |
47 | - | " ▀▀▀▀ ", |
47 | + | function messageBox(title,text,color) |
48 | - | }, |
48 | + | local x,y=6,7 |
49 | - | paper={ |
49 | + | local len1,len2=string.len(title),string.len(text) |
50 | - | " ▄ ", |
50 | + | local len3=math.max(len1,len2)+2 |
51 | - | " ▄███▄ ", |
51 | + | gpu.setBackground(0xffffff) |
52 | - | " ▄██████▀ ", |
52 | + | gpu.fill(x,y,len3,2+3," ") |
53 | - | " ▀███▀ ", |
53 | + | gpu.setForeground(color or 0xFF0000) |
54 | - | " ▀ ", |
54 | + | centerText(x,y+1,len3,title) |
55 | - | }, |
55 | + | gpu.setForeground(0x000000) |
56 | - | scissors={ |
56 | + | centerText(x,y+3,len3,text) |
57 | - | " ▄▄ ▄▄ ", |
57 | + | gpu.setBackground(color or 0xFF0000) |
58 | - | " ▀█▄▄█▀ ", |
58 | + | gpu.setForeground(0xffffff) |
59 | - | " ▄▄██▄▄ ", |
59 | + | gpu.fill(x,y+5,len3,3," ") |
60 | - | " █ ██ █ ", |
60 | + | centerText(x,y+6,len3,"OK!") |
61 | - | " ▀▀ ▀▀ ", |
61 | + | end |
62 | - | } |
62 | + | --------------------------------------------- |
63 | - | } |
63 | + | |
64 | - | tcol={ |
64 | + | tex={ |
65 | - | rock=0x555555, |
65 | + | rock={--symbol fore back |
66 | - | paper=0xf9f9f9, |
66 | + | " ▄▄ ", |
67 | - | scissors=0x888888, |
67 | + | " ▄█████ ", |
68 | - | scissors2=0x555500, |
68 | + | " ▄███████ ", |
69 | - | } |
69 | + | " ▀██████▀ ", |
70 | - | |
70 | + | " ▀▀▀▀ ", |
71 | - | local gpu=require("component").gpu |
71 | + | }, |
72 | - | local event=require("event") |
72 | + | paper={ |
73 | - | require("term").clear() |
73 | + | " ▄ ", |
74 | - | |
74 | + | " ▄███▄ ", |
75 | - | local gameCount=2 |
75 | + | " ▄██████▀ ", |
76 | - | local obj={} |
76 | + | " ▀███▀ ", |
77 | - | local player={} |
77 | + | " ▀ ", |
78 | - | |
78 | + | }, |
79 | - | function testClick(self,x,y) |
79 | + | scissors={ |
80 | - | return (x>=self.x)and(y>=self.y)and(x<self.x+self.w)and(y<self.y+self.h) |
80 | + | " ▄▄ ▄▄ ", |
81 | - | end |
81 | + | " ▀█▄▄█▀ ", |
82 | - | |
82 | + | " ▄▄██▄▄ ", |
83 | - | function offObj() |
83 | + | " █ ██ █ ", |
84 | - | return false |
84 | + | " ▀▀ ▀▀ ", |
85 | - | end |
85 | + | } |
86 | - | |
86 | + | } |
87 | - | function newButton(x,y,w,h,id,type) |
87 | + | tcol={ |
88 | - | table.insert(obj,{x=x,y=y,w=w,h=h,isClicked=testClick,id=id,type=type}) |
88 | + | rock=0x555555, |
89 | - | end |
89 | + | paper=0xf9f9f9, |
90 | - | |
90 | + | scissors=0x888888, |
91 | - | function drawImage(x,y,texture,bground) |
91 | + | scissors2=0x555500, |
92 | - | gpu.setForeground(tcol[texture]) |
92 | + | } |
93 | - | bground=bground or 0x000000 |
93 | + | |
94 | - | gpu.setBackground(bground) |
94 | + | local event=require("event") |
95 | - | for i=1,5 do |
95 | + | require("term").clear() |
96 | - | if (i==3)and(texture=="scissors") then |
96 | + | |
97 | - | gpu.setForeground(tcol["scissors2"]) |
97 | + | local gameCount=2 |
98 | - | gpu.set(x,y+i-1,tex[texture][i]) |
98 | + | local obj={} |
99 | - | gpu.setForeground(tcol["scissors"]) |
99 | + | local player={} |
100 | - | gpu.set(x+4,y+i-1,"██") |
100 | + | |
101 | - | gpu.setForeground(tcol["scissors2"]) |
101 | + | function testClick(self,x,y) |
102 | - | else |
102 | + | return (x>=self.x)and(y>=self.y)and(x<self.x+self.w)and(y<self.y+self.h) |
103 | - | gpu.set(x,y+i-1,tex[texture][i]) |
103 | + | end |
104 | - | end |
104 | + | |
105 | - | end |
105 | + | function offObj() |
106 | - | gpu.setForeground(0xffffff) |
106 | + | return false |
107 | - | gpu.setBackground(0x000000) |
107 | + | end |
108 | - | end |
108 | + | |
109 | - | |
109 | + | function newButton(x,y,w,h,id,type) |
110 | - | --drawImage(1,1,"rock");drawImage(11,1,"paper");drawImage(21,1,"scissors") |
110 | + | table.insert(obj,{x=x,y=y,w=w,h=h,isClicked=testClick,id=id,type=type}) |
111 | - | --os.exit() |
111 | + | end |
112 | - | |
112 | + | |
113 | - | function drawPlayer(x,y,id) |
113 | + | function drawImage(x,y,texture,bground) |
114 | - | newButton(x ,y+1,10,5,id,1) |
114 | + | gpu.setForeground(tcol[texture]) |
115 | - | newButton(x+11,y+1,10,5,id,2) |
115 | + | bground=bground or 0x000000 |
116 | - | newButton(x+22,y+1,10,5,id,3) |
116 | + | gpu.setBackground(bground) |
117 | - | -- gpu.fill(x,y,10,4," ") |
117 | + | for i=1,5 do |
118 | - | gpu.set(x,y,player[id].name) |
118 | + | if (i==3)and(texture=="scissors") then |
119 | - | drawImage(x ,y+1,"rock") |
119 | + | gpu.setForeground(tcol["scissors2"]) |
120 | - | drawImage(x+22,y+1,"paper") |
120 | + | gpu.set(x,y+i-1,tex[texture][i]) |
121 | - | drawImage(x+11,y+1,"scissors") |
121 | + | gpu.setForeground(tcol["scissors"]) |
122 | - | -- gpu.set(x,y+1,lang[slang]["rock"]) |
122 | + | gpu.set(x+4,y+i-1,"██") |
123 | - | -- gpu.set(x,y+2,lang[slang]["scissors"]) |
123 | + | gpu.setForeground(tcol["scissors2"]) |
124 | - | -- gpu.set(x,y+3,lang[slang]["paper"]) |
124 | + | else |
125 | - | gpu.set(x,y+7,lang[slang]["wins"]..player[id].win) |
125 | + | gpu.set(x,y+i-1,tex[texture][i]) |
126 | - | end |
126 | + | end |
127 | - | |
127 | + | end |
128 | - | gpu.setBackground(0x999999) |
128 | + | gpu.setForeground(0xffffff) |
129 | - | gpu.fill(1,1,10,4," ") |
129 | + | gpu.setBackground(0x000000) |
130 | - | gpu.fill(15,1,10,4," ") |
130 | + | end |
131 | - | newButton(1,1,10,4) |
131 | + | |
132 | - | newButton(15,1,10,4) |
132 | + | --drawImage(1,1,"rock");drawImage(11,1,"paper");drawImage(21,1,"scissors") |
133 | - | isRunning=true |
133 | + | --os.exit() |
134 | - | tmp=2 |
134 | + | |
135 | - | while isRunning do |
135 | + | function drawPlayer(x,y,id) |
136 | - | _,_,x,y,_,name=event.pull("touch") |
136 | + | newButton(x ,y+1,10,5,id,1) |
137 | - | for i=1,#obj do |
137 | + | newButton(x+11,y+1,10,5,id,2) |
138 | - | if obj[i]:isClicked(x,y) then |
138 | + | newButton(x+22,y+1,10,5,id,3) |
139 | - | player[i]={} |
139 | + | -- gpu.fill(x,y,10,4," ") |
140 | - | player[i].name=name |
140 | + | gpu.set(x,y,player[id].name) |
141 | - | player[i].bit=-1 |
141 | + | drawImage(x ,y+1,"rock") |
142 | - | player[i].win=0 |
142 | + | drawImage(x+22,y+1,"paper") |
143 | - | gpu.setBackground(0x009900) |
143 | + | drawImage(x+11,y+1,"scissors") |
144 | - | gpu.fill(obj[i].x,obj[i].y,obj[i].w,obj[i].h," ") |
144 | + | -- gpu.set(x,y+1,lang[slang]["rock"]) |
145 | - | gpu.set(obj[i].x,obj[i].y,player[i].name) |
145 | + | -- gpu.set(x,y+2,lang[slang]["scissors"]) |
146 | - | obj[i].isClicked=offObj |
146 | + | -- gpu.set(x,y+3,lang[slang]["paper"]) |
147 | - | tmp=tmp-1 |
147 | + | gpu.set(x,y+7,lang[slang]["wins"]..player[id].win) |
148 | - | end |
148 | + | end |
149 | - | end |
149 | + | |
150 | - | if tmp==0 then |
150 | + | gpu.setBackground(0x999999) |
151 | - | isRunning=false |
151 | + | gpu.fill(1,1,10,4," ") |
152 | - | end |
152 | + | gpu.fill(15,1,10,4," ") |
153 | - | end |
153 | + | newButton(1,1,10,4) |
154 | - | |
154 | + | newButton(15,1,10,4) |
155 | - | --gpu.setBackground(bground) |
155 | + | isRunning=true |
156 | - | --os.exit() |
156 | + | tmp=2 |
157 | - | --for _=1,gameCount do |
157 | + | while isRunning do |
158 | - | ms={"rock","scissors","paper"} |
158 | + | _,_,x,y,_,name=event.pull("touch") |
159 | - | while (player[1].win~=2)and(player[2].win~=2) do |
159 | + | for i=1,#obj do |
160 | - | gpu.setBackground(bground) |
160 | + | if obj[i]:isClicked(x,y) then |
161 | - | obj={} |
161 | + | player[i]={} |
162 | - | require("term").clear() |
162 | + | player[i].name=name |
163 | player[i].bit=-1 | |
164 | - | gpu.fill(1,2,32,5," ") |
164 | + | player[i].win=0 |
165 | - | gpu.fill(1,16,32,5," ") |
165 | + | gpu.setBackground(0x009900) |
166 | - | gpu.setBackground(bground) |
166 | + | gpu.fill(obj[i].x,obj[i].y,obj[i].w,obj[i].h," ") |
167 | - | drawPlayer(player1Pos[1],player1Pos[2],1) |
167 | + | gpu.set(obj[i].x,obj[i].y,player[i].name) |
168 | - | drawPlayer(player2Pos[1],player2Pos[2],2) |
168 | + | obj[i].isClicked=offObj |
169 | - | |
169 | + | tmp=tmp-1 |
170 | - | isRunning=true |
170 | + | end |
171 | - | |
171 | + | end |
172 | - | tmp=0 |
172 | + | if tmp==0 then |
173 | - | |
173 | + | isRunning=false |
174 | - | while isRunning do |
174 | + | end |
175 | - | _,_,x,y,_,name=event.pull("touch") |
175 | + | end |
176 | - | for i=1,#obj do |
176 | + | |
177 | - | if obj[i]:isClicked(x,y) then |
177 | + | --gpu.setBackground(bground) |
178 | - | --print(i,obj[i].id) |
178 | + | --os.exit() |
179 | - | if name==player[obj[i].id].name then |
179 | + | --for _=1,gameCount do |
180 | - | tmp=tmp+1 |
180 | + | ms={"rock","scissors","paper"} |
181 | - | -- gpu.set(149,49,i.."") |
181 | + | while (player[1].win~=2)and(player[2].win~=2) do |
182 | - | -- pos=(i-1)%3+1 |
182 | + | gpu.setBackground(bground) |
183 | - | player[obj[i].id].bit=obj[i].type |
183 | + | obj={} |
184 | - | pos=math.floor((i-1)/3) |
184 | + | require("term").clear() |
185 | - | if pos==0 then |
185 | + | gpu.setBackground(0x000000) |
186 | - | gpu.fill(1,2,32,5," ") |
186 | + | gpu.fill(1,2,32,5," ") |
187 | - | else |
187 | + | gpu.fill(1,16,32,5," ") |
188 | - | gpu.fill(1,16,32,5," ") |
188 | + | gpu.setBackground(bground) |
189 | - | end |
189 | + | drawPlayer(player1Pos[1],player1Pos[2],1) |
190 | - | obj[pos*3+1].isClicked=offObj;obj[pos*3+2].isClicked=offObj;obj[pos*3+3].isClicked=offObj |
190 | + | drawPlayer(player2Pos[1],player2Pos[2],2) |
191 | - | end |
191 | + | |
192 | - | end |
192 | + | isRunning=true |
193 | - | end |
193 | + | |
194 | - | if tmp==2 then |
194 | + | tmp=0 |
195 | - | isRunning=false |
195 | + | |
196 | - | end |
196 | + | while isRunning do |
197 | - | end |
197 | + | _,_,x,y,_,name=event.pull("touch") |
198 | - | --print(player[1].bit,player[2].bit) |
198 | + | for i=1,#obj do |
199 | - | --require("term").clear() |
199 | + | if obj[i]:isClicked(x,y) then |
200 | - | drawPlayer(player1Pos[1],player1Pos[2],1) |
200 | + | --print(i,obj[i].id) |
201 | - | drawPlayer(player2Pos[1],player2Pos[2],2) |
201 | + | if name==player[obj[i].id].name then |
202 | - | obj={} |
202 | + | tmp=tmp+1 |
203 | - | if player[1].bit==player[2].bit then |
203 | + | -- gpu.set(149,49,i.."") |
204 | - | -- print(lang[slang]["draw"]) |
204 | + | -- pos=(i-1)%3+1 |
205 | - | tx=(player[1].bit-1)*11 |
205 | + | player[obj[i].id].bit=obj[i].type |
206 | - | drawImage(player1Pos[1]+tx,player1Pos[2]+1,ms[player[1].bit],colorDraw) |
206 | + | pos=math.floor((i-1)/3) |
207 | - | drawImage(player2Pos[1]+tx,player2Pos[2]+1,ms[player[2].bit],colorDraw) |
207 | + | if pos==0 then |
208 | - | --elseif ((player[1].bit==1)and(player[2].bit==2))or((player[1].bit==2)and(player[1]) |
208 | + | gpu.fill(1,2,32,5," ") |
209 | - | elseif (player[1].bit==player[2].bit-1)or(player[1].bit==player[2].bit+2)then |
209 | + | else |
210 | - | -- print(lang[slang]["win1"]..player[1].name) |
210 | + | gpu.fill(1,16,32,5," ") |
211 | - | drawImage(player1Pos[1]+(player[1].bit-1)*11,player1Pos[2]+1,ms[player[1].bit],colorWin) |
211 | + | end |
212 | - | drawImage(player2Pos[1]+(player[2].bit-1)*11,player2Pos[2]+1,ms[player[2].bit],colorLose) |
212 | + | obj[pos*3+1].isClicked=offObj;obj[pos*3+2].isClicked=offObj;obj[pos*3+3].isClicked=offObj |
213 | - | player[1].win=player[1].win+1 |
213 | + | end |
214 | - | else |
214 | + | end |
215 | - | -- print(lang[slang]["win2"]..player[2].name) |
215 | + | end |
216 | - | drawImage(player1Pos[1]+(player[1].bit-1)*11,player1Pos[2]+1,ms[player[1].bit],colorLose) |
216 | + | if tmp==2 then |
217 | - | drawImage(player2Pos[1]+(player[2].bit-1)*11,player2Pos[2]+1,ms[player[2].bit],colorWin) |
217 | + | isRunning=false |
218 | - | player[2].win=player[2].win+1 |
218 | + | end |
219 | - | end |
219 | + | end |
220 | - | --ms={lang[slang]["rock2"],lang[slang]["scissors2"],lang[slang]["paper2"]} |
220 | + | --print(player[1].bit,player[2].bit) |
221 | - | --print(ms[player[1].bit],ms[player[2].bit]) |
221 | + | --require("term").clear() |
222 | - | event.pull("key_down") |
222 | + | drawPlayer(player1Pos[1],player1Pos[2],1) |
223 | - | end |
223 | + | drawPlayer(player2Pos[1],player2Pos[2],2) |
224 | - | if player[1].win>player[2].win then |
224 | + | obj={} |
225 | - | io.write(lang[slang]["win1"]) |
225 | + | if player[1].bit==player[2].bit then |
226 | - | else |
226 | + | -- print(lang[slang]["draw"]) |
227 | - | io.write(lang[slang]["win2"]) |
227 | + | tx=(player[1].bit-1)*11 |
228 | - | end |
228 | + | drawImage(player1Pos[1]+tx,player1Pos[2]+1,ms[player[1].bit],colorDraw) |
229 | - | io.write(player[1].win.." VS "..player[2].win) |
229 | + | drawImage(player2Pos[1]+tx,player2Pos[2]+1,ms[player[2].bit],colorDraw) |
230 | --elseif ((player[1].bit==1)and(player[2].bit==2))or((player[1].bit==2)and(player[1]) | |
231 | elseif (player[1].bit==player[2].bit-1)or(player[1].bit==player[2].bit+2)then | |
232 | -- print(lang[slang]["win1"]..player[1].name) | |
233 | drawImage(player1Pos[1]+(player[1].bit-1)*11,player1Pos[2]+1,ms[player[1].bit],colorWin) | |
234 | drawImage(player2Pos[1]+(player[2].bit-1)*11,player2Pos[2]+1,ms[player[2].bit],colorLose) | |
235 | player[1].win=player[1].win+1 | |
236 | else | |
237 | -- print(lang[slang]["win2"]..player[2].name) | |
238 | drawImage(player1Pos[1]+(player[1].bit-1)*11,player1Pos[2]+1,ms[player[1].bit],colorLose) | |
239 | drawImage(player2Pos[1]+(player[2].bit-1)*11,player2Pos[2]+1,ms[player[2].bit],colorWin) | |
240 | player[2].win=player[2].win+1 | |
241 | end | |
242 | --ms={lang[slang]["rock2"],lang[slang]["scissors2"],lang[slang]["paper2"]} | |
243 | --print(ms[player[1].bit],ms[player[2].bit]) | |
244 | event.pull("key_down") | |
245 | end | |
246 | if player[1].win>player[2].win then | |
247 | -- io.write(lang[slang]["win1"]) | |
248 | messageBox("GAME OVER",lang[slang]["win1"]..player[1].win.." VS "..player[2].win) | |
249 | else | |
250 | -- io.write(lang[slang]["win2"]) | |
251 | messageBox("GAME OVER",lang[slang]["win2"]..player[2].win.." VS "..player[1].win) | |
252 | end | |
253 | --io.write(player[1].win.." VS "..player[2].win) | |
254 | gpu.setBackground(0x000000) |