12 Replies - 2946 Views - Last Post: 01 February 2010 - 09:14 AM Rate Topic: -----

#1 Finjy Opops  Icon User is offline

  • New D.I.C Head

Reputation: 0
  • View blog
  • Posts: 6
  • Joined: 26-January 10

[Python] Text-Based Space Sim

Posted 27 January 2010 - 02:48 PM

Hello, I'm currently going to a technical college for programming, but it's my first year and at the moment the only actual programming I'm doing is in my VB class. I've never done any serious programming, but I've messed about with VB, C++, C#, and Python and in theory I'm alright with the basic concepts at least.

I've always been a big fan of space combat and trading simulators, like the X series and Elite and all that. I figured it might be worth furthering my education a bit on the side by trying to code a text-based space sim focused more on the running of an actual ship and interaction with the crew. I'm still in the planning stages, and I figured I might as well verify that this would be a good way to start:

Objectives starting out:

1. Make a large 'ship' class spanning several properties/nested classes depending on which one would work better. I plan on having different ship systems, i.e. engines, shields, weaponry, damageable and tied to performance of the ship.
2. Create a very basic combat system revolving around targeting the systems of another ship. (i.e. 'target engines' 'engage' or something similar with hit points for each ship system and the hull)
3. Add in factors like distance to the other ships and basic navigation.

After this I plan on adding in 'areas' around planets and stars and the like with the ability to travel between them.

I have been working on a pseudocode version that I can post when I'm done.

At the moment besides your thoughts and advice on the project, my first real question is what IDE/editor do you recommend? I've used Pyscripter in the past and I liked that a lot but now I find that I have to have the 32-bit version of it installed to work, and I don't really want to switch to 32-bit when I'm running a 64-bit OS. If it makes little difference I wouldn't mind terribly but I'd prefer not to. :)

(I am aware that this will likely take a very long time and a lot of effort, it is not really a serious 'zomg ima make da best game eva' type of project, more one that I'll work on in my free time for fun and practice. :pirate: )

This post has been edited by Finjy Opops: 27 January 2010 - 02:51 PM


Is This A Good Question/Topic? 0
  • +

Replies To: [Python] Text-Based Space Sim

#2 programble  Icon User is offline

  • (cons :dic :head)

Reputation: 49
  • View blog
  • Posts: 1,315
  • Joined: 21-February 09

Re: [Python] Text-Based Space Sim

Posted 27 January 2010 - 05:55 PM

Quote

'zomg ima make da best game eva'

OMGZ!

With Python, an IDE isn't really needed, it is just as easy to write python in a basic text editor, but I hear Netbeans and Eclipse have Python plugins.
Was This Post Helpful? 0
  • +
  • -

#3 girasquid  Icon User is offline

  • Barbarbar
  • member icon

Reputation: 108
  • View blog
  • Posts: 1,825
  • Joined: 03-October 06

Re: [Python] Text-Based Space Sim

Posted 28 January 2010 - 09:38 AM

I think what you've figured out so far sounds like a good way to go about things - if there are any problems with your design, they'll come out in the wash.

In regards to IDEs, I tend to just use a text editor (TextMate).
Was This Post Helpful? 0
  • +
  • -

#4 programble  Icon User is offline

  • (cons :dic :head)

Reputation: 49
  • View blog
  • Posts: 1,315
  • Joined: 21-February 09

Re: [Python] Text-Based Space Sim

Posted 28 January 2010 - 05:32 PM

Where are you planning on hosting this project? Github? Gitorious? SourceForge? CodePlex?
Was This Post Helpful? 0
  • +
  • -

#5 Finjy Opops  Icon User is offline

  • New D.I.C Head

Reputation: 0
  • View blog
  • Posts: 6
  • Joined: 26-January 10

Re: [Python] Text-Based Space Sim

Posted 28 January 2010 - 08:46 PM

View Postprogramble, on 28 Jan, 2010 - 04:32 PM, said:

Where are you planning on hosting this project? Github? Gitorious? SourceForge? CodePlex?


I'm not sure. What exactly do you mean, just having it available on the internet for others to follow and play when it's done?

Otherwise, I installed Netbeans and it seems to work fine. If I have any issues I might just do it in Notepad++ or something. :)

