home
***
CD-ROM
|
disk
|
FTP
|
other
***
search
/
FreeWare Collection 2
/
FreeSoftwareCollection2pd199x-jp.img
/
ms_dos
/
life
/
life.bas
next >
Wrap
BASIC Source File
|
1990-06-14
|
11KB
|
617 lines
'==================================================================
'*LIFE GAME by ASF
'*(LIFE.EXE v0.8)
'*1990.5.10
'*for FM TOWNS /FMR50(ms-dos v3.1)
'==================================================================
'*data load/save用のディレクトリを環境変数("LIFE")で指定する。
' SET LIFE=XXXXXXXXXX
'
DECLARE SUB PtrEdit ()
DECLARE SUB NextGen ()
DECLARE SUB Plot (x%, y%, col%)
DECLARE SUB Gcur (x1%, y1%, x2%, y2%)
DECLARE SUB ChrClr (l%, c%, clm%, lin%)
DECLARE SUB DrawMat ()
DECLARE SUB DataLoad (switch%)
DECLARE SUB DataSave (switch%)
DECLARE SUB PtrClear ()
DECLARE SUB LineCur (x%, y%, col%)
DECLARE FUNCTION FileCheck% (path$, filename$)
DECLARE FUNCTION GetFileName$ ()
DECLARE FUNCTION EndChk% ()
DECLARE FUNCTION Break% ()
DEFINT A-Z
COMMON SHARED Scnt: '石の総数
COMMON SHARED path$: '環境変数保存用
COMMON SHARED Flag: '誕生・死滅のチェック
'*座標データ
DIM SHARED PrePtr(0 TO 99, 0 TO 99)
DIM SHARED NxtPtr(0 TO 99, 0 TO 99)
'環境変数のチェック
path$ = ENVIRON$("LIFE")
SELECT CASE path$
CASE ""
path$ = "\"
CASE ELSE
IF RIGHT$(path$, 1) <> "\" THEN path$ = path$ + "\"
END SELECT
ON ERROR GOTO errTrap
PRINT "LIFE GAME ver 0.8 だよぉ (By ASF)"
SCREEN 0, 3, 0, 1: '描いているところを見ないように・・・・
DrawMat
PALETTE
PALETTE 1, &H37
PALETTE 0, &H444
'* タイトル
CLS 2
COLOR 3
LOCATE 2, 58: PRINT "*****************"
LOCATE 3, 58: PRINT "* LIFE GAME *"
LOCATE 4, 58: PRINT "* Ver 0.8 *"
LOCATE 5, 58: PRINT "* By ASF *"
LOCATE 6, 58: PRINT "*****************"
SCREEN , , , 0
start:
PtrEdit
LOCATE 20, 53: PRINT "中断 = anykey"
LOCATE 8, 55: PRINT "世代 ="
LOCATE 9, 55: PRINT "石数 ="
gen = 1
'*main
DO
gen = gen + 1
NextGen
LOCATE 8, 62: PRINT gen
LOCATE 9, 62: PRINT Scnt
IF INKEY$ <> "" THEN
SELECT CASE Break
CASE 1
COLOR 3
ChrClr 11, 55, 17, 5
CASE 2
COLOR 3
ChrClr 11, 55, 17, 5
E = 0
EXIT DO
CASE ELSE
COLOR 7
CLS
PALETTE
END
END SELECT
END IF
E = EndChk
LOOP UNTIL E <> 0
'* end
SELECT CASE E
CASE 0
'編集画面(^_^;)に戻る
PtrClear
ERASE NxtPtr
GOTO start
CASE 1
LOCATE 19, 10: PRINT "死滅しました"
CASE 2
LOCATE 19, 10: PRINT "完全に安定しました"
CASE 3
LOCATE 19, 10: PRINT "境界に達しました"
END SELECT
LOCATE 21, 10: PRINT "終了しますか < Y / anykey > "
VIEW PRINT 22 TO 23
PRINT TAB(10);
INPUT ; i$
VIEW PRINT
IF i$ = "Y" OR i$ = "y" THEN
CLS
COLOR 7
PALETTE
END
ELSE
ChrClr 19, 10, 30, 4
ERASE NxtPtr
PtrClear
GOTO start
END IF
'-------------------------
errTrap:
RESUME NEXT
FUNCTION Break
'中断処理
COLOR 20: '←これが曲者・・・FMRだとブリンクしちゃいます
LOCATE 11, 55: PRINT " **中断** "
LOCATE 12, 55: PRINT " 1) 継続 "
LOCATE 13, 55: PRINT " 2) 編集 "
LOCATE 14, 55: PRINT " 3) 終了 "
LOCATE 15, 55: PRINT " < push 1 - 3 > "
DO
i = VAL(INKEY$)
LOOP WHILE i < 1 OR i > 3
Break = i
END FUNCTION
SUB ChrClr (l, c, clm, lin)
'指定されたキャラクタ座標からclm個,lin行のスペースを出力する
FOR x = 1 TO lin
LOCATE l, c, 0: PRINT SPACE$(clm);
l = l + 1
NEXT
END SUB
SUB DataLoad (s)
's=0:life.dat用、s=1:その他
IF s = 0 THEN
IF FileCheck(path$, "LIFE.DAT") = 1 THEN
filename$ = "life.dat"
ELSE
EXIT SUB
END IF
ELSE
filename$ = GetFileName$
END IF
IF filename$ = "" THEN EXIT SUB
PtrClear
filename$ = path$ + filename$
OPEN filename$ FOR INPUT AS #1
s$ = INPUT$(4, #1)
Scnt = VAL(s$)
LOCATE 9, 55, 0: PRINT "石数 ="; Scnt
FOR i = 1 TO Scnt
x = VAL(INPUT$(4, #1))
y = VAL(INPUT$(4, #1))
Plot x, y, 7
PrePtr(x, y) = 1
NEXT
CLOSE
END SUB
SUB DataSave (s)
's=0:life.dat用、s=1:その他
IF s = 0 THEN
filename$ = path$ + "life.dat"
ELSE
LOCATE 12, 55: PRINT "ファイル名";
LOCATE 14, 55: PRINT " ~~~~~~~~"
LOCATE 13, 55: INPUT ; f$
filename$ = RTRIM$(f$)
ChrClr 12, 55, 25, 3
IF filename$ = "" THEN EXIT SUB
'拡張子を無視する
c = INSTR(filename$, ".")
IF c = 0 THEN c = 9
filename$ = path$ + LEFT$(filename$, c - 1) + ".lif"
END IF
OPEN filename$ FOR OUTPUT AS #1
'エラートラップ後の処理
IF ERR = 36 OR ERR = 76 THEN
BEEP
ChrClr 12, 55, 25, 3
PRINT SPACE$(50)
EXIT SUB
END IF
PRINT #1, USING "####"; Scnt;
FOR y = 1 TO 98
FOR x = 1 TO 98
IF PrePtr(x, y) THEN
PRINT #1, USING "####"; x; y;
END IF
NEXT
NEXT
PRINT #1, " "
CLOSE
LOCATE 13, 57: PRINT SPACE$(LEN(f$));
END SUB
SUB DrawMat
'ます目を描く
LINE (2, 2)-(398, 398), 2, BF
LINE (4, 4)-(396, 396), 0, BF
LINE (4, 4)-(396, 396), 1, B
FOR i = 8 TO 392 STEP 4
LINE (5, i)-(395, i), 1
LINE (i, 5)-(i, 395), 1
NEXT
END SUB
FUNCTION EndChk STATIC
'終了チェック 1:石が無くなった 2:完全に安定した 3:境界に達した
IF Scnt = 0 THEN
EndChk = 1
EXIT FUNCTION
END IF
IF Flag = 0 THEN
EndChk = 2
EXIT FUNCTION
END IF
FOR i = 1 TO 98
IF NxtPtr(i, 1) + NxtPtr(i, 98) + NxtPtr(1, i) + NxtPtr(98, i) THEN
EndChk = 3
EXIT FUNCTION
END IF
NEXT
EndChk = 0
END FUNCTION
FUNCTION FileCheck (p$, f$)
'ファイルの有無を調べる
'ファイル名は、大文字で入力する
LOCATE 10, 10, 0
SHELL "dir " + p$ + f$ + " > dummy"
f$ = RTRIM$(LEFT$(f$, INSTR(f$, ".") - 1))
OPEN "dummy" FOR INPUT AS #1
DO UNTIL EOF(1)
LINE INPUT #1, a$
IF RTRIM$(LEFT$(a$, 1)) <> "" AND INSTR(a$, f$) <> 0 THEN
FileCheck = 1
CLOSE
KILL "dummy"
EXIT FUNCTION
END IF
LOOP
CLOSE
KILL "dummy"
ChrClr 9, 10, 25, 2
FileCheck = 0
END FUNCTION
SUB Gcur (x1, y1, x2, y2)
'グラフィックカーソル
'x1,y1=old ,x2,y2=new:x2=y2=0→カーソルオフ
IF x2 + y2 = 0 THEN
LINE (x1 * 4, y1 * 4)-STEP(4, 4), 1, B
EXIT SUB
END IF
LINE (x1 * 4, y1 * 4)-STEP(4, 4), 1, B
LINE (x2 * 4, y2 * 4)-STEP(4, 4), 12, B
END SUB
FUNCTION GetFileName$
'
'ここは、qbに付いてくる sampleをかなり「参考」にしてます(^^;)
' ~~~~~~
DIM file$(99)
SCREEN , , 1, 1
LOCATE 10, 10, 0
SHELL "dir " + path$ + "*.lif > dummy"
OPEN "DUMMY" FOR INPUT AS #1
DO UNTIL EOF(1)
LINE INPUT #1, a$
IF RTRIM$(LEFT$(a$, 1)) <> "" AND INSTR(a$, "<DIR>") = 0 THEN
N = N + 1
file$(N) = RTRIM$(LEFT$(a$, 8))
END IF
LOOP
CLOSE
KILL "DUMMY"
IF N = 0 THEN
GetFileName$ = ""
BEEP
SCREEN , , 0, 0
EXIT FUNCTION
END IF
LOCATE 1, 1: PRINT " <" + path$ + " *.lif > 取消 = [ESC]"
DO
z = z + 1
PRINT USING " & & "; file$(z);
IF (z) MOD 5 = 0 THEN PRINT
LOOP UNTIL z > N
px = 1: py = 2
x = 1: y = 2: z = 1
DO
LineCur x, y, 4
a$ = INKEY$
SELECT CASE a$
CASE CHR$(0, 72)
LineCur x, y, 0
y = y - 1: IF y < 2 THEN y = 2
CASE CHR$(0, 75)
LineCur x, y, 0
x = (x + 3) MOD 5 + 1
CASE CHR$(0, 77)
LineCur x, y, 0
x = (x) MOD 5 + 1
CASE CHR$(0, 80)
LineCur x, y, 0
y = y + 1
CASE CHR$(&HD)
z = (y - 2) * 5 + x
GetFileName$ = file$(z) + ".lif"
CASE CHR$(&H1B)
ChrClr 1, 1, 50, 20
CLS 1
SCREEN , , 0, 0
EXIT FUNCTION
END SELECT
z = (y - 2) * 5 + x
IF z > N THEN
y = 2
a$ = ""
END IF
LOOP WHILE a$ <> CHR$(&HD)
ChrClr 1, 1, 50, 20
LineCur x, y, 0
SCREEN , , 0, 0
END FUNCTION
SUB LineCur (x, y, col)
'
LINE ((x - 1) * 80, (y - 1) * 16)-STEP(79, 15), col, BF
END SUB
SUB NextGen STATIC
'ここがほんとのメイン部分
'c = 周囲の石数(自分自身も含む)
Scnt = 0
Flag = 0
FOR y = 1 TO 98
FOR x = 1 TO 98
c = PrePtr(x + 1, y - 1) + PrePtr(x - 1, y - 1) + PrePtr(x, y - 1) + PrePtr(x + 1, y) + PrePtr(x - 1, y) + PrePtr(x + 1, y + 1) + PrePtr(x - 1, y + 1) + PrePtr(x, y + 1) + PrePtr(x, y)
IF c = 0 GOTO L1
IF PrePtr(x, y) THEN
IF c = 4 OR c = 3 THEN
NxtPtr(x, y) = 1: '生存
Scnt = Scnt + 1
ELSE
NxtPtr(x, y) = 0: '死滅
LINE (x * 4 + 1, y * 4 + 1)-STEP(2, 2), 0, BF
Flag = 1
END IF
ELSEIF c = 3 THEN
NxtPtr(x, y) = 1: '誕生
Scnt = Scnt + 1
LINE (x * 4 + 1, y * 4 + 1)-STEP(2, 2), 7, BF
Flag = 1
END IF
L1:
NEXT x
NEXT y
'
'* データの入れ換え
'
FOR y = 1 TO 98
FOR x = 1 TO 98
PrePtr(x, y) = NxtPtr(x, y)
NEXT
NEXT
END SUB
SUB Plot (x, y, col) STATIC
'石を描く&消す
LINE (x * 4 + 1, y * 4 + 1)-STEP(2, 2), col, BF
END SUB
SUB PtrClear
'
FOR y = 1 TO 98
FOR x = 1 TO 98
IF PrePtr(x, y) THEN Plot x, y, 0
NEXT
NEXT
ERASE PrePtr
Scnt = 0
LOCATE 9, 55: PRINT "石数 = 0 "
END SUB
SUB PtrEdit
'パターン編集
x = 49: y = 49
LOCATE 8, 55: PRINT "世代 = 1 "
LOCATE 9, 55: PRINT "石数 = 0 "
LOCATE 15, 52: PRINT "< パターン編集 >"
LOCATE 16, 52: PRINT "SET & UNSET = [SPACE]"
LOCATE 17, 52: PRINT "データロード= [L]"
LOCATE 18, 52: PRINT "データセーブ= [S]"
LOCATE 19, 52: PRINT "クリア = [C]"
LOCATE 20, 52: PRINT "EDIT 終了 = [C R]"
DataLoad 0: 'life.datを読み込む
ChrClr 9, 10, 30, 2
Gcur x, y, x, y: 'カーソルオン
'石入力用ループ
DO
i$ = INKEY$
SELECT CASE i$
CASE CHR$(0, &H48): 'up
IF y = 1 THEN
Gcur x, y, x, 98
y = 98
ELSE
Gcur x, y, x, y - 1
y = y - 1
END IF
CASE CHR$(0, &H4B): 'left
IF x = 1 THEN
Gcur x, y, 98, y
x = 98
ELSE
Gcur x, y, x - 1, y
x = x - 1
END IF
CASE CHR$(0, &H4D): 'right
IF x = 98 THEN
Gcur x, y, 1, y
x = 1
ELSE
Gcur x, y, x + 1, y
x = x + 1
END IF
CASE CHR$(0, &H50): 'down
IF y = 98 THEN
Gcur x, y, x, 1
y = 1
ELSE
Gcur x, y, x, y + 1
y = y + 1
END IF
CASE CHR$(0, &H47): 'home
Gcur x, y, 49, 49
x = 49: y = 49
CASE " ": 'set&unset
IF PrePtr(x, y) THEN
PrePtr(x, y) = 0: 'unset
Plot x, y, 0
Scnt = Scnt - 1
LOCATE 9, 55: PRINT "石数 ="; Scnt
ELSE
PrePtr(x, y) = 1: 'set
Plot x, y, 7
Scnt = Scnt + 1
LOCATE 9, 55: PRINT "石数 ="; Scnt
END IF
CASE CHR$(&HD): 'exit
IF Scnt = 0 THEN
LOCATE 21, 52: PRINT "石が有りません・・・"
LOCATE 22, 52: PRINT "終了しますか(Y/anykey)"
VIEW PRINT 23 TO 24
PRINT TAB(52);
INPUT ; i$
CLS 2
IF i$ = "y" OR i$ = "Y" THEN
COLOR 7
CLS
PALETTE
END
ELSE
VIEW PRINT 1 TO 23
ChrClr 21, 52, 24, 3
END IF
ELSE
LOCATE 21, 52: PRINT "OK (Y/anykey)"
VIEW PRINT 22 TO 23
PRINT TAB(52);
INPUT ; i$
CLS 2
VIEW PRINT 1 TO 23
IF i$ = "y" OR i$ = "Y" THEN
EXIT DO
ELSE
ChrClr 21, 52, 23, 3
END IF
END IF
CASE "c", "C": 'pattern clear
Gcur x, y, 0, 0
PtrClear
Gcur x, y, x, y
CASE "l", "L": 'data load
Gcur x, y, 0, 0
DataLoad 1
ChrClr 9, 10, 30, 2
Gcur x, y, x, y
CASE "s", "S": 'data save
DataSave 1
END SELECT
LOOP
'カーソルを消す
Gcur x, y, 0, 0
ChrClr 15, 52, 25, 7
DataSave 0: 'life.datをセーブ
END SUB