Python
python3

pythonでCUIの2Dゲーム基盤

pythonを勉強し始めて半年ほど経ったので書きました。
大学の課題でC言語とかで宝探しゲームとか作らされるやつです。
WASD移動でX座標とY座標それぞれ動きます。

python3です!

スクリーンショット 2017-12-18 15.52.58.png

maze.py
field = [
    ["-","-","-","-","-"],
    ["-","-","-","-","-"],
    ["-","-","-","-","-"],
    ["-","-","-","-","-"],
    ["-","-","-","-","-"]
]
p_x = 1
p_y = 1

def ref():
    field[p_y][p_x] = '-'

def draw():
    field[p_y][p_x] = '*'

def move(command):
    global p_x
    global p_y
    if command == 'w':
        if p_y > 0:
            ref()
            p_y -= 1
            draw()
        else:
            pass
    elif command == 's':
        if p_y < 4:
            ref()
            p_y += 1
            draw()
        else:
            pass
    elif command == 'a':
        if p_x > 0:
            ref()
            p_x -= 1
            draw()
        else:
            pass
    elif command == 'd':
        if p_x < 4:
            ref()
            p_x += 1
            draw()
        else:
            pass

if __name__ == '__main__':
    draw()
    while True:
        for i in field:
            for j in i:
                print(j, end="")
            print("")
        print("======")
        print('up:w left:a down:s right:d')
        key = input('>> ')
        move(key)