ab.com コミュニティ https://www.activebasic.com/forum/ |
|
頭の体操ゲームです https://www.activebasic.com/forum/viewtopic.php?t=2057 |
ページ 1 / 1 |
作成者: | AONIRO [ 2007年10月10日(水) 00:03 ] |
記事の件名: | 頭の体操ゲームです |
全然実践でもなんでもない、ちょっとしたゲームです。 高校でActiveBasicをはじめてまだ間もないので目も当てられんようなものなんですが 苦心して初心者なりの試行錯誤の末、簡単なものですが一応完成しました。 (アドバイス、補足修正等してくださる方いらっしゃったらぜひお願いします!) 元が結構有名なものなんですが、それをただActiveBasicで作ってみたいなと 思い立ったというだけのものなので、ゲームとしては楽しめると思います。 ただなにぶんコードにもある発案者に許可をとっていないので個人的に楽しむ範囲なんですが笑 雰囲気を出すために英語仕様にしてあるのでここに一応イントロなどのところの和文も載せておきます。 ○Petals Around the Rose(バラの周りの花びら)○ これは実際、ゲームというより、むしろパズルや頭の体操の部類のものである。 挑戦してみる用意はあるだろうか? <<導入>> このゲームの名前は「Petals Around the Rose(バラの周りの花びら)」。 名前はこのゲームにおいて重要な要素である。 まずはじめに、プログラムは5つの采を投げる。 そして、プレイヤーはその5つの采を見て、それの示すスコアを推測する。 スコアは常に0点か、偶数となる。 プレイヤーは振られた5つの采からプログラムがどのようにスコアを算出しているかを解き明かさなければならない。 そしてその真相をつかんだプレイヤーだけが、Potentate of the Rose(バラの支配者)となれる。 エンターキーを押して采を振り、采の目の示すスコアを推測して入力すると、その推測の正誤、またプログラムの算出した正しいスコアが確認できる。 そしてまたエンターキーを押せばもう一度采が振られるし、またはただウィンドウを閉じてゲームをやめてもいい。 *ゲームを楽しむ前に* このゲームの真相を暴くことに成功した人はPotentate of the Roseとなり the Fraternity of Petals Around the Rose(Petals Around the Rose同好会)のメンバーとなることができる。 (http://www.borrett.id.au/computing/petals-frat.htm) しかし、もしこの真相がわかってもそれをほかの人にばらしてしまうことは決して許されない。 心を鬼にして秘密を漏らさないと誓うことが要求される。 つまり自分の力でこの真相を解き明かすことのできる者たちだけが、このゲームの秘密を共有することができるのである。 プレイヤーたちの幸運を祈る。 コード: #console '--------------------------------------------- ' Petals Around the Rose Ver0.01 ' powered by AONIRO ' 2007 Lloyd Borrett. All rights reserved. ' www.borrett.id.au '--------------------------------------------- Dim a As Long Dim b As Long Dim c As Long Dim d As Long Dim e As Long Dim s As Long Dim t As Long Dim u As Long Dim v As Long Dim w As Long Dim x As Long Dim y As String Print "●○●Petals Around the Rose●○●" Print "Is Petals Around the Rose really a game? Well actually it's more of a puzzle or a brain teaser. Are you up to the challenge?" Print "<<Introduction>>" Print "The name of the game is Petals Around the Rose." Print "The name of the game is important." Print "The program will roll five dice and ask you to guess the score for the roll." Print "The score will always be zero or an even number." Print "Your mission is to work out how the program calculates the score and become a Potentate of the Rose." Print "Push the enter key to start the game and enter your guess to check the result." Print "Then either push the enter key for another turn, or simply close this window to stop playing." Print "" Print "*Please read the following before playing*" Print "If you succeed in working out the secret to the challenge, you become a Potentate of the Rose and qualify to become a member of the Fraternity of Petals Around the Rose.(http://www.borrett.id.au/computing/petals-frat.htm)" Print "However, you must pledge to be a cruel and heartless wretch who will never divulge the secret of the game to anyone else." Print "Only those that can work it out for themselves should know the secret of Petals Around the Rose." Print "Good luck!" Print "" Do Input "[Roll Dice] :Please push the enter key.",s If s = "" then Print ""; Else Print ""; EndIf Randomize 'a,b,c,d,eはそれぞれ采の名前 'Rndは采の目に対応する6つの数字(0~5)を扱う 'それぞれ0は1の目、0は2の目、・・・5は采の目の6を表す a = Fix(Rnd() * 6) b = Fix(Rnd() * 6) c = Fix(Rnd() * 6) d = Fix(Rnd() * 6) e = Fix(Rnd() * 6) '一行目 Print "| ̄ ̄ ̄ ̄ ̄|| ̄ ̄ ̄ ̄ ̄|| ̄ ̄ ̄ ̄ ̄|| ̄ ̄ ̄ ̄ ̄|| ̄ ̄ ̄ ̄ ̄|" '二行目 采a If a = 0 then Print "| |"; Elseif a => 1 and a =< 2 then Print "| ● |"; Elseif a => 3 and a =< 5 then Print "| ● ● |"; Endif '二行目 采b If b = 0 then Print "| |"; Elseif b => 1 and b =< 2 then Print "| ● |"; Elseif b => 3 and b =< 5 then Print "| ● ● |"; Endif '二行目 采c If c = 0 then Print "| |"; Elseif c => 1 and c =< 2 then Print "| ● |"; Elseif c => 3 and c =< 5 then Print "| ● ● |"; Endif '二行目 采d If d = 0 then Print "| |"; Elseif d => 1 and d =< 2 then Print "| ● |"; Elseif d => 3 and d =< 5 then Print "| ● ● |"; Endif '二行目 采e If e = 0 then Print "| |" Elseif e => 1 and e =< 2 then Print "| ● |" Elseif e => 3 and e =< 5 then Print "| ● ● |" Endif '三行目 采a If a = 0 or a = 2 or a = 4 then Print "| ● |"; Elseif a = 1 or a = 3 then Print "| |"; Elseif a = 5 then Print "| ● ● |"; Endif '三行目 采b If b = 0 or b = 2 or b = 4 then Print "| ● |"; Elseif b = 1 or b = 3 then Print "| |"; Elseif b = 5 then Print "| ● ● |"; Endif '三行目 采c If c = 0 or c = 2 or c = 4 then Print "| ● |"; Elseif c = 1 or c = 3 then Print "| |"; Elseif c = 5 then Print "| ● ● |"; Endif '三行目 采d If d = 0 or d = 2 or d = 4 then Print "| ● |"; Elseif d = 1 or d = 3 then Print "| |"; Elseif d = 5 then Print "| ● ● |"; Endif '三行目 采e If e = 0 or e = 2 or e = 4 then Print "| ● |" Elseif e = 1 or e = 3 then Print "| |" Elseif e = 5 then Print "| ● ● |" Endif '四行目 采a If a = 0 then Print "| |"; Elseif a => 1 and a =< 2 then Print "| ● |"; Elseif a => 3 and a =< 5 then Print "| ● ● |"; Endif '四行目 采b If b = 0 then Print "| |"; Elseif b => 1 and b =< 2 then Print "| ● |"; Elseif b => 3 and b =< 5 then Print "| ● ● |"; Endif '四行目 采c If c = 0 then Print "| |"; Elseif c => 1 and c =< 2 then Print "| ● |"; Elseif c => 3 and c =< 5 then Print "| ● ● |"; Endif '四行目 采d If d = 0 then Print "| |"; Elseif d => 1 and d =< 2 then Print "| ● |"; Elseif d => 3 and d =< 5 then Print "| ● ● |"; Endif '四行目 采e If e = 0 then Print "| |" Elseif e => 1 and e =< 2 then Print "| ● |" Elseif e => 3 and e =< 5 then Print "| ● ● |" Endif '五行目 Print "|_____||_____||_____||_____||_____|" If a+1 = 3 then u=u+2 Elseif a+1 = 5 then u=u+4 Endif If b+1 = 3 then u=u+2 Elseif b+1 = 5 then u=u+4 Endif If c+1 = 3 then u=u+2 Elseif c+1 = 5 then u=u+4 Endif If d+1 = 3 then u=u+2 Elseif d+1 = 5 then u=u+4 Endif If e+1 = 3 then u=u+2 Elseif e+1 = 5 then u=u+4 Endif Input "[Your Guess]:",t If t = u then Print "=YES= "; w=w+1 v=v+1 x=x+1 Print "[Total]:";w;" "; Print "[Correct]:";v;" "; Print "[Run]:";x Else Print "=NO= The score is";u;". "; w=w+1 x=0 Print "[Total]:";w;" "; Print "[Correct]:";v;" "; Print "[Run]:";x Endif If x = 6 then Print "Correct again! We think you've probably got it." Elseif x = 10 then Print "Congratulations! We have another Potentate of the Rose." Print "If you want to stop playing, please enter the key [n]." Input "To continue playing, please push the enter key.",y If y = "n" then Print "See you! (´・ω・`)"; Sleep(750) Print "ノ"; Sleep(500) Print "シ"; Print " "; Exit Do Endif Endif Print "" u=0 Loop Until t=100 Sleep(1500) End[/code] |
作成者: | konisi [ 2007年10月10日(水) 00:54 ] |
記事の件名: | |
とりあえず、読みやすいソースコードがあるとどうしてもそっちを読んでしまうので、 このように [ここをクリックすると内容が表示されます] してみました。コード: #console Dim a[4]As Long,s As Long,t As Long,u As Long,v As Long,w As Long,x As Long,y As String,i As Long Print "●○●Petals Around the Rose●○●" Print "Is Petals Around the Rose really a game? Well actually it's more of a puzzle or a brain teaser. Are you up to the challenge?" Print "<<Introduction>>" Print "The name of the game is Petals Around the Rose." Print "The name of the game is important." Print "The program will roll five dice and ask you to guess the score for the roll." Print "The score will always be zero or an even number." Print "Your mission is to work out how the program calculates the score and become a Potentate of the Rose." Print "Push the enter key to start the game and enter your guess to check the result." Print "Then either push the enter key for another turn, or simply close this window to stop playing." Print "" Print "*Please read the following before playing*" Print "If you succeed in working out the secret to the challenge, you become a Potentate of the Rose and qualify to become a member of the Fraternity of Petals Around the Rose.(http://www.borrett.id.au/computing/petals-frat.htm)" Print "However, you must pledge to be a cruel and heartless wretch who will never divulge the secret of the game to anyone else." Print "Only those that can work it out for themselves should know the secret of Petals Around the Rose." Print "Good luck!" Print "" Do Input "[Roll Dice] :Please push the enter key.",s Print ""; Randomize For i=0 To 4:a=Fix(Rnd()*6):Next:Print "| ̄ ̄ ̄ ̄ ̄|| ̄ ̄ ̄ ̄ ̄|| ̄ ̄ ̄ ̄ ̄|| ̄ ̄ ̄ ̄ ̄|| ̄ ̄ ̄ ̄ ̄|" For i=0 To 4:If a then If a<3 then Print "| ● |";else Print "| ● ● |";else Print "| |"; Next:Print "":For i=0 To 4:If aand 1 then If a-5 then Print "| |";else Print "| ● ● |";else Print "| ● |"; Next:Print "":For i=0 To 4:If a then If a<3 then Print "| ● |";else Print "| ● ● |";else Print "| |"; Next:Print Ex"\r\n|_____||_____||_____||_____||_____|":For i=0 To 4:If not aand 1 then u+=a Next:Input "[Your Guess]:",t:w++:If t=u then v++:x++:Print "=YES= [Total]:";w;" [Correct]:";v;" [Run]:";x else x=0:Print "=NO= The score is";u;". [Total]:";w;" [Correct]:";v;" [Run]:";x If x=6 then Print "Correct again! We think you've probably got it." If x=10 then Print Ex"Congratulations! We have another Potentate of the Rose.\r\nIf you want to stop playing, please enter the key [n]." Input "To continue playing, please push the enter key.",y If y="n" then Print "See you! (´・ω・`)";:Sleep(750):Print "ノ";:Sleep(500):Print "シ ";:Exit Do Endif Print "":u=0 Loop Until t=100 Sleep(1500) End 今更無意味です。4.20以上でコンパイルできるはずです。(当方4.23) |
作成者: | AONIRO [ 2007年10月11日(木) 19:05 ] |
記事の件名: | ありがとうございます! |
あんなに長くてウンザリな感じだったコードがこんなに短くなるなんてプログラミングってすごいですね。 まだ見てもぜんぜん何がどうなってるのか私にはわかりませんが、すごく面白そうです。 暇ができたらこれぐらい書けるようになってみたいです。とても興味が沸きました。 ありがとうございました! |
作成者: | konisi [ 2007年10月11日(木) 21:42 ] |
記事の件名: | |
どういたしまして。 コードを短くする努力(単調な処理をまとめる程度の努力)は、したほうがいいとは思いますが、 読みにくいコードを書く努力はしなくてもいいと思います。 #コンパイラの限界を知っておくことは有意義だと思いますが。 コードの変更内容と詳しくない解説(見りゃ分かるんだが読みにくいんで。) [ここをクリックすると内容が表示されます]
・サイコロの内容(a,b,c,d,e)を配列aにした。 条件分岐を改造した。(意味は変えてない。) [ここをクリックすると内容が表示されます] コード: If a = 0 then Print "| |"; Elseif a => 1 and a =< 2 then Print "| ● |"; Elseif a => 3 and a =< 5 then Print "| ● ● |"; Endifこいつが コード: For i=0 To 4 If a=0 then Print "| |"; Elseif a=> 1 and a=< 2 then Print "| ● |"; Elseif a=> 3 and a=< 5 then Print "| ● ● |"; End If Nextのようになって、最終的に コード: For i=0 To 4 If a then'aが0でないなら If a<3 then Print "| ● |"; Else Print "| ● ● |"; End If Else'aが0のとき Print "| |"; End If Nextこうなった。 [ここをクリックすると内容が表示されます] コード: If a = 0 or a = 2 or a = 4 then Print "| ● |"; Elseif a = 1 or a = 3 then Print "| |"; Elseif a = 5 then Print "| ● ● |"; Endifこいつが コード: For i=0 To 4 If a and 1 then'奇数なら If a[i]-5 then'a[i]-5が0で無ければ Print "| |"; Else'a[i]-5が0なら→a[i]=5なら Print "| ● ● |"; End If Else'偶数なら Print "| ● |"; End If Nextこうなって コード: If a+1 = 3 then u=u+2 Elseif a+1 = 5 then u=u+4 Endifこいつが コード: For i=0 To 4 if not a[i] and 1 then u=u+a[i]'値が偶数なら加算 Nextこうなった。 |
ページ 1 / 1 | 全ての表示時間は UTC+09:00 です |
Powered by phpBB® Forum Software © phpBB Limited https://www.phpbb.com/ |