我试图制作一个没有pygame(带有字母)的游戏机。但是我不知道该写些什么

时间:2019-07-17 12:35:17

标签: python-3.7

我试图制作游戏机,但是我不知道如何编码地图。

这是用于Windows。

import time

class Map:
    def showMap(self):
        print()
        #?

player_x = 2
player_y = 2

def Loop(): #Objects
    print(" - RPG Game\n")
    Map1 = Map()
    Map1.showMap()
    print(" X = "+str(player_x)+" Y = "+str(player_y)+"\n")

while True:
    time.sleep(0.1)

    keys = input()

    if keys == "w":
        player_y -= 1
    if keys == "a":
        player_x -= 1
    if keys == "s":
        player_y += 1
    if keys == "d":
        player_x += 1
    Loop()

我正在尝试创建5x5的地图。 但是我无法创造。我必须写什么
def showMap(self):吗?

谢谢。

1 个答案:

答案 0 :(得分:1)

我做到了。感谢@Ken White。这是代码。 (我在回答我的问题。有点愚蠢,但只是为了寻求帮助。)

但是如果有人也参加该活动,也许他/她应该查看该代码。

import time

l1 = "+ "
l2 = "+ "
l3 = "+ "
l4 = "+ "
l5 = "+ "
l6 = "+ "
l7 = "+ "
l8 = "+ "
l9 = "+ "

loc = 5

class Map:
    def showMap(self):  
        if loc==1:
            print("O ",l2,l3) #O is player.
            print(l4,l5,l6)
            print(l7,l8,l9)
        elif loc==2:
            print(l1,"O ",l3)
            print(l4,l5,l6)
            print(l7,l8,l9)
        elif loc==3:
            print(l1,l2,"O ")
            print(l4,l5,l6)
            print(l7,l8,l9)
        elif loc==4:
            print(l1,l2,l3)
            print("O ",l5,l6)
            print(l7,l8,l9)
        elif loc==5:
            print(l1,l2,l3)
            print(l4,"O ",l6)
            print(l7,l8,l9)
        elif loc==6:
            print(l1,l2,l3)
            print(l4,l5,"O ")
            print(l7,l8,l9)
        elif loc==7:
            print(l1,l2,l3)
            print(l4,l5,l6)
            print("O ",l8,l9)
        elif loc==8:
            print(l1,l2,l3)
            print(l4,l5,l6)
            print(l7,"O ",l9)
        elif loc==9:
            print(l1,l2,l3)
            print(l4,l5,l6)
            print(l7,l8,"O ")

while True:
    print(" - RPG Game\n")

    time.sleep(0.1)
    Map1 = Map()
    Map1.showMap()
    print(" X = "+str(loc%3)+" Y = "+str(loc//3)+"\n")
    keys = input(" > ")

    if keys == "w":
        loc -= 3 #3 here because we have 3 letter in columns
    if keys == "a":
        loc -= 1
    if keys == "s":
        loc += 3 
    if keys == "d":
        loc += 1

    print("\n"*10)