• 9
• 9
• 11
• 12
• 9
• ### Similar Content

• Where to get started in making a text based MUD?

So I have been making small games for over 3 years now and I'm comfortable in the programming languages that follow:
1. Python (I need a bit of practice with this)
2. C# (I am the most comfortable in this)
3. Java (I know quite a bit but might need to do a tad of research)

and I have also done a bit in:
4. JS (I know pretty much nothing here)
5. And some other stuff

Anyway, so now you know all that rubbish here goes. What I wan't to do is program a text based MMORPG or a text based MUD. I have basically no clue where to begin so I what I need is some places to start. If anyone has any information on the subject, anything at all, please post it bellow. I will be really appreciated.

• A simple arcade game in python.I am currently in class 9th and made this game using python

• I've made a very simple map generator as a demo for combat encounters in my game. I plan to have the trees and rocks be cover, while the player's bandits ambush a caravan on the road in the middle. Please, let me know what you think. Criticism is welcome.

• Hello all,
I have teamed up with TheGameCreators for them to trial a Python version of AppGameKit in the form of a PYD file that makes AppGameKit commands available to Python 3.6 and greater.  Currently this PYD is compiled only for use with the Windows x86 version of Python.  It is a free, unlimited version of their commercial product, but it does show the AppGameKit logo for a few seconds on game startup and AppGameKit is mentioned in the window title when in windowed mode.  The PYD works with PyInstaller for easy distribution.
If you haven't heard of AppGameKit, I would recommend looking over their website.  They also have documentation online and an active community forum.  I should point out that method names have been changed to follow PEP 8 naming conventions, so they will be similar but different from the online help.  I also had to make a few changes mentioned on the project's itch.io page.  There is also a PYI file there that can be used with PyCharm for easier access to the same information.
As mentioned, this is a trial for them, but if there's a positive response they will extend the project and include a way of compiling an executable without the intro logo and window title text as well as support other OS.
Please take a look and feel free to ask me any questions about it here or on the project's community forum on itch.io.
AppGameKit for Python project page at itch.io: https://fascimania.itch.io/appgamekit-for-python
Original announcement url: https://www.thegamecreators.com/post/announcing-appgamekit-for-python

• I want to make a random map generator in python 3, but I have no idea how to do it. Could someone recommend me a good starting point?
What I want to make is a flat 2D overworld-map with roads, rivers, settlements, farmlands, forests, and plains.
I don't want to model specific buildings. This is just for a game I'm making where I'd like the player to be able to travel from point to point.

# Dealing with Multiple Characters with Different Attributes

## Recommended Posts

I'm trying to make a game where the characters are randomly generated and retain individual attributes over time. Right now, I'm working on the combat system. I've made it so the roles of "Attacker" and "Defender" will switch between the player character and the NPC they are fighting. Problem is, I'm unsure of how to organize it in an elegant way. All I can think of is doing a bunch of if & else statements every time I need to check. Could you suggest ways of doing this in an elegant way? If there is anything in my code that could be significantly simplified don't be afraid to point that out either.

Here is an example of one of the methods I could use help with. In it, I am taking the int type variable, "overall action score", or OAS, from a tuple, which then helps to determine the force of any attacks that land. On if and else statements, I am checking who is attacking, and calling one of their respective physical attributes.

    def forceFinder(self):
"""
Determines force of strike from
OAS and alacrity.
"""
#subtract attacker OAS from defender OAS
force = self._oasTuple[0] - self._oasTuple[1]
#exponentially adds to force according to alacrity and
#margin between attacker, and defender OAS.
for i in range(0, force, 10):
force *= 1.10
if Combat._attacker == "pc":
force += Combat._pcAttr["alacrity"] * 3
else:
force += Combat._npcAttr["alacrity"] * 3
return int(force)

##### Share on other sites

Python is not my strong suit so I apologize if this is vague, but...

What you want to do is store a reference to the PC (or NPC) in a variable. Then instead of having an if check, you just ask the variable for its alacrity stat directly. When the turn switches, you can point that variable to the "other" character instead, and off you go.

This way the code uses the same exact checks for everyone, but it can be "configured" to point to one character or another on the fly.

Hope that made some semblance of sense :-)

##### Share on other sites

The typical approach is to have data that gets swapped out.

You might pass an index to a table for the source or target, you might pass an object for the source and the source for the target, or something else.

For example, adding that information to the object itself and accessing it generically:

force += Combat._attacker.Attr["alacrity"];

or perhaps:

force += Combat._attacker.CurrentAlacrity(Combat._defender);

or accessing it through another table:

force += CombatAttribs[Combat._attacker].["alacrity"];

