次のプログラムはカードゲームの ”神経衰弱” です。ここではこれまでに紹介した命令等の他、いくつかの命令と関数が使用されていますが、それらについては前節の「[[その他]]」を参照しながら解説します。できれば、神経衰弱のルール(アルゴリズム)を思い出しながら、プログラムの部分部分が何を表現しているのかを想像しながら入力してみてください。また、当然ですが、入力間違いをすると正しく動きませんので、よく注意して入力してくださいw #author("2023-01-31T10:40:09+09:00","default:maa","maa") ※プログラム中の "_" (下線)は " " (空白スペース)の意味です。"___" (下線 3 つ)は空白スペース 3 つの意味です。実際に入力する際には、"_ " の代わりに " " を入力してください。 100 randomize 110 cards=20:left=cards:dim card$(cards,1) 120 for i=1 to cards/2 130 f=0 140 while f<2 150 c=int(rnd(1)*cards+1) 160 if card$(c,0)="" then card$(c,0)=chr$(64+i) else goto 150 170 f=f+1 180 wend 190 next i 200 while left<>0 210 cls:print "_____<_神経衰弱_>":print 220 gosub *display 230 input "カードを2枚選んでください。";a,b 240 if a>cards or b>cards or a*b=0 or a=b then goto 230 250 if card$(a,1)="x" or card$(b,1)="x" then goto 230 260 num=num+1 270 if card$(a,0)=card$(b,0) then gosub *true else gosub *false 280 gosub *display 290 print "何かキーを押してください。" 300 if inkey$="" then goto 300 310 wend 320 print "おめでとう。全部正解するまでに";num;"回かかりました。" 330 end 340 *display 350 w=0 360 for i=1 to cards 370 w=w+1 380 if w=6 then print:print:w=1 390 if card$(i,1)="t" then gosub *open:goto 430 400 if card$(i,1)="f" then gosub *choice:goto 430 410 if card$(i,1)="x" then print "____";:goto 430 420 print "__";:color 0,7:print using "##";i;:color 7,0 430 next i 440 print:print 450 return 460 *open 470 print "__";:color 0,4:print "_";card$(i,0);:color 7,0 480 card$(i,1)="x" 490 return 500 *choice 510 print "__";:color 0,2:print "_";card$(i,0);:color 7,0 520 card$(i,1)="" 530 return 540 *true 550 cls:print "あたり!":print 560 card$(a,1)="t":card$(b,1)="t" 570 left=left-2 580 return 590 *false 600 cls:print "はずれ":print 610 card$(a,1)="f":card$(b,1)="f" 620 return