繁体   English   中英

我需要做什么/学习才能使基于文本的Python游戏可供互联网用户访问

[英]What do I need to do/learn to make my text based Python game accessible to users over the internet

我正在通过制作基于文本的游戏来学习Python。 我需要做些什么才能将此游戏放到网上? 显然,它非常不发达,甚至无法播放。 但是我只是想早点知道,这样我才能朝着正确的方向学习。

#object = [x, y, z, name, armor rating, weapon 1]

user= [100, 100, 100, "Wing Zero", 250, 50]

mothership=[100, 100, 50, 'mothership']
enemy1 = [100, 100, 105, "leo1", 100, 20]
enemy2 = [100, 100, 110, "leo2", 100, 20]
enemy3 = [100, 100, 115, "leo3", 100, 20]


nearbyships=[] #List of ships by player for printing purposes
truenearbyships=[]#List of ships near player for calculating purposes
listofships=[mothership, enemy1, enemy2, enemy3] #Overall ships in game

target = 'r'#Placecholder var

def radar(listofships, user):
                for i in listofships:
                    if user[0] + 50 > i[0] and user[1] + 50 > i[1] and user[2] + 50 > i[2]:
                        nearbyships.append("space object (%s) detected at coordinates (%s, %s, %s)" % (i[3], i[0], i[1], i[2]))
                        truenearbyships.append(('%s') % (i[3]))
                    else:
                        print('no ships detected')



def target(ship, user):
    print("You target ship")



while(True):
    print('\n Current coordinates: (%s, %s, %s)' % (user[0], user[1], user[2]))

    i=str(raw_input())
    if i == 'radar':
        radar(listofships, user)
        for i in nearbyships:
            print(i)
        nearbyships=[]


    elif i == 'l':
        print("You are sitting in a Leo cockpit")

    elif i == 'nearby':
        print(truenearbyships)

    elif 'target' in i:
        radar(listofships, user)
        targetlist=i
        targetlist=targetlist.split()

      #  target list is text taken from player input 'target object'. targetlist[-1] is the space object in game



        if targetlist[-1] in truenearbyships:
            print("You begin locking in on %s space object" % (i[-1]))
            print('target confirmed')
            currenttarget=targetlist[-1]
        else:
            print('ship not detected')


    elif i == 'fire weapon1':
        if currenttarget:
             print("You fire your buster rifle at %s and hit it directly" %(currenttarget)) #Insert probability of hit and damage

        else:#Check if there is a target set
            print("You are not targeting anything")



    else:
        print("Please input a valid command from the manual below \n'radar'\n'target (object)'")


#Movement system? Timed flight
#Combat
#Hyperspace
#multiple people
#Docking

一旦运行了该游戏的单人命令行版本,我认为下一步是将其连接到telnet界面。 您仍然可以轻松地在计算机上本地播放它(通过telnet到localhost),但是您还可以学习设置服务器的基础知识,以便您和您的朋友可以远程播放它。 您可以从朋友那里获得服务器空间,方法是在某个地方找到一个免费的Shell帐户,该帐户可以让您运行服务器等长期运行的进程(例如,在Mudconnector或Mudbytes之类的泥泞论坛上),或者每月支付几美元便宜的VPS(您可以在lowendbox上找到)。

我认为最好的简单Python telnet库是Miniboa。 您可以在https://code.google.com/p/miniboa/上找到它。

我认为@Calum的想法也是个好主意,但是Django比Miniboa复杂得多,因此您需要学习的东西更多(Django的学习曲线不一定更陡峭,更长的时间可能会分散您的注意力) )。

这实际上取决于您想走多远的兔子洞。 我要假设MUD并说很多MUD,因为这是将标签带到我这里的:)

您要了解的基础将是套接字编程和telnet协议( http://en.wikipedia.org/wiki/Telnet#Related_RFCs )。 很棒的网站是http://www.beej.us/guide/bgnet/ Python有一个很好的套接字使用接口,而本指南相当注重C语言,所有概念都适用。 这将使您的MUD能够通过网络(如Internet)发送和接收数据。

这不会让您得到大多数MUD实施的telnet协议的所有细节。 有颜色代码,转义字符,用于检测播放器屏幕尺寸并相应调整文本格式的例程。

MCCP是另一件值得研究的事情。 这是大多数MUD客户端理解的压缩协议。 与目前使用互联网的方式相比,基于文本的游戏中推送的网络数据量确实不是那么大,但是只要有CPU时间,一点点压缩就不会伤害任何人:)

坦率地说,这是所有要学习和实现的有趣的东西,如果您真的想从头开始,那就需要了解这些东西。

如其他答案中所述,也有现有的telnet库。 这样做的好处是您不必处理所有telnet协议/网络事务,而可以专注于游戏本身。

玩得开心!

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM