所以我一直在闲暇时间编写一款小型的文字冒险游戏,我正在尝试用python开发一个引人入胜的系统。
import time
from random import randint
import threading
engaged = False
class Die_Roller(object):
def __init__(self):
thread = threading.Thread(target=Dice_Ticks)
thread.daemon = True
thread.start()
def Dice_Ticks(self):
starttime = time.time
while True:
if randint(1, 10) == 3:
engaged = True
prompt()
time.sleep(1.0 - ((time.time() - starttime) % 1.0))
def prompt():
while True:
if engaged == True:
firstinput = input("A monster appears. You start fighting it")
if firstinput == "fight":
print("You fight the monster and defeat it")
engaged = False
# Now go down to otherinput until randint(1, 10) is 3 again
else:
otherinput = input("Would you like to move>\?")
if otherinput == "move":
print("You moved")
prompt()
骰子刻度应每秒执行一次,当randint为3时,怪物出现(应每10秒出现一次)。除非玩家与怪物战斗,否则玩家应该始终能够移动。我曾尝试将信号灯放入,但不确定将其放置在何处。任何帮助表示赞赏。