Actual coding begins tonight! If you guys are interested I can post what I have afterward and see if you've got any suggestions.
Was This Post Helpful? 0
  • +
  • -

#6 chemicalfan  Icon User is offline

  • D.I.C Head

Reputation: 4
  • View blog
  • Posts: 88
  • Joined: 16-October 09

Re: [Python] Text-Based Space Sim

Posted 29 January 2010 - 05:27 AM

Sure thing man, sounds pretty interesting (and ambitious!)

I use Eclipse, I really like the PyDev plug-in with it's auto-indenting, keyword completion, and a couple of other nifty bits that just make it a little bit easier than Notepad.
Was This Post Helpful? 0
  • +
  • -

#7 dsherohman  Icon User is offline

  • Perl Parson
  • member icon

Reputation: 226
  • View blog
  • Posts: 654
  • Joined: 29-March 09

Re: [Python] Text-Based Space Sim

Posted 29 January 2010 - 07:57 AM

Good luck to you!

I've been working on something similar lately, albeit in Perl rather than Python, and it's mildly amusing to see that you've decided to approach it in just the opposite order... I started out with navigation/movement, then added basic combat, then trading. Fully-detailed ship systems are somewhere way off in the distance, but ship upgrades are in my top two "things to add next". (The other of the top two is a simple planetary production model. I haven't decided yet whether to do production or upgrades first.)
Was This Post Helpful? 0
  • +
  • -

#8 Finjy Opops  Icon User is offline

  • New D.I.C Head

Reputation: 0
  • View blog
  • Posts: 6
  • Joined: 26-January 10

Re: [Python] Text-Based Space Sim

Posted 29 January 2010 - 02:51 PM

View Postdsherohman, on 29 Jan, 2010 - 06:57 AM, said:

Good luck to you!

I've been working on something similar lately, albeit in Perl rather than Python, and it's mildly amusing to see that you've decided to approach it in just the opposite order... I started out with navigation/movement, then added basic combat, then trading. Fully-detailed ship systems are somewhere way off in the distance, but ship upgrades are in my top two "things to add next". (The other of the top two is a simple planetary production model. I haven't decided yet whether to do production or upgrades first.)


Haha, that's awesome! When I get a bit farther in we should totally compare our games, and see how much better yours is than mine. :P

I have run into my first problem though! I had forgotten that in Python, strings are immutable. So when I made this simple code as a starting point for the program:

# Filename: startup.py
__version__ = '0.01'

def Startup(): 
	print("Welcome to Nebula!")
	print("Current Version: " + __version__)

	nimput = input("Please enter your name: ")
	if nimput.isalpha() is False:
		print("That is not a valid name.")
		Startup()
	else:
		pass
	
	name = nimput.capitalize()

	print("Captain " + name + ", on the bridge! Welcome aboard.")
	
Startup()


I didn't account for the fact that strings seem to store more than one variable, i.e.:

Quote

>>>
Welcome to Nebula!
Current Version: 0.01
Please enter your name: 53
That is not a valid name.
Welcome to Nebula!
Current Version: 0.01
Please enter your name: finjy
Captain Finjy, on the bridge! Welcome aboard.
Captain 53, on the bridge! Welcome aboard.


When I tried looking for code that would clear the string, I was reminded about the whole 'immutable' part. Having only programmed in C++ and VB, I wasn't sure how I would deal with this, so I started doing a little research and I see that it's recommended for people to use lists instead of strings when dealing with stuff you might change. So, I booted up the interpreter and did a bit of messing around:

Quote

