timur77
Junior Member
Someday I will tell my grandsons that I am older than the Internet. And it will blow their brain.
Posts: 79
|
Post by timur77 on Apr 1, 2020 4:14:08 GMT -5
Here is the first classic game code
nomainwin 'запрос параметров клетки UpperLeftX = DisplayWidth/2-150 UpperLeftY = DisplayHeight/2-50 WindowWidth = 300 WindowHeight = 100 statictext #win1.st1, "Размер клетки", 40, 25, 80, 25 textbox #win1.tb1, 130, 25, 30, 20 button #win1.b1, "OK",[exit1],UL, 170,25,50,20 open "Параметр клетки Жизни" for window as #win1 print #win1, "trapclose [exit1]" #win1.tb1, "10" wait
[exit1] #win1.tb1, "!contents? tb1$" RK=Val(tb1$) close #win1
Shir=Int((DisplayWidth-40)/10)*10'ширина поля Vis=Int((DisplayHeight-170)/10)*10'высота поля 'RK=5'размер клетки
KS=Int(Shir/RK)'кол-во клеток по ширине KV=Int(Vis/RK)'кол-во клеток по высоте
Dim m1(2000,1500) Dim m2(2000,1500)
'интерфейс WindowWidth = Shir+40 WindowHeight = Vis+100 UpperLeftX = DisplayWidth/2-WindowWidth/2 UpperLeftY = DisplayHeight/2-WindowHeight/2 button #win.bt1, "Пуск", [start], UL, 5,5,100,25 button #win.bt2, "Стоп", [stop], UL, 120,5,100,25 button #win.bt3, "Очистить", [clear], UL, 235,5,100,25 graphicbox #win.gbox, 10, 50, Shir+3, Vis+3 open "Жизнь" for window as #win print #win, "trapclose [exit]" 'рисование сетки print #win.gbox, "down; size 1; color lightgray" for i=RK To Shir-RK step RK print #win.gbox, "line ";i;" ";0;" ";i;" ";Vis next i for a=RK to Vis-RK step RK print #win.gbox, "line ";0;" ";a;" ";Shir;" ";a next a print #win.gbox, "flush" 'перехват нажатия мышки print #win.gbox, "when leftButtonMove [set]" print #win.gbox, "when rightButtonMove [give]" print #win.gbox, "when leftButtonDown [set]" print #win.gbox, "when rightButtonDown [give]" wait 'очистка [clear] print #win.gbox, "backcolor 255 255 255" For i=0 To KS-1 For a=0 To KV-1 m1(i,a)=0 m2(i,a)=0 print #win.gbox, "set ";i*RK;" ";a*RK print #win.gbox, "boxfilled ";i*RK+RK+1;" ";a*RK+RK+1 Next a Next i print #win.gbox, "flush" wait 'рисование клеток [set] i=Int(MouseX/RK) a=Int(MouseY/RK) if i<0 Or i>KS-1 Then wait if a<0 Or a>KV-1 Then wait m1(i,a)=1 print #win.gbox, "backcolor 0 255 0" print #win.gbox, "set ";i*RK;" ";a*RK print #win.gbox, "boxfilled ";i*RK+RK+1;" ";a*RK+RK+1 wait 'стирание клеток [give] i=Int(MouseX/RK) a=Int(MouseY/RK) if i<0 Or i>KS-1 Then wait if a<0 Or a>KV-1 Then wait m1(i,a)=0 print #win.gbox, "backcolor 255 255 255" print #win.gbox, "set ";i*RK;" ";a*RK print #win.gbox, "boxfilled ";i*RK+RK+1;" ";a*RK+RK+1 wait 'запуск симуляции [start] 'подсчет соседей для каждой клетки For i=0 To KS-1 For a=0 To KV-1 m2(i,a)=0 s=0 c=0 x1=i-1+(i=0)*KS y1=a-1+(a=0)*KV if m1(x1,y1)>0 Then s=s+1:c=m1(x1,y1) if m1(i,y1)>0 Then s=s+1:c=(c+m1(x1,y1))/2 x1=i+1-(i=(KS-1))*KS if m1(x1,y1)>0 Then s=s+1:c=(c+m1(x1,y1))/2 if m1(x1,a)>0 Then s=s+1:c=(c+m1(x1,y1))/2 y1=a+1-(a=(KV-1))*KV if m1(x1,y1)>0 Then s=s+1:c=(c+m1(x1,y1))/2 if m1(i,y1)>0 Then s=s+1:c=(c+m1(x1,y1))/2 x1=i-1+(i=0)*KS if m1(x1,y1)>0 Then s=s+1:c=(c+m1(x1,y1))/2 if m1(x1,a)>0 Then s=s+1:c=(c+m1(x1,y1))/2
if s<2 Or s>3 Then m2(i,a)=0 if s=3 Then m2(i,a)=m1(i,a)+1-(m1(i,a)>=255)*255+(m1(i,a)=0)*c if s=2 And m1(i,a)>0 Then m2(i,a)=m1(i,a)+1-(m1(i,a)>=255)*255 Next a Next i 'рисование следующего поколения клеток For i=0 To KS-1 For a=0 To KV-1 if m1(i,a)>0 Or m2(i,a)>0 Then m1(i,a)=m2(i,a) if m1(i,a)=0 Then print #win.gbox, "backcolor 255 255 255" End If if m1(i,a)>0 Then R=m1(i,a) G=255 - m1(i,a) B=m1(i,a) print #win.gbox, "backcolor ";R;" ";G;" ";B End If print #win.gbox, "set ";i*RK;" ";a*RK print #win.gbox, "boxfilled ";i*RK+RK+1;" ";a*RK+RK+1 End if Next a Next i
scan'проверка нажатия goto [start] wait 'остановка симуляции [stop] wait 'выход [exit] close #win end
Here is the modified game code
nomainwin 'запрос параметров клетки UpperLeftX = DisplayWidth/2-150 UpperLeftY = DisplayHeight/2-50 WindowWidth = 300 WindowHeight = 100 statictext #win1.st1, "Размер клетки", 40, 25, 80, 25 textbox #win1.tb1, 130, 25, 30, 20 button #win1.b1, "OK",[exit1],UL, 170,25,50,20 open "Параметр клетки Жизни" for window as #win1 print #win1, "trapclose [exit1]" #win1.tb1, "10" wait
[exit1] #win1.tb1, "!contents? tb1$" RK=Val(tb1$) RKV=RK*0.9 close #win1
Shir=Int((DisplayWidth-40)/10)*10'ширина поля Vis=Int((DisplayHeight-170)/10)*10'высота поля 'RK=5'размер клетки
KS=Int(Shir/RK)'кол-во клеток по ширине KV=Int(Vis/(RKV))-(Int(Vis/(RKV)) mod 2)'кол-во клеток по высоте
Dim m1(2000,1500) Dim m2(2000,1500)
'интерфейс WindowWidth = Shir+40 WindowHeight = Vis+100 UpperLeftX = DisplayWidth/2-WindowWidth/2 UpperLeftY = DisplayHeight/2-WindowHeight/2 button #win.bt1, "Пуск", [start], UL, 5,5,100,25 button #win.bt2, "Стоп", [stop], UL, 120,5,100,25 button #win.bt3, "Очистить", [clear], UL, 235,5,100,25 graphicbox #win.gbox, 10, 50, Shir+3, Vis+3 open "Жизнь" for window as #win print #win, "trapclose [exit]"
'рисование сетки print #win.gbox, "down; size 1; color lightgray" #win.gbox, "fill 128 128 128" #win.gbox, "backcolor 255 255 255" For i=0 To KS-2 For a=0 To KV-1 x=i*RK+(a Mod 2)*RK/2+RK/2 y=a*RKV+RKV/2 #win.gbox, "set ";x;" ";y #win.gbox, "circlefilled ";RK/2+1 next a next i print #win.gbox, "flush"
'перехват нажатия мышки print #win.gbox, "when leftButtonMove [set]" print #win.gbox, "when rightButtonMove [give]" print #win.gbox, "when leftButtonDown [set]" print #win.gbox, "when rightButtonDown [give]" wait 'очистка [clear] print #win.gbox, "backcolor 255 255 255" For i=0 To KS-2 For a=0 To KV-1 m1(i,a)=0 m2(i,a)=0 x=i*RK+(a Mod 2)*RK/2+RK/2 y=a*RKV+RKV/2 #win.gbox, "set ";x;" ";y #win.gbox, "circlefilled ";RK/2+1 Next a Next i print #win.gbox, "flush" wait 'рисование клеток [set] a=Int(MouseY/RKV) i=Int((MouseX-(a mod 2)*RK/2)/RK)
if i<0 Or i>KS-2 Then wait if a<0 Or a>KV-1 Then wait m1(i,a)=1 print #win.gbox, "backcolor 0 255 0" print #win.gbox, "set ";i*RK+(a mod 2)*RK/2+RK/2;" ";a*RKV+RKV/2 print #win.gbox, "circlefilled ";RK/2+1 wait 'стирание клеток [give] a=Int(MouseY/RKV) i=Int((MouseX-(a mod 2)*RK/2)/RK)
if i<0 Or i>KS-2 Then wait if a<0 Or a>KV-1 Then wait m1(i,a)=0 print #win.gbox, "backcolor 255 255 255" print #win.gbox, "set ";i*RK+(a mod 2)*RK/2+RK/2;" ";a*RKV+RKV/2 print #win.gbox, "circlefilled ";RK/2+1 wait wait 'запуск симуляции [start] 'подсчет соседей для каждой клетки For i=0 To KS-2 For a=0 To KV-1 m2(i,a)=0 s=0 c=0 x1=i-1+(i=0)*(KS-1) y1=a-1+(a=0)*KV chh=a mod 2 if m1(x1,y1)>0 and chh=0 Then s=s+1:c=m1(x1,y1) if m1(i,y1)>0 Then s=s+1:c=(c+m1(x1,y1))/2 x1=i+1-(i=(KS-2))*(KS-1) if m1(x1,y1)>0 and chh=1 Then s=s+1:c=(c+m1(x1,y1))/2 if m1(x1,a)>0 Then s=s+1:c=(c+m1(x1,y1))/2 y1=a+1-(a=(KV-1))*KV if m1(x1,y1)>0 and chh=1 Then s=s+1:c=(c+m1(x1,y1))/2 if m1(i,y1)>0 Then s=s+1:c=(c+m1(x1,y1))/2 x1=i-1+(i=0)*(KS-1) if m1(x1,y1)>0 and chh=0 Then s=s+1:c=(c+m1(x1,y1))/2 if m1(x1,a)>0 Then s=s+1:c=(c+m1(x1,y1))/2
if s<2 Or s>2 Then m2(i,a)=0 if s=2 Then m2(i,a)=m1(i,a)+1-(m1(i,a)>=255)*255+(m1(i,a)=0)*c if s=2 And m1(i,a)>0 Then m2(i,a)=m1(i,a)+1-(m1(i,a)>=255)*255 Next a Next i 'рисование следующего поколения клеток For i=0 To KS-2 For a=0 To KV-1 if m1(i,a)>0 Or m2(i,a)>0 Then m1(i,a)=m2(i,a) if m1(i,a)=0 Then print #win.gbox, "backcolor 255 255 255" End If if m1(i,a)>0 Then R=m1(i,a) G=255 - m1(i,a) B=m1(i,a) print #win.gbox, "backcolor ";R;" ";G;" ";B End If x=i*RK+(a Mod 2)*RK/2+RK/2 y=a*RKV+RKV/2 #win.gbox, "set ";x;" ";y #win.gbox, "circlefilled ";RK/2+1 End if Next a Next i
scan'проверка нажатия goto [start] wait 'остановка симуляции [stop] wait 'выход [exit] close #win end
|
|