adding simon module

This commit is contained in:
randomuser 2023-09-26 21:41:28 -05:00
parent 2801a3f4cd
commit d58ae87f8c
2 changed files with 76 additions and 1 deletions

View File

@ -1,5 +1,6 @@
from modules.wires import WiresModule
from modules.button import ButtonModule
from modules.simon import SimonModule
from modules.comp_wires import ComplicatedWiresModule
from modules.password import PasswordModule
@ -7,7 +8,7 @@ modules = {
'wires': WiresModule,
'button': ButtonModule,
'keypad': None,
'simon': None,
'simon': SimonModule,
'first': None,
'memory': None,
'morse': None,

74
src/modules/simon.py Normal file
View File

@ -0,0 +1,74 @@
from prompt_toolkit import prompt
from prompt_toolkit.completion import WordCompleter
class SimonModule:
buttonmapping = {
"vowel": {
0: {
"red": "blue",
"blue": "red",
"green": "yellow",
"yellow": "green",
},
1: {
"red": "yellow",
"blue": "green",
"green": "blue",
"yellow": "red",
},
2: {
"red": "green",
"blue": "red",
"green": "yellow",
"yellow": "blue",
},
},
"novowel": {
0: {
"red": "blue",
"blue": "yellow",
"green": "green",
"yellow": "red",
},
1: {
"red": "red",
"blue": "blue",
"green": "yellow",
"yellow": "green",
},
2: {
"red": "yellow",
"blue": "green",
"green": "blue",
"yellow": "red",
},
},
}
def __init__(self, strikes, isvowel):
self.strikes = strikes
self.isvowel = isvowel
self.isvowel = "vowel" if isvowel else "novowel"
def convert(self, color):
return self.buttonmapping[self.isvowel][self.strikes][color]
@classmethod
def interactive(cls, state, cmdline):
try:
obj = cls(state.strikes, state.serial.vowel)
except AttributeError:
print("you need to specify a serial number before running this.")
return
while True:
print("enter information")
user_in = prompt("simon> ")
if user_in == "strike":
state.strikes += 1
obj.strikes += 1
elif user_in == "quit":
break
else:
for i in user_in.split(" "):
print(obj.convert(i))