0% found this document useful (0 votes)
4 views5 pages

Game Design Using Python

This document outlines the installation and usage of a text adventure game created with the TextAdventureEngine. It includes examples of scenes, room connections, player status, and game mechanics such as encounters and inventory management. The game involves navigating through various locations on a cursed island to ultimately escape by building a raft.

Uploaded by

ans000105
Copyright
© All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as DOCX, PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
4 views5 pages

Game Design Using Python

This document outlines the installation and usage of a text adventure game created with the TextAdventureEngine. It includes examples of scenes, room connections, player status, and game mechanics such as encounters and inventory management. The game involves navigating through various locations on a cursed island to ultimately escape by building a raft.

Uploaded by

ans000105
Copyright
© All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as DOCX, PDF, TXT or read online on Scribd

# install

pip install textadventure

# [Link] example:

[SCENE] Beach

[TEXT] You wake up on a cursed island. Crocodiles lurk; anacondas hiss in the swamp. Your food stores
are low. A lifeline flares overhead.

[OPTIONS]

[OPTION] Search shoreline

[GOTO] Shore

[OPTION] Investigate swamp

[GOTO] Swamp

...more scenes...

# [Link]

import textadventure

textadventure.load_scene("[Link]")

textadventure.start_game()

from text_adventure import TextAdventureEngine

e = TextAdventureEngine()

e.add_room('Beach', 'You are stranded on a crocodile-infested beach.')


e.add_room('Jungle', 'Dense foliage, you hear snakes.')

e.add_room('Escape', 'You’ve crafted a raft and paddle away—freedom! ', is_end=True)

e.connect_rooms('Beach', 'Jungle', 'north', 'Enter the jungle')

e.connect_rooms('Jungle', 'Escape', 'east', 'Build a raft with driftwood')

[Link]()

rooms = {

'Beach': {

'desc': 'Crocodiles are near. Limited food. Swamp to north.',

'north': 'Swamp'

},

'Swamp': {

'desc': 'Anacondas hiss. You smell danger. East: Jungle.',

'east': 'Jungle'

},

'Jungle': {

'desc': 'You find driftwood, vines—maybe build raft east.',

'east': 'Escape'

},

'Escape': {

'desc': 'You build a raft and escape—You win!',

'end': True
}

import random

rooms = {

'Beach': {'desc': 'On beach – crocs nearby. Paths: north→Swamp', 'north': 'Swamp'},

'Swamp': {'desc': 'Swamp with anacondas. Paths: south→Beach, east→Jungle',

'south': 'Beach', 'east': 'Jungle'},

'Jungle': {'desc': 'Jungle with crocodile pools. Paths: west→Swamp, north→Cliff',

'west': 'Swamp', 'north': 'Cliff'},

'Cliff': {'desc': 'Cliff overlooking sea – can build raft here.', 'south': 'Jungle'}

player = {

'location': 'Beach',

'inventory': ['food'],

'food': 3,

'flare_used': False

def show_status():

loc = player['location']

print(f"\nYou are at the {loc}: {rooms[loc]['desc']}")

print(f"Food: {player['food']}, Inventory: {player['inventory']}")


def encounter():

loc = player['location']

if loc == 'Swamp' and [Link]() < 0.4:

print("An anaconda strikes!")

return [Link]() < 0.5 # 50% survive

if loc == 'Jungle' and [Link]() < 0.5:

print("A crocodile snaps at you!")

if not player['flare_used']:

use = input("Use flare to scare it off? (yes/no) ")

if [Link]().startswith('y'):

player['flare_used'] = True

print("Flare scares it away—but now it's gone.")

return True

return [Link]() < 0.3 # lower survive chance w/out flare

return True

def game_loop():

print("🧭 Escape the Deadly Island!")

while True:

show_status()

if player['food'] <= 0:

return print("You starve... Game over.")

cmd = input("Go: ").lower().strip()

if cmd in rooms[player['location']]:
player['location'] = rooms[player['location']][cmd]

player['food'] -= 1

if not encounter():

return print("You didn't survive... Game over.")

elif cmd == 'build' and player['location'] == 'Cliff':

if 'rope' in player['inventory'] and 'wood' in player['inventory']:

return print("You build a raft and escape! You win!")

else:

print("You lack the materials (rope & wood).")

elif cmd == 'search':

loc = player['location']

if loc == 'Swamp' and 'rope' not in player['inventory']:

player['inventory'].append('rope'); print("Found rope among vines!")

elif loc == 'Jungle' and 'wood' not in player['inventory']:

player['inventory'].append('wood'); print("Collected driftwood!")

else:

print("You find nothing new.")

else:

print("Can't do that here.")

You might also like