>>> toast = list("I like toast")
>>> len(toast)
12
>>> toast[5]
'e'
>>> toast = input("Please edit the list here: ")
Please edit the list here: lalala
>>> toast
'lalala'
>>> len(toast)
6


Now, this seems to be working fine, but before I start changing everything related to strings to lists I just wanted to verify that this was in fact the best way of dealing with it.

EDIT: Hmm. It seems to store lists as strings when I ask for input. Is there a way to have it interpret input as a list?

Thanks in advance. :pirate:

This post has been edited by Finjy Opops: 29 January 2010 - 03:19 PM

Was This Post Helpful? 0
  • +
  • -

#9 programble  Icon User is offline

  • (cons :dic :head)

Reputation: 49
  • View blog
  • Posts: 1,315
  • Joined: 21-February 09

Re: [Python] Text-Based Space Sim

Posted 29 January 2010 - 05:40 PM

That isn't your problem at all. Try this instead:
# Filename: startup.py
__version__ = '0.01'

def Startup(): 
    print("Welcome to Nebula!")
    print("Current Version: " + __version__)

    nimput = input("Please enter your name: ")
    if nimput.isalpha() is False:
        print("That is not a valid name.")
        Startup()
        return
    else:
        pass
    
    name = nimput.capitalize()

    print("Captain " + name + ", on the bridge! Welcome aboard.")
    
Startup()


Was This Post Helpful? 1
  • +
  • -

#10 Finjy Opops  Icon User is offline

  • New D.I.C Head

Reputation: 0
  • View blog
  • Posts: 6
  • Joined: 26-January 10

Re: [Python] Text-Based Space Sim

Posted 29 January 2010 - 06:19 PM

Thanks. I've been reading about python all day and what I ended up with was:

def GetName():
		ninput = input("What do you wish to be called?\n ")
		if ninput.isalpha() is False:
			print("That is not a valid name.")
			del ninput
			player.GetName()
		else:
			pass
		player.name = ninput.capitalize()
		print("Welcome aboard, Captain " + player.name + "!")


This is no longer in the startup.py and instead is in a separate .py I have for the player class. Using your way with the return works the same, and I assume that's a better solution. I had forgotten all about the return function! Haha.

I actually have a new, more confusing problem, when trying to ascertain the player's gender:

def GetGender():
		ginput = input("Are you male or female?\n ")
		ginputl = ginput.lower()
		
		if ginputl is "male":
			player.gender = "male"
		elif ginputl is "female":
			player.gender = "female"
		else:
			print("That isn't a gender...")
			player.GetGender()
			return


(I had del ginput, ginputl for that too, but I found your return works just as well)
Returns:

Quote

>>> player.GetGender()
Are you male or female?
male
That isn't a gender...
Are you male or female?
female
That isn't a gender...
Are you male or female?
both
That isn't a gender...
Are you male or female?


I'm assuming something is wrong in the if/then statement.

EDIT: Nevermind, I figured it out! Instead of

if ginputl is "male":


I could just put

if ginputl == "male":


And it works! I was being silly and forgot that you're supposed to have two =s for that, not just one. XD

Nevermind, it defaults to male no matter what you type. Grr!

Nevermind again, it's because I had added 'or 'm'' to it so it would read if they just typed m as well and then forgot it. When that's erased, it works. :)

This post has been edited by Finjy Opops: 29 January 2010 - 08:33 PM

Was This Post Helpful? 0
  • +
  • -

#11 Finjy Opops  Icon User is offline

  • New D.I.C Head

Reputation: 0
  • View blog
  • Posts: 6
  • Joined: 26-January 10

Re: [Python] Text-Based Space Sim

Posted 29 January 2010 - 11:18 PM

Alright! More questions. :)

I wrote up the ship class:

# Filename: ship.py

