Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

GameFolder #1

Open
wants to merge 1 commit into
base: main
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Binary file added Game/Flatline.mp3
Binary file not shown.
273 changes: 273 additions & 0 deletions Game/Game.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,273 @@

###############################################
# Name: Justin Denison, Pete Schellingerhout, John Auman
# Date: 3/30/24 (final)
# A game with many rooms and a puzzle
# Instructions:
# 1. take key and go to room 4 to interact with chest
# 2. go to room 3 to interact with statue
# 3. go to room 2 to inteact with fireplace
#################################################

import pygame
from tkinter import *
import json

pygame.init()
pygame.mixer.init()
pygame.mixer.music.load('PsycWard.mp3')
pygame.mixer.music.play(-1)

# Class representing a room in the game
class Room(object):
def __init__(self, name, image):
# Initialize room attributes
self._name = name
self._image = image
self._exits = {}
self._items = {}
self._grabbables = []

# Getter and setter methods for room attributes
@property
def name(self):
return self._name

@name.setter
def name(self, value):
self._name = value

@property
def image(self):
return self._image

@image.setter
def image(self, value):
self._image = value

@property
def exits(self):
return self._exits

@exits.setter
def exits(self, value):
self._exits = value

@property
def items(self):
return self._items

@items.setter
def items(self, value):
self._items = value

@property
def grabbables(self):
return self._grabbables

@grabbables.setter
def grabbables(self, value):
self._grabbables = value

# Method to add an exit to the room
def addExit(self, exit, room):
self._exits[exit] = room

# Method to add an item to the room
def addItem(self, item, desc):
self._items[item] = desc

# Method to add a grabbable item to the room
def addGrabbable(self, item):
self._grabbables.append(item)

# Method to remove a grabbable item from the room
def delGrabbable(self, item):
self._grabbables.remove(item)

# Method to return a string description of the room
def __str__(self):
s = "You are in {}.\n".format(self.name)
s += "You see: "
for item in self.items.keys():
s += item + " "
s += "\n"
s += "You can carry: "
for grab in self.grabbables:
s += grab + " "
s += "\n"
s += "Exits: "
for exit in self.exits.keys():
s += exit + " "
return s


# Class representing the game
class Game(Frame):
def __init__(self, parent):
Frame.__init__(self, parent)

# Method to create rooms in the game
# Method to create rooms in the game
def createRooms(self):
with open('rooms.json') as f:
data = json.load(f)

rooms_data = data['rooms']

rooms = {}
for room_data in rooms_data:
room = Room(room_data['name'], room_data['image'])
room.exits = room_data.get('exits', {})
room.items = room_data.get('items', {})
room.grabbables = room_data.get('grabbables', [])

# Check if there's a diary item, and if so, read its content from the file
for item, desc in room.items.items():
if item.startswith("diary"):
diary_number = item.split("diary")[1]
with open(f"diary{diary_number}.txt", "r") as f:
diary_content = f.read()
room.items[item] = diary_content.strip() # Set the content of the diary

rooms[room.name] = room

# Link exits
for room_data in rooms_data:
room = rooms[room_data['name']]
for exit_dir, exit_room_name in room_data.get('exits', {}).items():
room.addExit(exit_dir, rooms[exit_room_name])

# Set initial room
Game.currentRoom = rooms['Room 1']
Game.inventory = []

def setupGUI(self):
self.pack(fill=BOTH, expand=1)
Game.player_input = Entry(self, bg="white")
Game.player_input.bind("<Return>", self.process)
Game.player_input.pack(side=BOTTOM, fill=X)
Game.player_input.focus()

img = None
Game.image = Label(self, width=int(WIDTH / 2), image=img)
Game.image.image = img
Game.image.pack(side=LEFT, fill=Y)
Game.image.pack_propagate(False)

text_frame = Frame(self, width=WIDTH / 2)

Game.text = Text(text_frame, bg="lightgrey", state=DISABLED)
Game.text.pack(fill=Y, expand=1)
text_frame.pack(side=RIGHT, fill=Y)
text_frame.pack_propagate(False)

# Method to set the current room image
def setRoomImage(self):
if (Game.currentRoom == None):
Game.img = PhotoImage(file="skull.gif")
else:
Game.img = PhotoImage(file=Game.currentRoom.image)

Game.image.config(image=Game.img)
Game.image.image = Game.img

# Method to set the status displayed on the right of the GUI
def setStatus(self, status):
Game.text.config(state=NORMAL)
Game.text.delete("1.0", END)
if (Game.currentRoom == None):
Game.text.insert(END, "You are dead")
else:
possible_actions = " Hints: \n You can type: \n -go direction \n -direction are: south, north, east, west \n -look item \n -item = check 'you see' \n -take grabbable \n -grabbable = see 'you can carry'"
Game.text.insert(END, str(Game.currentRoom) + "\nYou are carrying: " + str(
Game.inventory) + "\n\n" + status + "\n\n\n" + possible_actions)
Game.text.config(state=DISABLED)

# Method to start playing the game
def play(self):
self.createRooms()
self.setupGUI()
self.setRoomImage()
self.setStatus("")

# Method to process the player's input
def process(self, event):
action = Game.player_input.get()
action = action.lower()
response = "I don't understand. Try verb noun. Valid verbs are go, look, take."
if (action == "quit" or action == "exit" or action == "bye" or action == "sionara"):
exit(0)
if (Game.currentRoom == None):
Game.player_input.delete(0, END)
return
words = action.split()
if (len(words) == 2):
verb = words[0]
noun = words[1]

