Text Adventure Game from a Newbie

This is the place to post any code that you want to share with the community. Only completed scripts should be posted here.

Text Adventure Game from a Newbie

Postby peterthesteam » Mon Jan 27, 2014 10:31 pm

Hi All
I might get this in the wrong place, as my script works (for me) but might never be finished totally.........
I am totally new to Python, but having turned 60 am no spring chicken. I got a chest infection last year and got bored, so thought I would try my hand at an adventure game.
The result can be found at http://www.bumpkinworld.co.uk/misc/adventuretest.zip
I have got 70 odd rooms and various obstacles. However I think it is now time to delve into working with files to be able to save a game and retrieve it. Also the room locations could do with going in a separate file.
The game seems to work OK, however I would love some feedback on my abysmal programming!
Programmed in Python 2.7
Cheers All
Last edited by stranac on Mon Jan 27, 2014 10:49 pm, edited 1 time in total.
Reason: First post lock.
peterthesteam
 
Posts: 5
Joined: Mon Jan 27, 2014 10:03 pm

Re: Text Adventure Game from a Newbie

Postby stranac » Mon Jan 27, 2014 10:52 pm

It would be much more convenient for all of us if you had this in an online repo.
If you have no idea what I'm talking about, you can read more about it here:
viewtopic.php?f=25&t=5269
Friendship is magic!

R.I.P. Tracy M. You will be missed.
User avatar
stranac
 
Posts: 1111
Joined: Thu Feb 07, 2013 3:42 pm

Re: Text Adventure Game from a Newbie

Postby peterthesteam » Tue Jan 28, 2014 4:58 pm

GOOD GRIEF!

GitHub looks somewhat complex for what I need. Also if you need a crib sheet to remember how to work it, then it rather scares me!

I only used 'bumpkinworld.co.uk' because it is my own website left over from when I was self employed. I now use it for my local Model Engineering society, but it is a handy place to throw the odd large file rather than emailing a huge attachment to my friends. I certainly don't have any popups or advertising on it. Those things drive me nuts.

If anyone can recommend a somewhat simpler solution than GitHub, I would be most happy.

All the best
peterthesteam
peterthesteam
 
Posts: 5
Joined: Mon Jan 27, 2014 10:03 pm

Re: Text Adventure Game from a Newbie

Postby metulburr » Tue Jan 28, 2014 5:26 pm

Github, at first, has a steep learning curve, but once you get the hang of it, things become quite easy. The commands are consistant. At this day and age, its almost considered required for programmers. If your going to spend thousands of hours coding, why not spend a few hours learning how to use git and github?

I no longer use a cheat sheet, as i have pushed so much, now its second nature (at least for basic push/pulls)

The method i use in the tutorial is the command prompt/terminal method, if your on windows, there is a GUI github, if your so inclined to not use the terminal.
New Users, Read This
OS Ubuntu 14.04, Arch Linux, Gentoo, Windows 7/8
https://github.com/metulburr
steam
User avatar
metulburr
 
Posts: 1415
Joined: Thu Feb 07, 2013 4:47 pm
Location: Elmira, NY

Re: Text Adventure Game from a Newbie

Postby micseydel » Tue Jan 28, 2014 6:36 pm

Git is a fantastic tool to use locally even if you don't use Github. Although the extra work for using Github ("git push" once it's setup) is so meager that it's well worth it.

Git is nice even for simple local dev without collaboration because it saves versions. It's fantastic for documenting the progress of your project, as well as saving good states in case of a bad one, and providing tools for identifying the problem (diffs). You really would just be using "git commit" and "git push" at first. Later you'd need "git pull" if you're collaborating, and fancy branching is worth learning but you can wait until you're comfortable with it or until you have some idea the feature is worth learning for you personally.
Join the #python-forum IRC channel on irc.freenode.net!

Please do not PM members regarding questions which are meant to be discussed publicly. The point of the forum is so that others can benefit from it. We don't want to help you over PMs or emails.
User avatar
micseydel
 
Posts: 1260
Joined: Tue Feb 12, 2013 2:18 am
Location: Mountain View, CA

Re: Text Adventure Game from a Newbie

Postby peterthesteam » Tue Jan 28, 2014 9:42 pm

Oh My - my head is completely muddled now. A copy of the code should be here
https://github.com/peterthesteam/adventuregame/blob/master/adventuretest.py
However I have to say that GitHub does not seem the place for beginners. I definitely think that a guide GitHub For Dummies should be implemented.
This is a STEEP learning curve!
Cheers All
peterthesteam
 
