• Announcements

    • khawk

      Download the Game Design and Indie Game Marketing Freebook   07/19/17

      GameDev.net and CRC Press have teamed up to bring a free ebook of content curated from top titles published by CRC Press. The freebook, Practices of Game Design & Indie Game Marketing, includes chapters from The Art of Game Design: A Book of Lenses, A Practical Guide to Indie Game Marketing, and An Architectural Approach to Level Design. The GameDev.net FreeBook is relevant to game designers, developers, and those interested in learning more about the challenges in game development. We know game development can be a tough discipline and business, so we picked several chapters from CRC Press titles that we thought would be of interest to you, the GameDev.net audience, in your journey to design, develop, and market your next game. The free ebook is available through CRC Press by clicking here. The Curated Books The Art of Game Design: A Book of Lenses, Second Edition, by Jesse Schell Presents 100+ sets of questions, or different lenses, for viewing a game’s design, encompassing diverse fields such as psychology, architecture, music, film, software engineering, theme park design, mathematics, anthropology, and more. Written by one of the world's top game designers, this book describes the deepest and most fundamental principles of game design, demonstrating how tactics used in board, card, and athletic games also work in video games. It provides practical instruction on creating world-class games that will be played again and again. View it here. A Practical Guide to Indie Game Marketing, by Joel Dreskin Marketing is an essential but too frequently overlooked or minimized component of the release plan for indie games. A Practical Guide to Indie Game Marketing provides you with the tools needed to build visibility and sell your indie games. With special focus on those developers with small budgets and limited staff and resources, this book is packed with tangible recommendations and techniques that you can put to use immediately. As a seasoned professional of the indie game arena, author Joel Dreskin gives you insight into practical, real-world experiences of marketing numerous successful games and also provides stories of the failures. View it here. An Architectural Approach to Level Design This is one of the first books to integrate architectural and spatial design theory with the field of level design. The book presents architectural techniques and theories for level designers to use in their own work. It connects architecture and level design in different ways that address the practical elements of how designers construct space and the experiential elements of how and why humans interact with this space. Throughout the text, readers learn skills for spatial layout, evoking emotion through gamespaces, and creating better levels through architectural theory. View it here. Learn more and download the ebook by clicking here. Did you know? GameDev.net and CRC Press also recently teamed up to bring GDNet+ Members up to a 20% discount on all CRC Press books. Learn more about this and other benefits here.
Sign in to follow this  
Followers 0
mauermcx

Movement Game Logic in a Python Text-Based Game

6 posts in this topic


 

Hey all,
Thanks to a few guys on the forums I finally got around to starting on my text-based adventure called "a knights quest." It features a knight played by the player that is sent by his king to wipe out a cave full of foul creatures. However I am a bit stuck on how to simulate player movement in Python. I looked around the internet for movement logic specifically in Python, but so far I have had no luck. So I come to you guys, the experts. Does anyone have a good method of simulating player movement? In case anyone is interested I am 51% of the way through the CodeAcademy Python track so I haven't completely learned the basics of Python yet. Should I write a function? Or I heard of something called a class which I have yet to learn about yet. Here's my code below if anyone is interested in giving me tips on what I already have.
Thanks in advance,
Michael

 

 

 


# -*- coding: utf-8 -*-
"""
Created on Sun Jun  2 17:29:40 2013
 
@author: Michael
"""
epicfailure = "Since you failed to type your own name you lose"
def printresponse(r):
    if len(r) > 0:
        return True
    else:
        return False
 
name = raw_input("What is your name?")
if printresponse(name) == True:
    hometown = raw_input("Where are you from?") 
else:
    print epicfailure  
def help(input):
    helpint = "typable options: north, south, east, west, hit creature, run away, use torch"
    if input == "help":
        print helpint
 
yournameintro = "<Your name is %s , a wearied traveler>" % (name)
yourhometownintro = "<You've been sent to a cave outside of %s by your king>" % (hometown)
yourquestintro = "<Wipe out all of the foul creatures that dwell there>"
caveentrance = "<As you enter the cave, you check your supplies.  You have a sword, and a torch.  You think to yourself 'My king is such a cheapskate'>"
thequestion = "<What do you do?>"      
if printresponse(hometown) == True:
    print yournameintro
    print yourhometownintro
    print yourquestintro
else:
    print epicfailure    
print "======================="    
print caveentrance
print "======================="
print thequestion
help("help")
response = raw_input(thequestion)
 
Edited by mauermcx
0

Share this post


Link to post
Share on other sites

