Skip to content
Snippets Groups Projects
Commit a9482a93 authored by Joe Stephenson's avatar Joe Stephenson
Browse files

Added lights puzzle

parent e4825c67
Branches
No related tags found
No related merge requests found
No preview for this file type
File added
No preview for this file type
......@@ -5,6 +5,7 @@ from gameparser import *
from items import *
from map import rooms
from player import *
import lightswitches
def check_complete(room):
......@@ -222,8 +223,9 @@ def execute_drop(item_id):
print("You cannot drop that")
def execute_puzzle():
#if current_room["Puzzle"] == "Decoder":
if current_room["puzzle"] == "Decoder":
decoder_puzzle()
elif current_room["puzzle"] == "Lights":
def execute_command(command):
......
class LightPuzzle:
def __init__(self):
self.statearray = [[0, 1, 0], [1, 1, 0], [0, 1, 1]]
self.solved = False
def PrintPuzzle(self):
for row in self.statearray:
rowprint = " ".join([str(tile) for tile in row])
print(rowprint)
print()
def FlipTile(self, x, y):
self.statearray[y][x] = self.ChangeState(self.statearray[y][x])
if y > 0:
self.statearray[y-1][x] = self.ChangeState(self.statearray[y-1][x])
if y < len(self.statearray) - 1:
self.statearray[y+1][x] = self.ChangeState(self.statearray[y+1][x])
if x > 0:
self.statearray[y][x-1] = self.ChangeState(self.statearray[y][x-1])
if x < len(self.statearray[y]) - 1:
self.statearray[y][x+1] = self.ChangeState(self.statearray[y][x+1])
def ChangeState(self, number):
return 0 if number == 1 else 1
def TakeEdit(self):
valid = False
while not valid:
ToChange = input("What part of the puzzle would you like to flip? Enter coordinates in the format X,Y (1-3): ")
XY = ToChange.split(",")
if len(XY) != 2 or not XY[0].isdigit() or not XY[1].isdigit():
print("Invalid input. Please enter two numbers separated by a comma.")
elif int(XY[0]) > 3 or int(XY[0]) < 1 or int(XY[1]) > 3 or int(XY[1]) < 1:
print("Invalid input. Coordinates must be between 1 and 3.")
else:
valid = True
self.FlipTile(int(XY[0]) - 1, 3 - int(XY[1]))
def StartPuzzle(self):
while not self.solved:
self.PrintPuzzle()
self.TakeEdit()
self.CheckSolved()
print("Puzzle solved!")
def CheckSolved(self):
for row in self.statearray:
if 0 in row:
return
self.solved = True
'''
def light_puzzle():
puzzle = LightPuzzle()
puzzle.StartPuzzle()'''
......@@ -34,7 +34,8 @@ On the desk you notice a cup of coffee and an empty
pack of biscuits. The reception is to the west.""",
"exits": {"west": "Reception"},
"items": [],
"puzzle": False,
"puzzle": "Lights",
"puzzle_complete": False
}
room_parking = {
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please register or to comment