Posts: 5
Joined: Mon Jan 27, 2014 10:03 pm

Re: Text Adventure Game from a Newbie

Postby micseydel » Tue Jan 28, 2014 9:52 pm

Could you give us some feedback on what's so difficult? IIRC it's as simple as git init, git add, git commit, git push. And then just git commit and git push after that.
Join the #python-forum IRC channel on irc.freenode.net!

Please do not PM members regarding questions which are meant to be discussed publicly. The point of the forum is so that others can benefit from it. We don't want to help you over PMs or emails.
User avatar
micseydel
 
Posts: 1260
Joined: Tue Feb 12, 2013 2:18 am
Location: Mountain View, CA

Re: Text Adventure Game from a Newbie

Postby metulburr » Tue Jan 28, 2014 10:24 pm

Hey i see code. So it looks like you were successful. Give it time, and you will push and pull without thinking of the commands at all, i promise.

Now regarding your code. There are some bad habits that you have established that should be snuffed quickly.
1) start splitting up the code into modules (different files).
2) remove and change the code as needed to not use keyword "global"
3) change the name convention your using. Classes as only capitalized, and function names and variables start with a lower case.
4) 4 spaces as opposed to 1 tab indentaion width
New Users, Read This
OS Ubuntu 14.04, Arch Linux, Gentoo, Windows 7/8
https://github.com/metulburr
steam
User avatar
metulburr
 
Posts: 1415
Joined: Thu Feb 07, 2013 4:47 pm
Location: Elmira, NY

Re: Text Adventure Game from a Newbie

Postby Kebap » Wed Jan 29, 2014 12:06 pm

peterthesteam wrote:(git) This is a STEEP learning curve!

I feel you. I've been trying to get into git for a couple times now, but never succeeded yet. I can see its merit, and the promises do seem daunting. Maybe next time around, I'll work it out finally.
Learn: How To Ask Questions The Smart Way
Join the #python-forum IRC channel on irc.freenode.net and chat with uns directly!
Kebap
 
Posts: 390
Joined: Thu Apr 04, 2013 1:17 pm
Location: Germany, Europe

Re: Text Adventure Game from a Newbie

Postby Crimson King » Wed Jan 29, 2014 3:00 pm

As micseydel said, you'd have to learn the most basic commands (init, add, commit, etc). It's a really nice tool to have at your disposal.

Eclipse has git support (Egit), only need to right click your project -> Team -> coomit|push|pull|whatever. No terminal involved.

Give it another try and if you get stucked we'll help you out.

Good luck!
User avatar
Crimson King
 
Posts: 85
Joined: Fri Mar 08, 2013 2:42 pm
Location: Buenos Aires, Argentina

Re: Text Adventure Game from a Newbie

Postby peterthesteam » Thu Jan 30, 2014 10:07 pm

Hi There

Yup, I should have split it down into smaller chunks and put them into separate files. I suppose my trouble is, 40 years ago I played with BASIC, and at that time it was better to write as much as possible into one program. The reason was, loading up more than one file took FOREVER, and if you were on magtape, then going back to a previous file was not good. Later, when on a mainframe on RSTS, then too much file searching crippled the system for other users. Now the meanest laptop would blow those old things away.
I am not too sure where to break it down into files. Certainly the parts dealing with all the room data and the items should be in separate files, but after that all the routines seem to interact with each other, and it seems to make it easier to work with it all together.
Then comes another issue in my code. All the GLOBALs. I have tried to structure all the routines in alphabetical order for ease of working. (picture GOSUB subroutines in BASIC). I then found that I needed to use the GLOBAL to move variables between routines.
I am not sure how to get round that. I wish you could set up the variables needed with a GLOBAL at the beginning of the program.
The tab spacing seems to be a function of the IDLE editor. I just went with it!

I am grateful for all comments.
Maybe I should have started a bit smaller to start with................

Peterthesteam
peterthesteam
 
Posts: 5
Joined: Mon Jan 27, 2014 10:03 pm

Re: Text Adventure Game from a Newbie

Postby metulburr » Thu Jan 30, 2014 10:38 pm

I havent really checked well into the code, but the first step would be to split the code into classes. This will get rid of globals, and organize the code into relevant sections. Then these sections can be split into file/modules.
New Users, Read This
OS Ubuntu 14.04, Arch Linux, Gentoo, Windows 7/8
https://github.com/metulburr
steam
User avatar
metulburr
 
