adding simon module
This commit is contained in:
parent
2801a3f4cd
commit
d58ae87f8c
|
@ -1,5 +1,6 @@
|
||||||
from modules.wires import WiresModule
|
from modules.wires import WiresModule
|
||||||
from modules.button import ButtonModule
|
from modules.button import ButtonModule
|
||||||
|
from modules.simon import SimonModule
|
||||||
from modules.comp_wires import ComplicatedWiresModule
|
from modules.comp_wires import ComplicatedWiresModule
|
||||||
from modules.password import PasswordModule
|
from modules.password import PasswordModule
|
||||||
|
|
||||||
|
@ -7,7 +8,7 @@ modules = {
|
||||||
'wires': WiresModule,
|
'wires': WiresModule,
|
||||||
'button': ButtonModule,
|
'button': ButtonModule,
|
||||||
'keypad': None,
|
'keypad': None,
|
||||||
'simon': None,
|
'simon': SimonModule,
|
||||||
'first': None,
|
'first': None,
|
||||||
'memory': None,
|
'memory': None,
|
||||||
'morse': None,
|
'morse': None,
|
||||||
|
|
|
@ -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))
|
Loading…
Reference in New Issue