d
This commit is contained in:
21
v4/main.py
21
v4/main.py
@@ -1,5 +1,6 @@
|
|||||||
from memory_test import *
|
from memory_test import *
|
||||||
from memoryCLI import *
|
from shell import *
|
||||||
|
from shell_test import *
|
||||||
import sys
|
import sys
|
||||||
|
|
||||||
print(memory_test_generateConstPlayfield())
|
print(memory_test_generateConstPlayfield())
|
||||||
@@ -11,10 +12,20 @@ print(memory_test_shouldDeselectMismatchedItems_itemTwice())
|
|||||||
print(memory_test_shouldDetectVictory())
|
print(memory_test_shouldDetectVictory())
|
||||||
print(memory_test_shouldHideMatchingItems())
|
print(memory_test_shouldHideMatchingItems())
|
||||||
|
|
||||||
c = memoryCLI_createContext()
|
print(shell_test_exit_e())
|
||||||
c = memoryCLI_greetUser(c)
|
print(shell_test_exit_exit())
|
||||||
|
print(shell_test_exit_q())
|
||||||
|
print(shell_test_exit_quit())
|
||||||
|
|
||||||
|
c = shell_createContext()
|
||||||
|
c = shell_start(c)
|
||||||
|
if c.recentField == "output":
|
||||||
print(c.output)
|
print(c.output)
|
||||||
|
|
||||||
for line in sys.stdin:
|
for line in sys.stdin:
|
||||||
ln = line.rstrip()
|
c.input = line.rstrip()
|
||||||
print(f"you entered: '{ln}'")
|
c = shell_processInput(c)
|
||||||
|
if c.recentField == "output":
|
||||||
|
print(c.output)
|
||||||
|
elif c.recentField == "exit":
|
||||||
|
break
|
||||||
|
|||||||
36
v4/shell.py
Normal file
36
v4/shell.py
Normal file
@@ -0,0 +1,36 @@
|
|||||||
|
from shell_Context import *
|
||||||
|
from llm import *
|
||||||
|
|
||||||
|
# Greet the user upon start
|
||||||
|
@llm_by_value
|
||||||
|
def shell_start(
|
||||||
|
c: shell_Context
|
||||||
|
) -> shell_Context:
|
||||||
|
c.output = "Shell.StartText"
|
||||||
|
c.recentField = "output"
|
||||||
|
return c
|
||||||
|
#}
|
||||||
|
|
||||||
|
# Switch among CLI functions based on input
|
||||||
|
#
|
||||||
|
# Conditions:
|
||||||
|
# 1. User requested to quit the game
|
||||||
|
# 2. User plays the game
|
||||||
|
@llm_by_value
|
||||||
|
def shell_processInput(
|
||||||
|
c: shell_Context
|
||||||
|
) -> shell_Context:
|
||||||
|
if (
|
||||||
|
c.input == "e" or
|
||||||
|
c.input == "exit" or
|
||||||
|
c.input == "q" or
|
||||||
|
c.input == "quit"
|
||||||
|
):
|
||||||
|
c.exit = True
|
||||||
|
c.recentField = "exit"
|
||||||
|
return c
|
||||||
|
|
||||||
|
c.output = "TODO Call all CLI functions, let them process game input"
|
||||||
|
c.recentField = "output"
|
||||||
|
return c
|
||||||
|
#}
|
||||||
8
v4/shell_Context.py
Normal file
8
v4/shell_Context.py
Normal file
@@ -0,0 +1,8 @@
|
|||||||
|
class shell_Context:
|
||||||
|
def __init__(self):
|
||||||
|
self.exit = False
|
||||||
|
self.input = ""
|
||||||
|
self.output = ""
|
||||||
|
|
||||||
|
def shell_createContext():
|
||||||
|
return shell_Context()
|
||||||
54
v4/shell_test.py
Normal file
54
v4/shell_test.py
Normal file
@@ -0,0 +1,54 @@
|
|||||||
|
from shell import *
|
||||||
|
from shell_Context import *
|
||||||
|
|
||||||
|
def shell_test_exit_e(
|
||||||
|
) -> str:
|
||||||
|
c = shell_createContext()
|
||||||
|
c.input = "e"
|
||||||
|
c = shell_processInput(c)
|
||||||
|
if (
|
||||||
|
c.recentField == "exit"
|
||||||
|
):
|
||||||
|
return "OK: shell_exit_e"
|
||||||
|
#}
|
||||||
|
return "ERR: shell_exit_e"
|
||||||
|
#}
|
||||||
|
|
||||||
|
def shell_test_exit_exit(
|
||||||
|
) -> str:
|
||||||
|
c = shell_createContext()
|
||||||
|
c.input = "exit"
|
||||||
|
c = shell_processInput(c)
|
||||||
|
if (
|
||||||
|
c.recentField == "exit"
|
||||||
|
):
|
||||||
|
return "OK: shell_exit_exit"
|
||||||
|
#}
|
||||||
|
return "ERR: shell_exit_exit"
|
||||||
|
#}
|
||||||
|
|
||||||
|
def shell_test_exit_q(
|
||||||
|
) -> str:
|
||||||
|
c = shell_createContext()
|
||||||
|
c.input = "q"
|
||||||
|
c = shell_processInput(c)
|
||||||
|
if (
|
||||||
|
c.recentField == "exit"
|
||||||
|
):
|
||||||
|
return "OK: shell_exit_q"
|
||||||
|
#}
|
||||||
|
return "ERR: shell_exit_q"
|
||||||
|
#}
|
||||||
|
|
||||||
|
def shell_test_exit_quit(
|
||||||
|
) -> str:
|
||||||
|
c = shell_createContext()
|
||||||
|
c.input = "quit"
|
||||||
|
c = shell_processInput(c)
|
||||||
|
if (
|
||||||
|
c.recentField == "exit"
|
||||||
|
):
|
||||||
|
return "OK: shell_exit_quit"
|
||||||
|
#}
|
||||||
|
return "ERR: shell_exit_quit"
|
||||||
|
#}
|
||||||
Reference in New Issue
Block a user