However I am a bit stuck on how to simulate player movement in Python. I looked around the internet for movement logic specifically in Python, but so far I have had no luck. So I come to you guys, the experts. Does anyone have a good method of simulating player movement? In case anyone is interested I am 51% of the way through the CodeAcademy Python track so I haven't completely learned the basics of Python yet.

 

From reading this it sounds like you are attempting to tackle a project a bit out of your scope at the moment. Let me clarify something first that there is no "movement logic" specifically in Python. Python is simply a programming language, a tool. To solve the problem of how to simulate player movement would involve thinking about how you are breaking down the representation of your player and a room. What data structures are you going to use to represent these game entities? Will rooms have references to each other by cardinal directions and a list of game objects and/or players?

 

I think you should read more about Python and experiment with classes, modules etc. before tackling a text based RPG. One way to think about programming is taking a large problem and dividing that into several smaller problems to solve then piecing it all back together. The language itself is simply a tool or means to an end however, if you don't know how to use the tool with some proficiency your problem will be rather hard to solve indeed.

1

Share this post


Link to post
Share on other sites

Thanks for this advice.  You are right.  I need to focus on learning the language before tackling this big of a project.  I like the idea of dividing it into several smaller projects.  Eventually when I have more experience with Python i will map out my game before I start in on it again.

I think you should read more about Python and experiment with classes, modules etc. before tackling a text based RPG. One way to think about programming is taking a large problem and dividing that into several smaller problems to solve then piecing it all back together. The language itself is simply a tool or means to an end however, if you don't know how to use the tool with some proficiency your problem will be rather hard to solve indeed.

0

Share this post


Link to post
Share on other sites

Hmm. It's been a while since I've worked on a text-based RPG but IIRC you can set up the room objects using a graph structure where the rooms are nodes and they are connected by bi-directional edges. As an example, Room1 has exits (S, W, N) and Room2 has exits (N, E, S, W), and Room1 (W) is attached to Room2 (E).

 

I know this may sound confusing but googling some of these terms may help get you started. Good luck on your game and remember to have fun.

2

Share this post


Link to post
Share on other sites

Remember that everything in code is a model of something and the more complex (detailed) your model the more complex your code.  If you have an Age class which stores age in years as an int that is a model which restrictions.  You can't have half years because it's an int and you have to put logic in there to handle cases where age will be negative because that is outside the domain of an Age.  If years as an int is not detailed enough you could model Age as a start datetime and an end datetime but then you have to add code to handle conversions, pretty printing, etc.  It depends on what you need the model to do.

 

Get a pencil and paper and start to sketch out how you will model space.  As tp9 mentioned you could go the classic way of Rooms which have connections to other rooms which would be a great way to start.  You could build on a 2d plane and model the player's location as an x,y point but that is getting very complex.  Define the player commands (attack, move, etc) and then sketch a few possible sequences such as "player moves north twice and then attacks".  Well defined and thought out data structures lend themselves to simple code that works.

 

You will want to separate your user interface out from the game logic so that you don't have raw_input's next to move_to_room() functions or room data structures.

 

Personally I think a project like this (if you stick to the room based game) would be an excellent way to learn Python.  I would recommend getting basic functionality going and then looking around to see if there is a library to do it for you.  That will allow you to understand what the library is doing for you rather than treating it like magic.

 

Dive in, fix the stuff that doesn't work, break stuff trying to do something new.  Good luck!

0

Share this post


Link to post
Share on other sites

Here is some advice:

 

1. Your printresponse function is poorly named because it does not print a response. It looks like it checks the length of a response to see if it is greater than zero, but this is not going to provide much information about the content of the response from the player. Looking into regular expressions in Python will provide you a way of checking player input in a more robust manner.

 

2. I tell everyone making a text based game that you really want to use a data driven design. Look at how to do File I/O in Python and define your rooms and game data in a file. Read this file into a data structure (once you learn about them) and write code to read this data structure and perform various actions based on the player input. Essentially your configuration file(s) are the content of the game, and your code is what allows the player to interact with the content. Doing things in this way will allow you to add more content without adding a proportional amount of new code. There are lots of options for what format to make such a file including but not limited to XML and JSON. XML is widely used but JSON is very popular right now.

 

3. Design first and code second. Plan out your game and how it will work. Especially when you have a lack of programming experience you need to really focus on defining your problem and how to break it down into parts that you can research how to do. Design is important no matter what level of experience and it is my view that at least thinking about the design first will make you a better programmer. That is not to say that you should spend months on a design or that you should not do anything but design, but it is that you should at least get a clear picture in your head of what you are trying to build so that you know what direction to go in.

0

Share this post


Link to post
Share on other sites

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

Sign in

Already have an account? Sign in here.


Sign In Now
Sign in to follow this  
Followers 0