パーソナルブログメモリ

a = [1, 1]
for _ in "*" * 999: a += [sum(a[-2:])]
print(a)

アドベンチャーゲームを実装中2

2019-06-04 | Python

目標3日だったのですが2日目で終わってしまいました。

 

想定攻略時間2時間

 

呪文3つ

コマンド10個

階層 見かけは3 実質1

バッドエンド1 トゥルーエンド1

作成時間6時間 テスト&練り直し2時間

 

バグ修正

help:助けを呼ぶとエラーで終了(削除漏れ)

 

 

import time

class Item:
    def __init__(t,x,y,z,msg,d=0):
        t.x, t.y, t.z, t.msg, t.d = x, y, z, msg ,d

def getMove(p,z):
    r=""
    for n,d in zip(["up","down","left","right"],[-11,11,-1,1]):
        np=p+d
        if mp[np]==str(z):
            r+=n+" "
    return r

def getMoveD(dName):
    for n,d in zip(["up","down","left","right","u","d","l","r"],[-11,11,-1,1,-11,11,-1,1]):
        if dName==n:return d

def ItemMsg(p):
    global hp
    for i in item:
        if i.x+i.y*11==p and i.z==0:
            print(i.msg+"と書かれている")
        if i.x+i.y*11==p and i.z==3:
            print(i.msg+"と囁かれている")
        if i.x+i.y*11==p and i.z==4:
            print(i.msg+"と書かれている")
            time.sleep(3)
            print("ダメージを受けた。ここで見てはいけない")
            hp-=1
        if i.x+i.y*11==p and i.z==1:
            print(i.msg+"が落ちている")

def getItem(p):
    for i in item:
        if i.x+i.y*11==p and i.z==1:
            i.z=2
            print(i.msg+"を拾った")
            return
    print("1G 拾った気がした")

def dropItem(p):
    for i in item:
        if i.z==2:
            print(i.msg+"をそっと置いた")
            i.z=1
            i.x,i.y=p%11,int(p/11)
            return
    print("アイテムをもってない")

def getMp(x,y,c):
    if x<0 or y<0 or x>10 or y>10:return "@"
    if mp[x+y*11]==c:return "."
    return "@"

def writeAround(p):
    x,y=p%11,int(p/11)
    for y1 in range(-2,3):
        w=""
        for x1 in range(-2,3):
            w+=getMp(x+x1,y+y1,mp[p])
        print(w)

def black():
    global p
    for i in item:
        if i.x+i.y*11==p and i.z==3 and i.msg.count("黒")>0:
            print("かすかに風が流れただけに思われた")
            time.sleep(2)
            print("しかし風はどんどん強くなり暴風となって引き込まれた")
            p+=i.d
            return
    print("かすかに風が流れる")

def white():
    global p
    for i in item:
        if i.x+i.y*11==p and i.z==3 and i.msg.count("白")>0:
            print("かすかに光が流れる")
            time.sleep(2)
            print("次の瞬間、まばゆい光があふれる。最初の地に戻ったらしい")
            p+=i.d
            return
    print("かすかに光が流れる")

def endCheck(p):
    if p!=5+22:
        print("チャックが開いた。ここではないらしい")
        return False
    for i in item:
        if i.x+i.y*11==p and i.z==1:
            print("大地に亀裂がはしり鍵が光りながら吸い込まれていく")
            time.sleep(5)
            print("この世界を救ってくれてありがとう ささやき声が聞こえた")
            print("光と闇の世界がともに解放されたらしい True End")
            return True
    print("静寂が広がる")
print("3days アドベンチャー")
time.sleep(2)
print("光は闇を切りさくのではなく闇を照らすものなり")
print("光と闇をつなぎこの世につかの間の平安に導き給え")
print("光にも過ちはある。音に出してみよ")
print("")
print("lookと入力してEnterを押してください")
time.sleep(2)

mp ="############000211000##002021000##000221000#"
mp+="#022211100##221211210##111222210##012221101#"
mp+="#111122110##021222100############"

item=[Item(4,4,0,"はじまりの地")]
item+=[Item(4,7,0,"はいせんの地")]
item+=[Item(4,4,1,"おしまいの鍵")]
item+=[Item(1,5,0,"for:周りの地形が少しみえる")]
item+=[Item(5,2,0,"look:行き止まりで使うと…")]
item+=[Item(7,5,0,"dark:ここで使うと永遠に封じ込められる")]
item+=[Item(7,5,3,"黒き世界へ",-11)]
item+=[Item(5,1,0,"end:もう脱出はできない")]
item+=[Item(3,9,0,"light:白き世界へ戻る")]
item+=[Item(3,7,3,"黒き世界へ",-1)]
item+=[Item(4,8,3,"白き世界へ",1)]
item+=[Item(4,9,0,"移動 u d l ...")]
item+=[Item(3,5,3,"白き世界へ",-11)]
item+=[Item(6,4,4,"ここは闇の気が溢れている。ここは危険だ",1)]
item+=[Item(1,8,0,"put:はじまりの地より3歩の地、目の右に置くべし")]
item+=[Item(6,9,0,"get:はじまりの地にて拾うべし")]
item+=[Item(1,6,0,"zip:老いた後2つの世界をつなぐ最後の呪文をとなえよ")]

p=4+4*11
looker=0
former=0
hp=3

a=input("command?")
while a!="end":
    if a=="dark":black()
    if a=="light":white()
    if a=="get" or a=="take":
        getItem(p)
    if a=="for":
        writeAround(p)
        former+=1
        if former==10:print("あなたはforをマスターしてprospecterに昇進した")
    if a=="look":
        print("床は",["なし","黒","白"][int(mp[p])])
        print("移動可能な空間は",getMove(p,mp[p]))
        ItemMsg(p)
        looker+=1
        if looker==10:print("あなたはlookをマスターしてlookerに昇進した")
    if a=="zip":
        if endCheck(p):
            a="end"
            continue
    if a=="drop" or a=="put":
        dropItem(p)
    if a in ["up","down","left","right","u","d","l","r"]:
        if getMove(p,mp[p]).find(a)>-1:
            p+=getMoveD(a)
            print("移動しました")
            print("床は",["なし","黒","白"][int(mp[p])])
            print("移動可能な空間は",getMove(p,mp[p]))
            if former>=10:
                writeAround(p)
            if looker>=10:
                ItemMsg(p)
        else:print("何かに阻まれた")
    if hp==0:
        print("あなたは力尽きた end")
        a="end"
    else:
        a=input("command?")


最新の画像もっと見る

コメントを投稿

ブログ作成者から承認されるまでコメントは反映されません。