0

I am learning Python by making a text based game. What would I need to do to put this game online? Obviously it is extremely underdeveloped and not even playable. But I just wanted to know early on so I can head in the right direction and learn.

#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
  • 1
    I think a good place to start would be to look at django https://www.djangoproject.com/, it is a web framework for python, has a really good tutorial to get you started (realistically it will probably entail you rewriting most of your game) I would suggest just sticking with a desktop game to start with if you are just learning python. – Calum Oct 09 '13 at 02:40

2 Answers2

0

Once you have a single-player command-line version of this game running I think a good next step would be to hook it up to a telnet interface. You could still easily play it locally on your computer (by telneting to localhost) but you also could learn the basics of setting up a server so that you and your friends could play it remotely. You could get server space from a friend, by finding a free shell account somewhere that lets you run a long-running process like a server (for example, at a mud forum like Mudconnector or Mudbytes), or by paying a few dollars a month for a cheap VPS (which you can find on lowendbox).

I think the best simple Python telnet library is Miniboa. You can find it here, https://code.google.com/p/miniboa/ .

I think @Calum's idea is a good one too, but Django is much more complicated than Miniboa so you'd have a lot more to learn (the learning curve is not necessarily steeper with Django, just longer, and might distract you at this point).

georgek
  • 877
  • 6
  • 11
0

It really depends on how far down the rabbit hole you want to go. I'm going to assume MUD and say MUD a lot since that's the tag that brought me here :)

The base for what you will want to understand is going to be socket programming and the telnet protcol ( http://en.wikipedia.org/wiki/Telnet#Related_RFCs ). A great site is http://www.beej.us/guide/bgnet/ . Python has a pretty good interface for socket usage and while this guide is pretty C focused all of the concepts apply. This will get your MUD able to send and receive data via a network such as the internet.

What this will not get you is all of the ins and outs of the telnet protocol that most MUDs implement. There are color codes, escape characters, routines for detecting the size of the players screen and adjusting text format accordingly.

MCCP is another thing worth looking into. This is a compression protocol understood by most MUD clients. The amount of network data pushed around in text based games is really not all that huge compared to the way the internet is used these days but a little compression never hurt anybody as long as they had the cputime for it :)

Honestly this is all fun stuff to learn about and implement, and if you really want to go from the ground up it's stuff you'll want to know.

As mentioned in other answers there are existing telnet libraries as well. The plus to this is that you will not have to handle all of the telnet protocol/networking stuff and can focus on the game itself.

Have fun!

Korthrun
  • 141
  • 5