Skip to content

Commit c8c80e2

Browse files
committed
add command line color and modify dict
1 parent 556ea51 commit c8c80e2

File tree

5 files changed

+35
-9
lines changed

5 files changed

+35
-9
lines changed

Pipfile

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,7 @@ name = "pypi"
55

66
[packages]
77
openpyxl = "*"
8+
colorama = "*"
89

910
[dev-packages]
1011
pyinstaller = "*"

Pipfile.lock

Lines changed: 12 additions & 4 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

test.py

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
from colorama import init, Fore
2+
3+
init()
4+
print(Fore.RED+"GAME OVER!!!")
5+
print("hello")

typewords.py

Lines changed: 17 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -2,13 +2,15 @@
22
import random
33
import excel
44
import time
5+
from colorama import init, Fore#, Style # Back
56

67
class TypeWords:
78
help_cmds={"/help":"相关命令帮助", "/exit":"退出","/choose":"选类别,[99]为全部","/next":"下一个类别"}
89
params = {"exit":False, "type":99}
910
sheetnames={}
1011

1112
def __init__(self):
13+
1214
self.points = 0
1315
self.dicts={}
1416
# get words
@@ -59,31 +61,41 @@ def process_cmds(self,cmd):
5961
print("Wrong cmds:",cmd)
6062

6163
def practise(self):
64+
6265
self.help_print()
6366
self.choose_types()
6467

6568
while not self.params["exit"]:
6669
time.sleep(1)
6770
word = random.sample(list(self.dicts.keys()), 1)[0] # 随机一个字典中的key,第二个参数为限制个数
6871
leng = len(word)
69-
70-
ans = input(f'{word}\n')
71-
if ans[0]=="/":
72+
print()
73+
print(Fore.CYAN+"---points: %d---" % (self.points, ))
74+
print(Fore.WHITE+self.dicts[word])
75+
print(Fore.GREEN)
76+
print(word)
77+
print(Fore.YELLOW, end="")
78+
ans = input()
79+
# print(Fore.RESET)
80+
if len(ans) >0 and ans[0]=="/":
81+
7282
self.process_cmds(ans)
7383
continue
7484

7585
if ans == word:
7686
self.points += leng
77-
print("---%d---\n%s\n" % (self.points, self.dicts[ans]))
87+
#print(Fore.WHITE+"---%d---\n%s\n" % (self.points, self.dicts[ans]))
7888
else:
7989
self.points -= leng
8090
print("Try again... %d\n" % self.points)
8191
if self.points <= 0:
82-
print("GAME OVER!!! Your have not enough points!")
92+
print(Fore.RED+"GAME OVER!!! Your have not enough points!")
8393
input("Type any key to exit...")
94+
print(Fore.RESET+"")
8495
break
8596

8697

8798
if __name__ == '__main__':
99+
init()
88100
t = TypeWords()
89101
t.practise()

words.xlsx

2.18 KB
Binary file not shown.

0 commit comments

Comments
 (0)