I prefer the function version above, since it more easily allows you to add modifications based on the source and the target, such as a bonus versus dragons or penalty versus shopkeepers or whatever fits your game.

##### Share on other sites
1 hour ago, ApochPiQ said:

Python is not my strong suit so I apologize if this is vague, but...

What you want to do is store a reference to the PC (or NPC) in a variable. Then instead of having an if check, you just ask the variable for its alacrity stat directly. When the turn switches, you can point that variable to the "other" character instead, and off you go.

This way the code uses the same exact checks for everyone, but it can be "configured" to point to one character or another on the fly.

Hope that made some semblance of sense :-)

So basically, you have an array for each character and switch the identifiers of the arrays based on who fills each role? If that's what you're saying I get it. It seems fairly simple, and would work. I'd like to examine other possibilities still.

22 minutes ago, frob said:

The typical approach is to have data that gets swapped out.

You might pass an index to a table for the source or target, you might pass an object for the source and the source for the target, or something else.

For example, adding that information to the object itself and accessing it generically:

force += Combat._attacker.Attr["alacrity"];

or perhaps:

force += Combat._attacker.CurrentAlacrity(Combat._defender);

or accessing it through another table:

force += CombatAttribs[Combat._attacker].["alacrity"];

I prefer the function version above, since it more easily allows you to add modifications based on the source and the target, such as a bonus versus dragons or penalty versus shopkeepers or whatever fits your game.

Thank you for the quick, and in-depth response. I'm sorry, but I don't understand Python 2. I'm guessing that's what these examples are since we never seem to end lines in Python 3.6 with semi-colons. I'm not sure how to make these examples work since I don't understand their formatting. I've never seen class-level variables called in that way, with two periods, to reach specific data. Could you please explain it or link to a website/video that can help me understand how to do the same thing in Python 3? It seems like some of your ways might be better than how I've interpreted ApochiPiQ's suggestion.

##### Share on other sites
8 hours ago, RidiculousName said:

So basically, you have an array for each character and switch the identifiers of the arrays based on who fills each role? If that's what you're saying I get it. It seems fairly simple, and would work. I'd like to examine other possibilities still.

You can wrap the access code in a function

def get_property(combat, property):
if combat._attacker == "pc":
return combat._pcAttr[property]
else:
return combat._npcAttr[property]

which then gives

force += get_property(Combat, "alacrity") * 3

Frob folds the selection into the Combat object (his Pythoneese has some C++ influences, just ignore the semi-colons and the dots that look weird )

Instead of making "Combat.attacker" a string, make it the object you point to:

# Inside Combat

def assignAttacker(self, attacker_type):
if attacker_type == "pc":
self._attackerAttr = self._pcAttr
self._defenderAttr = self._npcAttr
else:
self._attackerAttr = self._npcAttr
self._defenderAttr = self._pcAttr

And now you can access Combat._attackerAttr[...]

As a note, the "_" prefix denotes a private variable (by convention) in Python, which basically means you should not access those variables from outside the methods of the class (like you do with Combat._pcAttr for example). Other Python programmers will get confused about it.

Unlike eg Java and C++, in Python an object variable is always prefixed by the containing object, that is, you cannot write "_pcAttr" to access the variable in Combat, you must always write something like "Combat._pcAttr" or "self._pcAttr". As such, there is no real need to differentiate between normal variables and object member variables, the "Combat." or "self." prefixes in front of the latter already do this.

Edited by Alberth
fixed code example

##### Share on other sites

Again, Alberth!? Every time I post a question you're there with amazingly well-reasoned and detailed answers. Thank you!

I'll take your advice. Only one thing still puzzles me bit.

Quote

As a note, the "_" prefix denotes a private variable (by convention) in Python, which basically means you should not access those variables from outside the methods of the class (like you do with Combat._pcAttr for example). Other Python programmers will get confused about it.

The method I gave as an example is held within the Combat class. Have I misunderstood you?

##### Share on other sites
8 hours ago, RidiculousName said:

Again, Alberth!? Every time I post a question you're there with amazingly well-reasoned and detailed answers. Thank you!

Hmm, yeah, sorry about that. Likely that will continue to happen until you start asking questions about complicated component systems, data-oriented-design, and pretty much anything about GPUs or detailed performance stuff.

9 hours ago, RidiculousName said:

The method I gave as an example is held within the Combat class. Have I misunderstood you?

Good point, missed that. It would be fine then I guess, since it's only a convention anyway.

## Create an account or sign in to comment

You need to be a member in order to leave a comment

## Create an account

Sign up for a new account in our community. It's easy!

Register a new account