大学经常组织你画我猜游戏,这次学习python正好写了一个游戏自动发题和记分,只需要维护题库就行。直接上源码tinyGame.py
。
运行时用
执行
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 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201
| import time
import random
def changePoint(playerPoints: dict):
str = input('输入参与者得分情况(add(sub) name point)')
cmd = str.split()
if(cmd[1] in playerPoints):
if(cmd[0] == 'add'):
playerPoints[cmd[1]] += int(cmd[2])
print(cmd[1], '增加', cmd[2], '分\n')
elif(cmd[0] == 'sub'):
playerPoints[cmd[1]] -= int(cmd[2])
print(cmd[1], '减少', cmd[2], '分\n')
else:
print('参与者姓名不存在!请重新输入\n')
def showPlayerPoints(playerPoints: dict):
print('姓名\t得分')
for p in playerPoints:
print(p, '\t', playerPoints[p])
print()
def paintAndGuess(playerPoints: dict, orinArr: list):
print('************欢迎来到你画我猜游戏************')
probNum = int(input('现在请输入每组的题量'))
probNum = probNum * len(playerPoints)
if(probNum > len(orinArr)):
print('题库题量不足!当前仅剩', len(orinArr), '题')
else:
arr = random.sample(orinArr, probNum)
for a in arr:
orinArr.remove(a)
while True:
print('输入start开始')
if(input() == 'start'):
break
for a in arr:
\# print(a)
for i in range(len(a)):
print(a[i], end=' ')
time.sleep(0.5)
print()
while True:
print('输入回车显示下一题')
if(input() == ''):
break
return orinArr
def printCmds():
print('命令\t\t作用')
print('show\t\t查看积分列表')
print('modPoint\t增加或减少积分')
print('pag\t\t你画我猜游戏')
print('help\t\t查看所有命令和用法')
print('endGame\t\t退出程序')
print('\n')
playerNum = int(input('please input the num of players\n'))
print()
players = [n for n in range(playerNum)]
playerPoints = {}
for i in range(playerNum):
print(i+1, 'player name')
players[i] = input()
playerPoints[players[i]] = 0
print('\n')
file1 = open('./paintAndGuess.txt')
orinArr = file1.read().split('\n')
orinArr.remove('')
file1.close
while True:
print('请输入要做的事,不知道要做什么请输入help')
cmd = input()
if(cmd == 'endGame'):
break
elif(cmd == 'modPoint'):
changePoint(playerPoints)
elif(cmd == 'help'):
printCmds()
elif(cmd == 'pag'):
orinArr = paintAndGuess(playerPoints, orinArr)
elif(cmd == 'show'):
showPlayerPoints(playerPoints)
else:
print('命令不存在!您可以用以下合法命令')
printCmds()
print('感谢您使用本程序')
print('请多多支持我的个人博客:https://zhm-super.github.io/')
print('也请多多支持我的CSDN博客:https://blog.csdn.net/weixin_43916065?spm=1010.2135.3001.5113')
print('输入回车退出............')
while True:
if(input() == ''):
break
|