Skip to content
Snippets Groups Projects
Commit 44eaaf90 authored by AnAverageProgrammer99's avatar AnAverageProgrammer99
Browse files

Light puzzle fully integrated

parent 2d1c2b2b
No related branches found
No related tags found
No related merge requests found
No preview for this file type
No preview for this file type
......@@ -2,13 +2,25 @@ import random
password = "undecoded"
def print_key():
print(1,"",2,"",3,"",4,"",5,"",6,"",7,"",8,"",9,"",10,11,12,13,14,15,16,17,18,19,20,21,22,23,24,25,26)
print("a ", "b ", "c ", "d ", "e ", "f ", "g ", "h ", "i ", "j ", "k ", "l ", "m ","n ","o ","p ","q ","r ","s ","t ","u ","v ","w ","x ","y ","z ")
def function_guessing():
function = functionSetter()
printInfo(function)
print(function)
function_guess = 0
for i in range(6, 0, -1):
function_guess = int(input("Guess a number: "))
run = True
while run:
try:
function_guess = int(input("Guess a number between -26 and 26: "))
run = False
except ValueError:
print("Enter an integer between -26 and 26")
if function_guess > function:
print("Lower")
elif function_guess < function:
......@@ -21,13 +33,10 @@ def function_guessing():
def decode():
# Allows for 2 attemps in case the user mistypes
# Allows for 2 attemps in case the user typo or mistake
for j in range(2):
print_key()
guess = input("Guess the password: ")
# TODO Remove this
if guess == "":
quit()
if guess == password:
print("CORRECT")
break
......@@ -61,8 +70,7 @@ def encode(function):
# Creates a list, where each item is a letter in the now encoded word
encoded_list = []
for item in nums_of_chars:
# This ensures that when going above 26, it goes back to 1 again
# TODO Make sure this can also work when going into negative numbers
# This ensures that when going above 26, it goes back to 1 again and when going below 1 it goes to 26
num = (item + function) % 26
if num == 0:
num = 26
......@@ -89,10 +97,20 @@ def decoder_puzzle():
'''
Runs the decoding loop, currently allowing for an infinite amount of trys to guess the function
'''
correct = False
while not correct:
for c in range(2,-1,-1):
correct = function_guessing()
if correct:
print("That is the function!")
break
else:
if c == 0:
print("You Failed")
else:
print("You have",c,"more chances!")
if correct:
decode()
else:
return False
return True
......@@ -7,9 +7,6 @@ from lightswitches import *
from map import rooms
from player import *
decoder_complete = False
lights_complete = False
def check_complete(room):
if room == rooms["Reception"]:
......@@ -227,12 +224,17 @@ def execute_drop(item_id):
def execute_puzzle():
global decoder_complete, lights_complete
"""This function runs a different puzzle depending on the room and key
in the room dictionary that determins if a puzzle is complete is set to
the output of the puzzle
"""
if current_room["puzzle"] == "Decoder":
current_room["puzzle_complete"] = decoder_puzzle()
print(current_room["puzzle_complete"])
elif current_room["puzzle"] == "Lights":
lights.StartPuzzle()
current_room["puzzle_complete"] = lights.solved
print(current_room["puzzle_complete"])
def execute_command(command):
......
......@@ -2,13 +2,10 @@ class LightPuzzle:
def __init__(self):
self.statearray = [[0, 1, 0], [1, 1, 0], [0, 1, 1]]
self.statearray = [[1, 0, 1], [0, 0, 0], [1, 0, 1]]
self.solved = False
def PrintPuzzle(self):
for row in self.statearray:
......@@ -19,9 +16,6 @@ class LightPuzzle:
print()
def FlipTile(self, x, y):
self.statearray[y][x] = self.ChangeState(self.statearray[y][x])
......@@ -42,24 +36,22 @@ class LightPuzzle:
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): ")
ToChange = input(
"What part of the puzzle would you like to flip? Enter coordinates in the format X,Y (1-3): "
)
if ToChange == "":
quit()
XY = ToChange.split(",")
if len(XY) != 2 or not XY[0].isdigit() or not XY[1].isdigit():
......@@ -74,28 +66,20 @@ class LightPuzzle:
valid = True
self.FlipTile(int(XY[0]) - 1, 3 - int(XY[1]))
def StartPuzzle(self):
while not self.solved:
for i in range(10):
print("You have", 10 - i, "go left")
self.PrintPuzzle()
self.TakeEdit()
self.CheckSolved()
if self.solved:
print("Puzzle solved!")
break
def CheckSolved(self):
......@@ -108,6 +92,4 @@ class LightPuzzle:
self.solved = True
lights = LightPuzzle()
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please register or to comment