2009年12月23日水曜日

How to make an adventure game built on Scheme vol.2

取りあえず何も考えずに上のリンクに従って実装。


;; PLT Scheme 依存

(define-struct scenario
(iKind ;処理の種類(0 -> 通常文章 1-> 選択肢 2-> キー待ち)
pString ;文章
idx1 ;次のシナリオのインデックス(-1で終了)
idx2 ;次のシナリオのインデックス
))

(define *s-aScenario*
(vector
(make-scenario 0 "シナリオ1\n" 1 0)
(make-scenario 1 "選択肢1 -> 1 選択肢2 -> 2\n" 2 3)
(make-scenario 0 "シナリオ2\n" 9 0)
(make-scenario 0 "シナリオ3\n" 4 0)
(make-scenario 1 "選択肢1 -> 1 選択肢2 -> 2\n" 5 6)
(make-scenario 0 "シナリオ4\n" 9 0)
(make-scenario 0 "シナリオ5\n" 7 0)
(make-scenario 2 "Hit Any Key" 8 0)
(make-scenario 0 "シナリオ6\n" 9 0)
(make-scenario 0 "エンドシナリオ\n" -1 0)))

(define (main)
(do ((index 0
(let ((it (vector-ref *s-aScenario* index)))
(case (scenario-iKind it)
((0) (scenario-idx1 it))
((1) (let ((getche (read)))
(if (= getche 1)
(scenario-idx1 it)
(scenario-idx2 it))))
((2) (let ((getche (read)))
(scenario-idx1 it)))))))
((< index 0))
(display (scenario-pString (vector-ref *s-aScenario* index)))))


個人的な好みで言うと、Cのコードってそんなに綺麗と思わない。重複多いし。
Schemeへの翻訳は結構大変だったりします。

vol.3があるかどうかは知らない。

0 件のコメント:

コメントを投稿