#!/usr/bin/python3 # ==================================================================== # create a game data file # Note: json object contains the game data # ==================================================================== # test game/maze # # (1)==========(3) # ^ || # | || # | || '==' or '||' two way # (2)<------(0)==========(6) # || || '--' or '|' one way only # || || # || || # (4)====================(5) # # ==================================================================== # Coordinates describe the relative position of all nodes. The # coordinates fit in a bounding box where: # -1 <= x <= 1 and -1 <= y <= 1 # To plot the points, scaled the coordinates to fit in the # graphics window. # ==================================================================== import json import time game_path = 'my_simple_game.json' game = { "title": "Adventure in the Mine", "author": "Tom Wolfe", "date": "", "start_message": ''' You wake up in an abandoned mine with no idea how you got there. You need to explore the mine passages and find your way out.''', "end_message": ''' Congratulations, you have found your way out of the mine.''', 'start': 'node0', 'end': 'node0', 'nodes': { 'node0': { 'coordinates': [0.0,0.0], 'connections': [['north','node1'],['west','node2']], 'description': ''' You look around and see old mining equipment. You also see the entrances to several tunnels, but no indication of which way to go. You realize you will have to pick one at random to find your way out.''' }, 'node1': { 'coordinates': [0.0,1.0], 'connections': [['east','node3']], 'description': ''' You look around and the rock is granite. you are in a old abandoned hard rock mine. You also see the entrances to a tunnel. You realize there is only one way out.''' }, 'node2': { 'coordinates': [-1.0,0.0], 'connections': [['south','node4']], 'description': ''' You are beginning to realize that you could get lost in the tunnels. You wish you had pencil and paper to draw a map so you would not get lost. Next time you will carry some when you are out and about. You see the entrance to a tunnel. There is only one way out.''' }, 'node3': { 'coordinates': [1.0,1.0], 'connections': [['south','node6'],['west','node1']], 'description': ''' You have come out of the tunnel into a natural cave. There are many petroglyphs on the cave walls. The must have been there for thousands of years. There also several tunnels out of the cave.''' }, 'node4': { 'coordinates': [-1.0,-1.0], 'connections': [['north','node2'],['east','node5']], 'description': ''' You are starting to get hungry and thirsty. You must get out of the mine soon. Several tunnels lead away from here.''' }, 'node5': { 'coordinates': [.0,-1.0], 'connections': [['north','node6'],['west','node4']], 'description': ''' You see sunlight coming from tiny cracks in the ceiling rock. You look up thru the cracks but the are way to small for you to crawl out. However, you see several tunnels.''' }, 'node6': { 'coordinates': [1.0,0.0], 'connections': [['north','node3'],['south','node5'], ['west','node0']], 'description': ''' You have reached the junction of several tunnels. You look around and there are gold veins in the rock. You tell yourself to remember where you are so you can comeback later and get the gold.''' } } } # ==================================================================== # ---- main # ==================================================================== current_date_time = time.strftime('%Y-%m-%d %H:%M:%S') game['date'] = current_date_time with open(game_path,"w") as gp: json.dump(game, gp) gp.close() print() print(f'Game file {game_path} created at {current_date_time}') print()