done = False

if (verb == "go"):
response = "Invalid exit."

if (noun in Game.currentRoom.exits):
Game.currentRoom = Game.currentRoom.exits[noun]
response = "Room changed."
elif (verb == "look"):
response = "I don't see that item"
if (noun in Game.currentRoom.items):
response = Game.currentRoom.items[noun]
elif verb == "interact":
# Check if the noun is interactable
if noun in ["chair", "table", "rug", "brewrig"]:
response = Game.currentRoom.items[noun]
# Handle specific interactions based on items and inventory
elif noun == "chest":
if "key" in Game.inventory and "hammer" not in Game.inventory:
response = "Interesting! The key unlocked the chest and in it you found a hammer!"
Game.inventory.append("hammer")
else:
response = "The chest is locked."
elif noun == "statue":
if "hammer" in Game.inventory and "fire extinguisher" not in Game.inventory:
response = "Interesting! The hammer smashed the statue and you found a fire extinguisher in it!"
Game.inventory.append("fire extinguisher")
else:
response = "The statue seems sturdy."
elif noun == "fireplace":
if "fire extinguisher" in Game.inventory:
response = "You have extinguished the fireplace and escaped through a hidden door!"
exit(0)
else:
response = "The fireplace crackles warmly."
elif (verb == "take"):
response = "I don't see that item"
for grabbable in Game.currentRoom.grabbables:
if (noun == grabbable):
Game.inventory.append(grabbable)
Game.currentRoom.delGrabbable(grabbable)
response = "Item grabbed"
break
self.setStatus(response)
self.setRoomImage()
Game.player_input.delete(0, END)


######################MAIN#########################

# Default size of the GUI
WIDTH = 1600
HEIGHT = 1200

# Create the window
window = Tk()
window.title("Room Adventure")

# Create the GUI as a Tkinter canvas inside the window
g = Game(window)
# Play the game
g.play()

# Wait for the window to close
window.mainloop()
Binary file added Game/PsycWard.mp3
Binary file not shown.
Binary file added Game/PsycWard.zip
Binary file not shown.
Binary file added Game/Room1.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added Game/Room10.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added Game/Room11.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added Game/Room12.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added Game/Room13.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added Game/Room14.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added Game/Room15.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added Game/Room16.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added Game/Room17.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added Game/Room18.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added Game/Room19.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added Game/Room2.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added Game/Room20.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added Game/Room21.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added Game/Room22.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added Game/Room23.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added Game/Room24.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added Game/Room3.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added Game/Room4.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added Game/Room5.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added Game/Room6.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added Game/Room7.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added Game/Room8.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added Game/Room9.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
5 changes: 5 additions & 0 deletions Game/diary1.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
4/2/22

I had an idea. After my late brother passed from the 'mystery disease' of deathicitis, I knew I had to find a solution. The only problem was a lack of patients to test my solution on and experiment with. I have so far been able to capture a few. They usually fight but it's nothing I can't handle.

Dr. Zonderstrom
5 changes: 5 additions & 0 deletions Game/diary2.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
4/30/22

I cannot believe I did not think of this sooner! I have made a lot of progress in finding a cure. I must admit at first the screams got to me a little bit but it is all in the name of Science! I am considering ramping up testing to speed up the time to find a cure.

Dr. Zonderstrom
6 changes: 6 additions & 0 deletions Game/diary3.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
5/13/22

I have hit a bit of a wall. I saw massive progress at first but in my latest test (No. 67) it seems the cure stops the disease temporarily but doesn't cure it. The only way onward is to further test. It's all in the name of my brother. I hate to admit it but I am not even bothered by the testing process anymore. Desensitization is an interesting phenomenon.

Dr. Zonderstrom

6 changes: 6 additions & 0 deletions Game/diary4.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
6/3/22

I had to ramp up work a lot but I was able to crack the problem! In trial No. 115 I tried applying the solution all at once and not over a gradual period and it led to a complete cure of the disease! The only downside to this is that it causes severe memory loss and imminent death hours after waking up. I am currently working to solve this.

Dr. Zonderstrom

6 changes: 6 additions & 0 deletions Game/diary5.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
6/21/24

Still no cure. I have begun to get headaches from the workload. I do not know if it is some form of karma for my actions. Many people have died in my experiments so far (No. 143 currently), however, it is all for the greater good. If only people would understand this is the only way to further push science! We cannot be weak-willed and allow ourselves to be bested!

Dr. Zonderstrom

15 changes: 15 additions & 0 deletions Game/diary6.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
7/3/24

I have realized that I am unfortunately ailed by the same illness that took my brother and that I dedicated myself to solving it. All before perfecting the cure. This will most likely be my last entry due to death after I risk the medicine on my own body. It is my only hope to survive. If you are reading these then I am probably one of the numerous bodies surrounding the labs. I would've liked to have been remembered, but I do not think the world would take kindly to my experiments. I will leave my medical ID here as proof of my work and a testament to my life. It might help you to identify me.

Dr. Zonderstrom

-------------------------------
- -
- Medical Identification Card -
- -
- Name: Dr Jack Zonderstrom -
- -
- Director of Pathology -
- -
-------------------------------
Loading