REM Крестики-нолики gosub func gr.open 255,0,0,0,0,1 dim so[9],cli[9] gr.screen sw,sh cw=sw/2 ch=sh/2 f(255,255,255) rcr_b(0,sh/15,sw,sh+20,20) textk(sw/15,sh/30,"Крестики-нолики",sh/30,1,2) c(255,0,0,2) text(sw-sw/15,sh/30,"X",sh/30,2,2) !gr.rect ff,sw-sw/8,0,sw,sh/15 bex=regtch(sw-sw/8,0,sw,sh/15) lt=sw/20 tp=ch-cw+sw/20 rt=sw-sw/20 bt=ch+cw-sw/20 w=rt-lt q=w/3 f(0,0,255) a(100) rcr_b(lt,tp,rt,bt,5) f(255,255,255) a(200) rcr_b(lt+2,tp+2,rt-2,bt-2,3) c(0,0,255,2) a(80) gr.line oline,lt+q,tp+q/5,lt+q,bt-q/5 gr.line oline,lt+q*2,tp+q/5,lt+q*2,bt-q/5 gr.line oline,lt+q/5,tp+q,rt-q/5,tp+q gr.line oline,lt+q/5,tp+q*2,rt-q/5,tp+q*2 a(150) c(0,0,0,2) dim tx[9],to[9] f=0 for i=0 to 2 for j=0 to 2 f++ tx[f]=text(lt+q/2+q*j+3,tp+q/2+i*q-q/10,"x",q,2,2) to[f]=text(lt+q/2+q*j+3,tp+q/2+i*q-q/10,"o",q,2,2) gr.hide tx[f] gr.hide to[f] next j next i dim ln[8] c(255,0,0,7) for i=0 to 2 gr.line ln[i+4],lt+q/2+q*i+3,tp+q/5, lt+q/2+q*i+3,bt-q/5 gr.line ln[i+1],lt+q/5+3,tp+q/2+q*i, rt-q/5+3,tp+q/2+q*i next i gr.line ln[7],lt+q/3,tp+q/3, rt-q/3,bt-q/3 gr.line ln[8],lt+q/3,bt-q/3,rt-q/3,tp+q/3 for i=1 to 8 gr.hide ln[i] next i f(0,0,0) a(255) ht=text(cw,ch-cw/0.85,"Первый ход Х",w/10,2,2) f(255,0,0) a(255) dim tch[9] f=0 for i=0 to 2 for j=0 to 2 f++ tch[f]=regtch(lt+j*q,tp+i*q,lt+q+j*q,tp+q+i*q) next j next i !Debug.show.watch sct= text(cw,bt+sh/10,"",sh/40,2,2) f(0,0,0) a(255) gr.rect wall,0,0,sw,sh f(255,255,255) caps=text(cw,ch,"Крестики-нолики",sw/15,2,2) about=text(cw,sh-sh/40,"@ CH.A.D 2016", sh/40,2,2) gr.render pause 1000 for i=1 to 255 step 20 gr.modify wall,"alpha",255-i gr.modify caps,"alpha",255-i gr.modify about,"alpha",255-i gr.render next i gr.render resreg=regtch(0,0,sw,sh) do gosub ev onbackkey=0 until e_n_d=1 end "До встречи!" OnError: end "Игра завершена с ошибкой!" ev: ex=click(bex,ex) if ex=2 then gr.modify sct,"text","Счет сброшен!" sco=0 scx=0 gr.render endif for i=1 to 9 cli[i]=click(tch[i],cli[i]) if cli[i]=1 & so[i]=0 then if boo=0 then gr.show tx[i] gr.modify ht,"text","Ходят О" so[i]=1 gosub win boo=1 elseif boo=1 then gr.show to[i] gr.modify ht,"text","Ходят X" so[i]=2 boo=0 gosub win endif endif next i return win: for j=1 to 2 for i=0 to 2 if so[i*3+1]=j & so[i*3+2]=j & so[i*3+3]=j then gr.show ln[i+1] gosub score F_N.break endif if so[1+i]=j & so[4+i]=j & so[7+i]=j then gr.show ln[i+4] gosub score F_N.break endif next i if so[1]=j & so[5]=j & so[9]=j then gr.show ln[7] gosub score endif if so[3]=j & so[5]=j & so[7]=j then gr.show ln[8] gosub score endif next j if so[1]<>0 & so[2]<>0 & so[3]<>0 & so[4]<>0 & so[5]<>0 & so[6]<>0 & so[7]<>0 & so[8]<>0 & so[9]<>0 then gr.modify sct,"text","Игра завершена!" gr.render pause 1000 do resclick=click(resreg,resclick) if resclick=2 then gosub reset until resclick=2 gosub score endif gr.render return score: if j=1 then scx++ if j=2 then sco++ if scx>sco then gr.modify sct,"text","Крестики выигрывают со счетом "+int$(scx)+":"+int$(sco) if sco>scx then gr.modify sct,"text","Нолики выигрывают со счетом "+int$(sco)+":"+int$(scx) if sco=scx then gr.modify sct,"text", "Ничья со счетом "+int$(sco)+":"+int$(scx) gr.render pause 500 do resclick=click(resreg,resclick) if resclick=2 then gosub reset until resclick=2 return reset: for i=1 to 9 gr.hide tx[i] gr.hide to[i] if i<9 then gr.hide ln[i] so[i]=0 next i gr.render return func: fn.def c(r,g,b,ss) gr.set.stroke ss gr.color ,r,g,b,0 fn.end fn.def f(r,g,b) gr.set.stroke 1 gr.color ,r,g,b,1 fn.end fn.def a(a) gr.color a fn.end fn.def text(x,y,s$,s,ag,av) gr.text.align ag gr.text.size s if av=1 then v=0 if av=2 then v=-(s*(0.29/2))+s/2 if av=3 then v=-(s*0.29)+s gr.text.draw oTx,x,y+v,s$ fn.rtn oTx fn.end fn.def textk(x,y,s$,s,ag,av) gr.text.align ag gr.text.size s Gr.text.skew -0.5 if av=1 then v=0 if av=2 then v=-(s*(0.29/2))+s/2 if av=3 then v=-(s*0.29)+s gr.text.draw oTx,x,y+v,s$ Gr.text.skew 0 fn.rtn oTx fn.end fn.def rcr_b(lt,tp,rt,bt,r) w=rt-lt h=bt-tp list.create n,lst_rcr_b array.load z[],-1,1,1,-1, -1,-1,1,1 for i=0 to 3 step 1 for g=90*(i+2) to 90*(i+3) step 90/10 mx=cos(toradians(g))*r+(w/2-r)*z[i+1] my=sin(toradians(g))*r+(h/2-r)*z[i+5] list.add lst_rcr_b,mx,my next g next i gr.poly oP,lst_rcr_b,rt-(rt-lt)/2,bt-(bt-tp)/2 fn.rtn oP fn.end fn.def click(lst,f) List.get lst,1,lt List.get lst,2,tp List.get lst,3,rt List.get lst,4,bt gr.bounded.touch btc,lt,tp,rt,bt gr.touch tc,x,y if f=1 then c=1 if f=2 then c=0 if f=10 then c=10 if tc=1 & btc=0 & f=0 then c=10 if btc=1 & f<10 then c=1 if btc=0 & tc=0 & f=10 then c=0 if f=1 & btc=0 & tc=0 then c=2 if f=1 & btc=0 & tc=1 then c=0 fn.rtn c fn.end fn.def regtch(lt,tp,rt,bt) List.create N, lst list.add lst, lt,tp,rt,bt fn.rtn lst fn.end fn.def dialog_2wt(s$,sl$,sr$) gr.screen sw,sh list.create n, lstobj gx=sw/12 gy=sh/20 q=gx cw=sw/2 ch=sh/2 dim btd[2] gr.color 150,0,0,0,1 gr.rect fon,0,0,sw,sh list.add lstobj,fon !Рисуем окно gr.set.stroke 2 gr.color 255,255,255,255,1 !w1=rcr_b(gx-1,gy*7-1,gx*11,gy*13,q/2+3) gr.rect w1,gx-1,gy*7-1,gx*11,gy*13 gr.set.stroke 2 gr.color 130,0,0,0,1 !w2= rcr_b(gx,gy*7,gx*11+2,gy*13+2,q/2+2) gr.rect w2,gx,gy*7,gx*11+2,gy*13+2 gr.set.stroke 2 gr.color 210,255,255,255,1 !w3=rcr_b(gx+1,gy*7+1,gx*11+1,gy*13+1,q/2+2) gr.rect w3,gx+1,gy*7+1,gx*11+1,gy*13+1 gr.color 255,170,170,170,1 !w4=rcr_b(gx+1,gy*7+1,gx*11-1,gy*13-1,q/2) gr.rect w4,gx+1,gy*7+1,gx*11-1,gy*13-1 list.add lstobj,w1,w2,w3,w4 !Рисуем линии gr.color 130,0,0,0,0 gr.set.stroke 1 gr.line line1,gx*1.5,gy*11,gx*10.5,gy*11 gr.line line2,gx*6,gy*11.3,gx*6,gy*12.7 gr.color 170,255,255,255,0 gr.line line3,gx*1.5-1,gy*11-1,gx*10.5-1,gy*11-1 gr.line line4,gx*6-1,gy*11.3-1,gx*6-1,gy*12.7-1 list.add lstobj,line1,line2,line3,line4 !Рисуем нажатую левую кнопку gr.color 0,255,255,255,1 %alpha 175 gr.rect btd[1],gx*1.5,gy*11.3,gx*5.5,gy*12.7 !Рисуем нажатую правую кнопку gr.color 0,255,255,255,1 %alpha 175 gr.rect btd[2],gx*6.5,gy*11.3,gx*10.5,gy*12.7 list.add lstobj,btd[1],btd[2] !Рисуем главный текст gr.text.align 2 size=q gr.text.size size gr.color 170,255,255,255,1 gr.text.draw t1,gx*6-1,(gy*9-1)-size*(0.29/2)+size/2,s$ gr.color 170,0,0,0,1 gr.text.draw t2,gx*6+1,(gy*9+1)-size*(0.29/2)+size/2,s$ gr.color 255,100,100,200,1 gr.text.draw t3,gx*6,(gy*9)-size*(0.29/2)+size/2,s$ !! gr.color 170,255,255,255,1 t1=text(gx*6-1,gy*9-1,s$,q,2,2) gr.color 170,0,0,0,1 t2=text(gx*6+1,gy*9+1,s$,q,2,2) gr.color 255,100,100,200,1 t3=text(gx*6,gy*9,s$,q,2,2) !! !Рисуем текст левой кнопки gr.text.align 2 size=q/1.3 gr.text.size size gr.color 170,255,255,255,1 gr.text.draw t4,gx*3.5-1,(gy*12-1)-size*(0.29/2)+size/2,sl$ gr.color 170,0,0,0,1 gr.text.draw t5,gx*3.5+1,(gy*12+1)-size*(0.29/2)+size/2,sl$ gr.color 255,100,100,200,1 gr.text.draw t6,gx*3.5,(gy*12)-size*(0.29/2)+size/2,sl$ !! gr.color 170,255,255,255,1 t4=text(gx*3.5-1,gy*12-1,sl$,q/1.3,2,2) gr.color 170,0,0,0,1 t5=text(gx*3.5+1,gy*12+1,sl$,q/1.3,2,2) gr.color 255,100,100,200,1 t6=text(gx*3.5,gy*12,sl$,q/1.3,2,2) !! !Рисуем текст правой кнопки gr.text.align 2 size=q/1.3 gr.text.size size gr.color 170,255,255,255,1 gr.text.draw t7,gx*8.5-1,(gy*12-1)-size*(0.29/2)+size/2,sr$ gr.color 170,0,0,0,1 gr.text.draw t8,gx*8.5+1,(gy*12+1)-size*(0.29/2)+size/2,sr$ gr.color 255,100,100,200,1 gr.text.draw t9,gx*8.5,(gy*12)-size*(0.29/2)+size/2,sr$ !! -((size*(0.29/2)+size/2)) t7=text(gx*8.5-1,gy*12-1,sr$,q/1.3,2,2) gr.color 170,0,0,0,1 t8=text(gx*8.5+1,gy*12+1,sr$,q/1.3,2,2) gr.color 255,100,100,200,1 t9=text(gx*8.5,gy*12,sr$,q/1.3,2,2) !! list.add lstobj,t1,t2,t3,t4,t5,t6,t7,t8,t9 !Создаем невидимый курсор gr.color 0,0,0,0,1 gr.circle cur,-100,-100,q/4 list.add lstobj,cur Gr.group.list objs, lstobj !Стартовое значение таймера sttime=int(clock()+11000) do et$=int$((sttime-clock())/1000) et=val(et$) if et=0 then gr.modify t4,"text",sl$ gr.modify t5,"text",sl$ gr.modify t6,"text",sl$ gr.render pause 500 gr.modify btd[1],"alpha",175 gr.render pause 500 gr.hide objs List.clear lstobj d_o_e_n_d=1:rtn=10 elseif et>0 & et<10 then gr.modify t4,"text",sl$+chr$(9311+et) gr.modify t5,"text",sl$+chr$(9311+et) gr.modify t6,"text",sl$+chr$(9311+et) endif gr.touch fl,xtch,ytch gr.render IF fl=1 THEN do et$=int$((sttime-clock())/1000) et=val(et$) if et=0 then gr.modify t4,"text",sl$ gr.modify t5,"text",sl$ gr.modify t6,"text",sl$ gr.render pause 500 gr.modify btd[1],"alpha",175 gr.render pause 500 gr.hide objs List.clear lstobj d_o_e_n_d=1:rtn=10 elseif et>0 & et<10 then gr.modify t4,"text",sl$+chr$(9311+et) gr.modify t5,"text",sl$+chr$(9311+et) gr.modify t6,"text",sl$+chr$(9311+et) endif gr.touch fl,xtch,ytch gr.modify cur,"x",xtch,"y",ytch for i=1 to 2 if gr_collision(cur,btd[i]) & fl=1 then gr.modify btd[i],"alpha",175 elseif gr_collision(cur,btd[i]) & fl=0 then if i=1 then rtn=i if i=2 then rtn=i gr.hide objs List.clear lstobj d_o_e_n_d=1 f_n.break else gr.modify btd[i],"alpha",0 endif next gr.render until d_o_e_n_d=1 ENDIF until d_o_e_n_d=1 fn.rtn rtn fn.end return OnBackKey: if onbackkey=0 then onbackkey=1 diaex=dialog_2wt("Выход?","Да","Нет") if diaex=1 | diaex=10 then e_n_d=1 endif Back.resume