不思議のダンジョンいじってみた【メモ:関数】
投稿者:
fragile
投稿日:2013/06/01 15:19
【存在しないブログ記事です】をもとにつくってみた。 : qaz/wsx(スペースで高速)
次の値がいじれるように
floorとかの動作がちと怪しいな...
SEARCHも1番目じゃなくて適当に選んでくれたらな...
↓今更だけどなんで色逆?
ツイート
次の値がいじれるように
- 部屋の数の縦横の最大値
- 部屋の広さの縦横の最大値
- 廊下の広さの縦横の最大値(幅は変更不可)
- 部屋のできやすさ
- 描画用に周囲何マスを空けるか
- 通常の2倍の大部屋を何部屋作るか
- ちょっとしたつぶやき
floorとかの動作がちと怪しいな...
SEARCHも1番目じゃなくて適当に選んでくれたらな...
↓今更だけどなんで色逆?
"あああ" #あああ
def RAND(n)#とりあえず自分が必要なもの
a=createArray()
i=0
while i < n
a[i] = i
i=i+1
end
i=0
while i < n
x = rand(n)
y = a[i]
a[i] = a[n]
a[n] = y
i=i+1
end
return a
end
##########################################################################
setTextFontSize(4)
setTextViewMode(0)
setVariable("text", createText(5, 5, 790, 590))
def square(y1, x1, y2, x2, array, k) #方形代入
if y1 > y2
n = y1
y1 = y2
y2 = n
end
if x1 > x2
n = x1
x1 = x2
x2 = n
end
X = x1
while y1 <= y2
x1 = X
while x1 <= x2
array[y1][x1] = k
x1 = x1 + 1
end
y1 = y1 + 1
end
return array
end
############################################
def SARCH(array, k)#二次元配列の検索
n = createArray()
i = 0
while i < getArrayLength(array)
I = 0
while I < getArrayLength(array[i])
if array[i][I] == k
n[0] = i
n[1] = I
return n
end
I = I + 1
end
i = i + 1
end
n[0] = -1
n[1] = -1
return n
end
############################################
############################################
def createDangeon()
#配列の宣言
R = createArray()
D = createArray()
F = createArray()
S = createArray()
#配列を二次に
i=0
while i < getVariable("横の部屋数")
R[i] = createArray()
D[i] = createArray()
F[i] = createArray()
i=i+1
end
#配列の初期設定
R = square(0, 0, getVariable("縦の部屋数")-1, 0, R, 1)
R = square(0, 1, getVariable("縦の部屋数")-1, getVariable("横の部屋数")-2, R, -1)
R = square(0, getVariable("横の部屋数")-1, getVariable("縦の部屋数")-1, getVariable("横の部屋数")-1, R, 1)
D = square(0, 0, 0, getVariable("横の部屋数")-1, D, 1)
D = square(1, 0, getVariable("縦の部屋数")-2, getVariable("横の部屋数")-1, D, -1)
D = square(getVariable("縦の部屋数")-1, 0, getVariable("縦の部屋数")-1, getVariable("横の部屋数")-1, D, 1)
F = square(0, 0, getVariable("縦の部屋数")-1, 0, F, -1)
F = square(0, 1, 0, getVariable("横の部屋数")-1, F, -1)
F = square(1, 1, getVariable("縦の部屋数")-1, getVariable("横の部屋数")-1, F, 0)
#配列を二次に
i=0
while i < 2*getVariable("周囲何マス空けるか") + getVariable("縦の部屋数")*(getVariable("部屋の縦の長さ")+getVariable("廊下の縦の長さ"))
S[i] = createArray()
i=i+1
end
#同じく初期設定
S = square(0, 0, 2*getVariable("周囲何マス空けるか") + getVariable("縦の部屋数")*(getVariable("部屋の縦の長さ")+getVariable("廊下の縦の長さ")) -1, 2*getVariable("周囲何マス空けるか") + getVariable("横の部屋数")*(getVariable("部屋の横の長さ")+getVariable("廊下の横の長さ")), S, 1)
#ダンジョンの基準になる部屋を設定
Y = floor(getVariable("縦の部屋数")/2)
X = floor(getVariable("横の部屋数")/2)
F[Y][X] = 1
first = rand(4)
k = SARCH(F, 1) #処理待ちの部屋を探す
Y = k[0]
X = k[1]
while Y != -1
if D[Y-1][X] == -1 #上の壁が未処理なら
if (first==0) || (rand(100) < getVariable("部屋ができる確率")) #**%で
F[Y-1][X] = 1 #上の部屋を処理待ちに
D[Y-1][X] = 0 #「上の部屋との間の壁には通路がある」
red = getVariable("周囲何マス空けるか")+Y*(getVariable("部屋の縦の長さ")+getVariable("廊下の縦の長さ")) + rand(3) + floor(getVariable("部屋の縦の長さ")/2)-1
blue = getVariable("周囲何マス空けるか")+X*(getVariable("部屋の横の長さ")+getVariable("廊下の横の長さ")) + rand(3) + floor(getVariable("部屋の横の長さ")/2)-1
S = square(red, blue, red-getVariable("部屋の縦の長さ")-getVariable("廊下の縦の長さ"), blue, S, 0) #道を作る
else
D[Y-1][X] = 1 #道を作らない
end
end
if D[Y][X] == -1 #下の壁が~
if (first==1) || (rand(100) < getVariable("部屋ができる確率"))
F[Y+1][X] = 1
D[Y][X] = 0
red = getVariable("周囲何マス空けるか")+Y*(getVariable("部屋の縦の長さ")+getVariable("廊下の縦の長さ")) + rand(3) + floor(getVariable("部屋の縦の長さ")/2)-1
blue = getVariable("周囲何マス空けるか")+X*(getVariable("部屋の横の長さ")+getVariable("廊下の横の長さ")) + rand(3) + floor(getVariable("部屋の横の長さ")/2)-1
S = square(red, blue, red+getVariable("部屋の縦の長さ")+getVariable("廊下の縦の長さ"), blue, S, 0)
else
D[Y][X] = 1
end
end
if R[Y][X-1] == -1 #左の壁が~
if (first==2) || (rand(100) < getVariable("部屋ができる確率"))
F[Y][X-1] = 1
R[Y][X-1] = 0
red = getVariable("周囲何マス空けるか")+Y*(getVariable("部屋の縦の長さ")+getVariable("廊下の縦の長さ")) + rand(3) + floor(getVariable("部屋の縦の長さ")/2)-1
blue = getVariable("周囲何マス空けるか")+X*(getVariable("部屋の横の長さ")+getVariable("廊下の横の長さ")) + rand(3) + floor(getVariable("部屋の横の長さ")/2)-1
S = square(red, blue, red, blue-getVariable("部屋の横の長さ")-getVariable("廊下の横の長さ"), S, 0)
else
R[Y][X-1] = 1
end
end
if R[Y][X] == -1 #右の壁が~
if (first==3) || (rand(100) < getVariable("部屋ができる確率"))
F[Y][X+1] = 1
R[Y][X] = 0
red = getVariable("周囲何マス空けるか")+Y*(getVariable("部屋の縦の長さ")+getVariable("廊下の縦の長さ")) + rand(3) + floor(getVariable("部屋の縦の長さ")/2)-1
blue = getVariable("周囲何マス空けるか")+X*(getVariable("部屋の横の長さ")+getVariable("廊下の横の長さ")) + rand(3) + floor(getVariable("部屋の横の長さ")/2)-1
S = square(red, blue, red, blue+getVariable("部屋の横の長さ")+getVariable("廊下の横の長さ"), S, 0)
else
R[Y][X] = 1
end
end
first = 4
i=0
W = ""
while i < getArrayLength(S)
W = W+S[i]+"\n"
i=i+1
end
waitTime(400)
setText(getVariable("text"), W)
#今いる場所に部屋を作る
S = square(getVariable("周囲何マス空けるか")+Y*(getVariable("部屋の縦の長さ")+getVariable("廊下の縦の長さ"))+rand(floor(getVariable("部屋の縦の長さ")/2-3/2)), getVariable("周囲何マス空けるか")+X*(getVariable("部屋の横の長さ")+getVariable("廊下の横の長さ"))+rand(floor(getVariable("部屋の横の長さ")/2-3/2)),
getVariable("周囲何マス空けるか")+(Y+1)*(getVariable("部屋の縦の長さ")+getVariable("廊下の縦の長さ"))-getVariable("廊下の縦の長さ")-rand(floor(getVariable("部屋の縦の長さ")/2-3/2)), getVariable("周囲何マス空けるか")+(X+1)*(getVariable("部屋の横の長さ")+getVariable("廊下の横の長さ"))-getVariable("廊下の横の長さ")-rand(floor(getVariable("部屋の横の長さ")/2-3/2)), S, 0)
i=0
W = ""
while i < getArrayLength(S)
W = W+S[i]+"\n"
i=i+1
end
waitTime(400)
setText(getVariable("text"), W)
#今の部屋を処理済みに
F[Y][X] = 2
#処理待ち探し
k = SARCH(F, 1)
Y = k[0]
X = k[1]
end
#ここからは大部屋作り。
########################
#SEARCHを他の機能で代用する必要あり#
########################
large = getVariable("大部屋")
while 0 < large
n = SARCH(F, 2)
if n[0] == -1
large = 0
else
F[n[0]][n[1]] = 3
try=0
k=rand(4)
while try < 4
k = (k+1)%4
case k
when 0 if D[n[0]-1][n[1]] == 0 #上
F[n[0]-1][n[1]] = 3
S = square(getVariable("周囲何マス空けるか")+(n[0]-1)*(getVariable("部屋の縦の長さ")+getVariable("廊下の縦の長さ")), getVariable("周囲何マス空けるか")+n[1]*(getVariable("部屋の横の長さ")+getVariable("廊下の横の長さ")), getVariable("周囲何マス空けるか")+(n[0]+1)*(getVariable("部屋の縦の長さ")+getVariable("廊下の縦の長さ"))-getVariable("廊下の縦の長さ"), getVariable("周囲何マス空けるか")+(n[1]+1)*(getVariable("部屋の横の長さ")+getVariable("廊下の横の長さ"))-getVariable("廊下の横の長さ"), S, 0)
try=5
end
when 1 if R[n[0]][n[1]] == 0 #右
F[n[0]][n[1]+1] = 3
S = square(getVariable("周囲何マス空けるか")+n[0]*(getVariable("部屋の縦の長さ")+getVariable("廊下の縦の長さ")), getVariable("周囲何マス空けるか")+n[1]*(getVariable("部屋の横の長さ")+getVariable("廊下の横の長さ")), getVariable("周囲何マス空けるか")+(n[0]+1)*(getVariable("部屋の縦の長さ")+getVariable("廊下の縦の長さ"))-getVariable("廊下の縦の長さ"), getVariable("周囲何マス空けるか")+(n[1]+2)*(getVariable("部屋の横の長さ")+getVariable("廊下の横の長さ"))-getVariable("廊下の横の長さ"), S, 0)
try=5
end
when 2 if D[n[0]][n[1]] == 0 #下
F[n[0]+1][n[1]] = 3
S = square(getVariable("周囲何マス空けるか")+n[0]*(getVariable("部屋の縦の長さ")+getVariable("廊下の縦の長さ")), getVariable("周囲何マス空けるか")+n[1]*(getVariable("部屋の横の長さ")+getVariable("廊下の横の長さ")), getVariable("周囲何マス空けるか")+(n[0]+2)*(getVariable("部屋の縦の長さ")+getVariable("廊下の縦の長さ"))-getVariable("廊下の縦の長さ"), getVariable("周囲何マス空けるか")+(n[1]+1)*(getVariable("部屋の横の長さ")+getVariable("廊下の横の長さ"))-getVariable("廊下の横の長さ"), S, 0)
try=5
end
when 3 if R[n[0]][n[1]-1] == 0 #左
F[n[0]][n[1]-1] = 3
S = square(getVariable("周囲何マス空けるか")+n[0]*(getVariable("部屋の縦の長さ")+getVariable("廊下の縦の長さ")), getVariable("周囲何マス空けるか")+(n[1]-1)*(getVariable("部屋の横の長さ")+getVariable("廊下の横の長さ")), getVariable("周囲何マス空けるか")+(n[0]+1)*(getVariable("部屋の縦の長さ")+getVariable("廊下の縦の長さ"))-getVariable("廊下の縦の長さ"), getVariable("周囲何マス空けるか")+(n[1]+1)*(getVariable("部屋の横の長さ")+getVariable("廊下の横の長さ"))-getVariable("廊下の横の長さ"), S, 0)
try=5
end
end
end
i=0
W = ""
while i < getArrayLength(S)
W = W+S[i]+"\n"
i=i+1
end
setText(getVariable("text"), W)
#if try == 5
#large = 0
#else
large = large-1
#end
end
end
i=0
W = ""
while i < getArrayLength(S)
W = W+S[i]+"\n"
i=i+1
end
setText(getVariable("text"), W)
return S
endsetVariable("縦の部屋数", 7)
setVariable("横の部屋数", 7)
setVariable("部屋の縦の長さ", 7)
setVariable("部屋の横の長さ", 7)
setVariable("廊下の縦の長さ", 3)
setVariable("廊下の横の長さ", 3)
setVariable("周囲何マス空けるか", 1)
setVariable("大部屋", 3)
setVariable("部屋ができる確率", 60)
#表示用にフォントを小さく
setTextFontSize(4)
setTextViewMode(0)
a=createText(5, 5, 790, 590)
while 1
#これ必須。「周囲何マス開けるか」は描画処理に合わせて設定。
setVariable("縦の部屋数", 7)
setVariable("横の部屋数", 7)
setVariable("部屋の縦の長さ", 7)
setVariable("部屋の横の長さ", 7)
setVariable("廊下の縦の長さ", 3)
setVariable("廊下の横の長さ", 3)
setVariable("周囲何マス空けるか", 10)
setVariable("大部屋", 3)
setVariable("部屋ができる確率", 60)
#処理
S = createDangeon()
#一時停止
speak("***")
endコメントする
コメントするには、ログインする必要があります。
コメント一覧
コメントはありません。