Posts: 1415
Joined: Thu Feb 07, 2013 4:47 pm
Location: Elmira, NY

Re: Text Adventure Game from a Newbie

Postby Kebap » Thu Jan 30, 2014 11:39 pm

Classes are a good learning, but for starters, how about pushing and popping values from functions! I don't think this was possible with basic gosub..

You said:
Code: Select all
        Command = raw_input(" \nWhat Now? >").lower()
        Check_move_command()


But maybe try something like:
Code: Select all
        Command = raw_input(" \nWhat Now? >").lower()
        result = Check_move_command(Command)


For this you would need:
Code: Select all
def Check_move_command(current_command):
    # do something with the provided command text
    return resulting_value


This also help weeding out the globals
Learn: How To Ask Questions The Smart Way
Join the #python-forum IRC channel on irc.freenode.net and chat with uns directly!
Kebap
 
Posts: 390
Joined: Thu Apr 04, 2013 1:17 pm
Location: Germany, Europe

Re: Text Adventure Game from a Newbie

Postby robgraves » Sun Mar 16, 2014 6:31 am

You can read/download the entire "Pro Git" book written by Scott Chacon on this website:

http://git-scm.com/book
User avatar
robgraves
 
Posts: 5
Joined: Tue May 21, 2013 8:57 pm
Location: Elmira, NY

Re: Text Adventure Game from a Newbie

Postby Seanliu » Mon Apr 07, 2014 10:57 am

umm... I found there was too much Syntax Errors. You are using Python like it was BASIC.

it is
Code: Select all
print("Hello World")

not
Code: Select all
print"Hello World!"

so make sure you have brackets around what you need to print. Otherwise, keep up the good work! You are never too old to learn new things!

--Seanliu
The CoDeR!


--Sean Liu
User avatar
Seanliu
 
Posts: 29
Joined: Sun Mar 30, 2014 4:03 pm

Re: Text Adventure Game from a Newbie

Postby Mekire » Mon Apr 07, 2014 11:27 am

Seanliu wrote:umm... I found there was too much Syntax Errors. You are using Python like it was BASIC.

it is
Code: Select all
print("Hello World")

not
Code: Select all
print"Hello World!"

so make sure you have brackets around what you need to print. Otherwise, keep up the good work! You are never too old to learn new things!

--Seanliu
Please be sure of the veracity of your statements before giving advice. In python 2.x you do not need parenthesis with print. This is because print is a function in python 3 but a statement in python 2.

-Mek
User avatar
Mekire
 
Posts: 987
Joined: Thu Feb 07, 2013 11:33 pm
Location: Amakusa, Japan

Re: Text Adventure Game from a Newbie

Postby Seanliu » Mon Apr 07, 2014 12:13 pm

I am running it in Python 3.x.x, because that is the new updated version.
The CoDeR!


--Sean Liu
User avatar
Seanliu
 
Posts: 29
Joined: Sun Mar 30, 2014 4:03 pm

Re: Text Adventure Game from a Newbie

Postby stranac » Mon Apr 07, 2014 12:39 pm

Yes, but not everyone is, so make sure you don't give advice which is incorrect in the situation.
Friendship is magic!

R.I.P. Tracy M. You will be missed.
User avatar
stranac
 
Posts: 1111
Joined: Thu Feb 07, 2013 3:42 pm

Re: Text Adventure Game from a Newbie

Postby micseydel » Mon Apr 07, 2014 3:52 pm

Python 2 is still the de facto standard in most places. If I were to teach a Python class, I'd use Python 2. Also, Seanliu, necroposts (typically no activity on a thread for >2 weeks) aren't generally appreciated. If you really want to add to the discussion, create a new post, link to the old one, and say what you want there. If it really is worth updating the old thread, we can let you know after we've vetted your advice.

If it's an active thread we can go ahead and have the discussion, but don't needlessly go dredging up old stuff, because people who might be long gone will get emails and then will see they looked for nothing, will turn off emails, and if something genuinely useful comes up then they'll miss out. This hurts both the community and that person who might miss out.
Join the #python-forum IRC channel on irc.freenode.net!

Please do not PM members regarding questions which are meant to be discussed publicly. The point of the forum is so that others can benefit from it. We don't want to help you over PMs or emails.
User avatar
micseydel
 
Posts: 1260
Joined: Tue Feb 12, 2013 2:18 am
Location: Mountain View, CA


Return to Completed Scripts

Who is online

Users browsing this forum: No registered users and 1 guest