class base():
	def __init__(self, name, stype, systems):
		self.name = name
		self.stype = stype
		self.systems = systems

	class systems():
		def __init__(self, engines, weapons, shields, hull):
			self.engines = engines
			self.weapons = weapons
			self.shields = shields
			self.hull = hull

		class engines():
			def __init__(self, damage, speed):
				self.damage = damage
				self.speed = speed

		class weapons():
			def __init__(self, damage, power):
				self.damage = damage
				self.power = power

		class shields():
			def __init__(self, damage, power):
				self.damage = damage
				self.power = power

		class hull():
			def __init__(self, damage, strength):
				self.damage = damage
				self.strength = strength


As you can see, I decided to go with the nested classes approach. I haven't really gotten a chance to test this to make sure it's correct, as I wanted to create another module called pship (player ship) that contained a class based off of ship. This is where I'm having issues.

from ship import *

class pship(base):
	pass


This seems to work, as in when I assign a value to pship.name it stores it correctly. I have no idea, however, if this is proper or will even work in the long run. The tutorial I've been reading is overall great so far but is a bit vague on this area, the way they have it set up is it basically calls everything it already called in the original class within the new one, which seems off to me.

What do you guys feel is the best way to use nested classes and such?
Was This Post Helpful? 0
  • +
  • -

#12 chemicalfan  Icon User is offline

  • D.I.C Head

Reputation: 4
  • View blog
  • Posts: 88
  • Joined: 16-October 09

Re: [Python] Text-Based Space Sim

Posted 01 February 2010 - 01:43 AM

Those classes aren't nested properly (assuming you wanted proper subclassing so methods and attributes are available to the children instances), they should be:

class systems(base):

Was This Post Helpful? 0
  • +
  • -

#13 Finjy Opops  Icon User is offline

  • New D.I.C Head

Reputation: 0
  • View blog
  • Posts: 6
  • Joined: 26-January 10

Re: [Python] Text-Based Space Sim

Posted 01 February 2010 - 09:14 AM

View Postchemicalfan, on 1 Feb, 2010 - 12:43 AM, said:

Those classes aren't nested properly (assuming you wanted proper subclassing so methods and attributes are available to the children instances), they should be:

class systems(base):


I've done a bit of revising since then as I had useless attributes galore with that method. Right now, with the proper nesting (I think) it's:

# Filename: ship.py

class base():
	def __init__(self, name, stype):
		self.name = name
		self.stype = stype

	class engines(base):
		def __init__(self, damage, speed):
			self.damage = damage
			self.speed = speed

	class weapons(base):
		def __init__(self):
			pass

		class bow(weapons):
			def __init__(self, wtype, wnumber, power, damage):
				self.wtype = wtype
				self.wnumber = wnumber
				self.power = power
				self.damage = damage

		class aft(weapons):
			def __init__(self, wtype, wnumber, power, damage):
				self.wtype = wtype
				self.wnumber = wnumber
				self.power = power
				self.damage = damage

		class port(weapons):
			def __init__(self, wtype, wnumber, power, damage):
				self.wtype = wtype
				self.wnumber = wnumber
				self.power = power
				self.damage = damage

		class starboard(weapons):
			def __init__(self, wtype, wnumber, power, damage):
				self.wtype = wtype
				self.wnumber = wnumber
				self.power = power
				self.damage = damage
					   
	class shields(base):
		def __init__(self):
			pass

		class bow(shields):
			def __init__(self, strength)
			self.strength = strength
			
		class aft(shields):
			def __init__(self, strength)
			self.strength = strength
			
		class port(shields):
			def __init__(self, strength)
			self.strength = strength
			
		class starboard(shields):
			def __init__(self, strength)
			self.strength = strength

	class hull(base):
		def __init__(self, damage, strength):
			self.damage = damage
			self.strength = strength


Now, am I correct in assuming I would subclass weapon and shields subclasses to weapons and shields, or would I just do base with everything?
Was This Post Helpful? 0
  • +
  • -

Page 1 of 1