Hello everyone!
This is the first game I have created in fusion and the game I have made is a choose your own adventure strog game, with the help of google gemeni!
Here is the link trasncript between me and google gemeni
https://docs.google.com/document/d/1zMuhdl62tHDXEHV2VbSNrdfIlPDcpH-hKM0a0BT6Ubc/edit?tab=t.0

This is my flowchart and my process of ideas on how I wanted to make my game and how the user would “win” the game
Below is the code that I used to create my game. However, you do need to instal a libary called tkinter or else it will not work. For some people they are unable to do that. Thus I have recorded a yotube video that will go over my code and game. Here is the video.
Here is my code
CODE
import tkinter as tk
# Player inventory, accessible by all functions.
inventory = {
“gold”: 0,
“sword”: False,
“biscuit”: False,
“strange_key”: False
}
def clear_screen():
for widget in root.winfo_children():
widget.destroy()
# — Functions for Game Choices —
def fight_the_bear():
clear_screen()
if inventory[“sword”] == True:
story_text = “You draw the sharp sword you found in the chest and kill the bear good job”
continue_button = tk.Button(root, text=”Search the Cave”, command=bear_cave_chest)
continue_button.pack()
else:
story_text = “You try fighting the bear with your fists?? wow no surpise you get clapped and died L noob.”
story_label = tk.Label(root, text=story_text)
story_label.pack()
play_again_button = tk.Button(root, text=”Play Again”, command=start_game)
play_again_button.pack()
def bear_cave_chest():
clear_screen()
inventory[“strange_key”] = True
story_label = tk.Label(root, text=”Deeper in the cave, you find the bear’s treasure chest. Inside is a strange key.”)
story_label.pack()
back_button = tk.Button(root, text=”Take key and go back”, command=start_game)
back_button.pack()
def hide_from_bear():
clear_screen()
if inventory[“biscuit”] == True:
story_text = “you hide and live off the biscut. a hunter comes and saves you, you win!”
else:
story_text = “You hide but you died of starvation, L noob”
story_label = tk.Label(root, text=story_text)
story_label.pack()
play_again_button = tk.Button(root, text=”Play Again”, command=start_game)
play_again_button.pack()
def wolf_attack():
clear_screen()
story_label = tk.Label(root, text=”You hear some howls, you get surrounded by wolves and you died L noob.”)
story_label.pack()
play_again_button = tk.Button(root, text=”Play Again”, command=start_game)
play_again_button.pack()
def meet_bear():
clear_screen()
story_label = tk.Label(root, text=”You see a big brown bear.”)
story_label.pack()
fight_button = tk.Button(root, text=”Fight the bear”, command=fight_the_bear)
fight_button.pack()
hide_button = tk.Button(root, text=”Try to hide”, command=hide_from_bear)
hide_button.pack()
def deeper_in_cave():
clear_screen()
story_label = tk.Label(root, text=”The cave is damp and you hear a strange noise.”)
story_label.pack()
continue_button = tk.Button(root, text=”Follow the noise”, command=meet_bear)
continue_button.pack()
def go_in_spooky_cave():
clear_screen()
story_label = tk.Label(root, text=”You step into the spooky cave…”)
story_label.pack()
continue_button = tk.Button(root, text=”Continue”, command=deeper_in_cave)
continue_button.pack()
def leave_spooky_cave():
clear_screen()
story_label = tk.Label(root, text=”You decide not to risk it and leave.”)
story_label.pack()
continue_button = tk.Button(root, text=”You walk for some time…”, command=wolf_attack)
continue_button.pack()
def find_spooky_cave():
clear_screen()
story_text = “It’s getting dark, luckily you find a spooky suspicious evil looking cave.”
story_label = tk.Label(root, text=story_text)
story_label.pack()
in_button = tk.Button(root, text=”Go in”, command=go_in_spooky_cave)
in_button.pack()
leave_button = tk.Button(root, text=”Leave”, command=leave_spooky_cave)
leave_button.pack()
def open_chest():
global inventory
clear_screen()
inventory[“gold”] += 1
inventory[“sword”] = True
story_text = f”You open the chest and find a sharp sword and 1 gold piece!\n(Gold: {inventory[‘gold’]})”
story_label = tk.Label(root, text=story_text)
story_label.pack()
back_button = tk.Button(root, text=”Go Back”, command=start_game)
back_button.pack()
def try_door():
clear_screen()
if inventory[“strange_key”] == True:
# WINNER: The player has the key
story_text = “You place the sdFSDFDF0101 F key sdFsda0101fS in”
story_label = tk.Label(root, text=story_text)
story_label.pack()
story_text = “you’ve escaped the matrix! … or have U?”
story_label = tk.Label(root, text=story_text)
story_label.pack()
continue_button = tk.Button(root, text=”Continue”, command=show_credits)
continue_button.pack()
else:
story_label = tk.Label(root, text=”The key doesn’t fit the door. It remains locked.”)
story_label.pack()
back_button = tk.Button(root, text=”Go Back”, command=go_left)
back_button.pack()
def live():
global inventory
clear_screen()
inventory[“gold”] -= 1
inventory[“biscuit”] = True
story_text = f”You trade 1 gold for the biscuit.\n(Gold: {inventory[‘gold’]})”
story_label = tk.Label(root, text=story_text)
story_label.pack()
back_button = tk.Button(root, text=”Go Back”, command=start_game)
back_button.pack()
def show_credits():
clear_screen()
story_label = tk.Label(root, text=”Game Created By Tiger wei and thanks to gemeni!\n\nThanks for playing.”)
story_label.pack()
play_again_button = tk.Button(root, text=”Play Again”, command=start_game)
play_again_button.pack()
def go_away():
clear_screen()
story_label = tk.Label(root, text=”You walk the other way towards a crossroad.”)
story_label.pack()
continue_button = tk.Button(root, text=”Continue”, command=find_spooky_cave)
continue_button.pack()
def meet_trader():
global inventory
clear_screen()
if inventory[“gold”] >= 1:
story_text = f”The shady trader sees your gold.\n’Care for a biscuit? Just 1 gold piece.’\n(You have: {inventory[‘gold’]} gold)”
story_label = tk.Label(root, text=story_text)
story_label.pack()
live_button = tk.Button(root, text=”Trade with him”, command=live)
live_button.pack()
away_button = tk.Button(root, text=”No thanks”, command=go_away)
away_button.pack()
else:
story_text = f”The shady trader looks you over, sees you have no gold, and scoffs.\n’Don’t waste my time.’\n(You have: {inventory[‘gold’]} gold)”
story_label = tk.Label(root, text=story_text)
story_label.pack()
back_button = tk.Button(root, text=”Go Back”, command=go_right)
back_button.pack()
def go_left():
clear_screen()
story_label = tk.Label(root, text=”You walk down a path and find a shiny key.”)
story_label.pack()
chest_button = tk.Button(root, text=”Open Chest”, command=open_chest)
chest_button.pack()
door_button = tk.Button(root, text=”Try Door”, command=try_door)
door_button.pack()
back_button = tk.Button(root, text=”Go Back”, command=start_game)
back_button.pack()
def go_right():
clear_screen()
story_label = tk.Label(root, text=”You walk towards a river. The water is flowing quickly.”)
story_label.pack()
trader_button = tk.Button(root, text=”Meet the shady trader”, command=meet_trader)
trader_button.pack()
away_button = tk.Button(root, text=”Go away from the river”, command=go_away)
away_button.pack()
back_button = tk.Button(root, text=”Go Back”, command=start_game)
back_button.pack()
def start_game():
clear_screen()
story_label = tk.Label(root, text=”You wake up in a dark forest. You can go left or right.”)
story_label.pack()
left_button = tk.Button(root, text=”Go Left”, command=go_left)
left_button.pack()
right_button = tk.Button(root, text=”Go Right”, command=go_right)
right_button.pack()
# — Main Program Setup —
root = tk.Tk()
root.title(“My Adventure Game”)
root.geometry(“400×300”)
start_button = tk.Button(root, text=”Start Game”, command=start_game)
start_button.pack()
root.mainloop()
EXPLAIN CODE
Here I will explain what all my code does in a very simple manner so that everyone can understand
Libraries
for this project, you need to install the tinker library for python. If u do not, this code will not work. Here is a link to the library so you can download it
https://www.tcl-lang.org/software/tcltk/download.html
import tkinter as tk
This code is very important as it brings the tinker library into our code and allows us to do actions like creating a new window and adding a button
inventory = {
“gold”: 0,
“sword”: False,
“biscuit”: False,
“strange_key”: False
}
This code creates our inventory and allows for different results in our game. We can set these items to 0 or false
def clear_screen():
for widget in root.winfo_children():
widget.destroy()
This code creates a function that erases the screen after a choice is made and we use this everytime we’ve made a choice in the game
FUNCTIONS
In my game I have alot of functions like
EX.
def fight_the_bear() :
def hide_from_bear() :
def go_left() :
def go_right() :
each of theese functions are like pages in our story. Each of these functions is the pages that allow the player to choose between 2 actions
MAIN REPEATED CODE
In my game all of the options and text afterwards are all construced by 4 different set of codes
story_label = tk.Label(root, text=)
this code makes the lines of text you see before you click on one of the buttons
X_button.pack()
This code makes our buttons actually function and acts like a hand that flips the page after each choice
Story_text = X
This is the code that displays a longer line of text after you have clicked on one of the buttons and made your choice
X_Button = tk.Button(root, text=””z, command =Y)
This is one of teh msot important part’s of our code. This code creates the buttons for our game. X has to be part of one of our functions so that it can connect back to it. Z is the text that will be displayed on the button (EX. Go left). Y is the next function or scene we want to go to after we click on this button (EX. We click on go left Go Left => Open Chest) we would put Open_Chest where Y is and it would lead us to that scene.
More EX.
continue_button = tk.Button(root, text=”Follow the noise”, command=meet_bear)
This will display a continue button and move us to the scene where we meet the bear
Leave a Reply