specsdude
Posts: 52
Joined: Sat Jan 21, 2012 2:15 pm
Location: In a small English village, far from the eyes of Mordor

A single-file Text Adventure Game!!

Sun Jun 10, 2012 2:20 pm

Hello people,

Who is up for a quick and easy bit of fun?

Try out this tiny little text adventure game I wrote!

Controls:

n = go north
e = go east
s = go south
w = go west
r = sleep (this uses up XP!)

There is also a cheat, but it's hidden in the program... 8-)

See what level you last until!

Code: Select all

import random
import time


hp=100
ehp=75

print "Welcome, player!"
print "Your quest is to rid this barren wasteland of monsters!"
print "Your hp is currently "+str(hp)

x=15
y=15

dead=False
hammer=False

xp=0

lvl=0

thing=[None for i in range(900)]

for z in range(15):
	ex=random.randint(1,30)
	ey=random.randint(1,30)

	print ex,ey

	thing[ex*ey]="enemy"

for z in range(50):
	ex=random.randint(1,30)
	ey=random.randint(1,30)

	print ex,ey

	thing[ex*ey]="rock"

while not dead:
	#get player's direction
	oldx=x
	oldy=y
	print "You're at",str(x),",",str(y)
	print "Which way?"
	way=raw_input(":").upper()
	if way=="N":
		y-=1
	elif way=="S":
		y+=1
	elif way=="E":
		x+=1
	elif way=="W":
		x-=1
	elif way=="hammerofthor":
		hammer=True
	elif way=="R":
		print "You settle down for the night and sleep..."
		xpl=0
		for s in range(6):
			if random.random>s/10:
				xpl+=s
			time.sleep(1)
			print "z"
		print "You awaken and feel rested"
		print "<<<<< HP RESTORED >>>>>"
		print "<<<<< - "+str(xpl)+" XP >>>>>"
		xp-=xpl
		if xp<1:xp=0
		hp=100*(1.2**lvl)
		
		
	if x<1:x=1
	if x>30:x=30
	if y<1:y=1
	if y>30:y=30
	
	#level up?
	if xp>100:
		print "<<<<< LEVEL UP ! >>>>>"
		print "Health bonus : +20%"
		print "Attack bonus : +10%"
		print "Defence bonus: +15%"
		lvl+=1
		xp-=100
		
	
	#process object at x,y
	if thing[x*y]:
		print "You find a",thing[x*y]
		
		while thing[x*y]=="enemy":
			print "The enemy attacks you!"
			time.sleep(1)
			hp-=random.randint(5,20)*(0.8**lvl)
			print "Your health is now "+str(hp)
			time.sleep(1.5)
			if hp<1:
				dead=True
				break
			print "You attack the enemy!"
			time.sleep(1)
			ehp-=int(random.randint(8,25)*(1.1**lvl))
			if hammer:
				print "You strike again with your hammer!"
				ehp-=int(random.randint(5,10)*(1.1**lvl))
			print "Enemy's health is now "+str(ehp)
			time.sleep(1.5)
			if ehp<1:
				thing[x*y]=""
				print "You killed the enemy!!"
				print "<<<<< + "+str(10+(0-ehp))+" XP >>>>>>"
				xp+=10
				ehp=75
				if not hammer:
					print "You loot a hammer."
					print "<<<<< + 20 XP >>>>>>"
					xp+=20
					hammer=True
				
			
		if thing[x*y]=="rock":
			if hammer:
				print "You break up the rock with your hammer!!"
				print "<<<<< + 5 XP >>>>>>"
				xp+=5
				thing[x*y]=""
			else:
				print "There's no way through, so you go back."
				x=oldx
				y=oldy
	#level up?
	if xp>100:
		print "<<<<< LEVEL UP ! >>>>>"
		print "Health bonus : +20%"
		print "Attack bonus : +10%"
		print "Defence bonus: +15%"
		lvl+=1
		xp-=100
		hp=100*(1.2**lvl)

print "sorry, you died."

print "You got to level "+str(lvl)+" before death!"
Save it to a file and run (or use IDLE). Nothing else required!

Enjoy!! :P
Arise! Arise, riders of Théoden! Spears shall be shaken, shields shall be splintered - a sword day, a red day, ere the sun rises! Ride now! Ride now! Ride! Ride to ruin, and the world's ending! Forth Éorlingas!

User avatar
Grumpy Mike
Posts: 914
Joined: Sat Sep 10, 2011 7:49 pm
Location: Manchester (England England)
Contact: Website

Re: A single-file Text Adventure Game!!

Sun Jun 10, 2012 7:55 pm

Sounds goo I will try it thanks.

But you know this is exactly how Linux works.
You want this missing feature then you have to install xxx, but to do that then you have to decode the new form of compression. But before you can do that you have to get a tool to install the decompression program. You might find that that tool is only available on a different platform so you have to compile it.
When you compile it you find that you have missing libraries so you have to find them and install them. And that is only if you are lucky and things are straight forward.

User avatar
cheery
Posts: 219
Joined: Wed Jan 25, 2012 9:39 pm

Re: A single-file Text Adventure Game!!

Mon Jun 11, 2012 10:33 am

It was terrible, considering there was only single key, yet you had to press enter.. Also you didn't know what was in front of you.

Make it again in pygame. Or at least add some image of map into the output.

texy
Forum Moderator
Forum Moderator
Posts: 5157
Joined: Sat Mar 03, 2012 10:59 am
Location: Berkshire, England

Re: A single-file Text Adventure Game!!

Mon Jun 11, 2012 12:35 pm

Cheery's reply was grumpier than Grumpy's :lol:

Texy
Various male/female 40- and 26-way GPIO header for sale here ( IDEAL FOR YOUR PiZero ):
https://www.raspberrypi.org/forums/viewtopic.php?f=93&t=147682#p971555

User avatar
Ed Raket
Posts: 164
Joined: Mon Apr 30, 2012 4:28 pm

Re: A single-file Text Adventure Game!!

Tue Jun 12, 2012 2:01 pm

texy wrote:Cheery's reply was grumpier than Grumpy's :lol:
:mrgreen:

User avatar
Newt_Othis
Posts: 20
Joined: Tue Dec 06, 2011 1:12 pm

Re: A single-file Text Adventure Game!!

Tue Jun 12, 2012 3:24 pm

Nice!

Ahh - Text adventures - Those were the days....

You are in a dimly lit room. There is food on the floor. You are hungry.
### pick up food
+++ Don't understand 'pick up food'
### get food
+++ Don't understand 'get food'
### eat food
+++ You eat the food. It is poisoned.
GAME OVER

User avatar
extravagoose
Posts: 59
Joined: Tue May 29, 2012 2:51 pm
Location: UK
Contact: Website

Re: A single-file Text Adventure Game!!

Tue Jun 12, 2012 5:51 pm

Sounds fun... perhaps this might give some addition inspiration?
http://www.youtube.com/watch?v=hvkjP6dqpfY
RPi 1: Hostname: Gimli, 500Gb USB HDD, ArchLinux | ARM.
Main Use: Bit of everything - but mainly web server, Network Storage and C programming.

RPi 2: Hostname tba, awaiting delivery.

JustThisGuy
Posts: 114
Joined: Thu Jan 05, 2012 11:22 pm

Re: A single-file Text Adventure Game!!

Tue Jun 12, 2012 8:57 pm

Good start. It works straight up on my XP (using ActiveState's python v 2.7.2).
Any conversation about a sufficiently complex subject is indistinguishable from babble.

Return to “Python”