Page 1 of 1

A single-file Text Adventure Game!!

Posted: Sun Jun 10, 2012 2:20 pm
by specsdude
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

Re: A single-file Text Adventure Game!!

Posted: Sun Jun 10, 2012 7:55 pm
by Grumpy Mike
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.

Re: A single-file Text Adventure Game!!

Posted: Mon Jun 11, 2012 10:33 am
by cheery
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.

Re: A single-file Text Adventure Game!!

Posted: Mon Jun 11, 2012 12:35 pm
by texy
Cheery's reply was grumpier than Grumpy's :lol:

Texy

Re: A single-file Text Adventure Game!!

Posted: Tue Jun 12, 2012 2:01 pm
by Ed Raket
texy wrote:Cheery's reply was grumpier than Grumpy's :lol:
:mrgreen:

Re: A single-file Text Adventure Game!!

Posted: Tue Jun 12, 2012 3:24 pm
by Newt_Othis
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

Re: A single-file Text Adventure Game!!

Posted: Tue Jun 12, 2012 5:51 pm
by extravagoose
Sounds fun... perhaps this might give some addition inspiration?
http://www.youtube.com/watch?v=hvkjP6dqpfY

Re: A single-file Text Adventure Game!!

Posted: Tue Jun 12, 2012 8:57 pm
by JustThisGuy
Good start. It works straight up on my XP (using ActiveState's python v 2.7.2).