增加问题[关闭]

问题描述 投票:0回答:0

我不知道如何增加这个游戏的问题。

t = turtle.Turtle()
t.speed(0)
t.hideturtle()
t.penup()
t.goto(-100,0)

score= turtle.Turtle()
score.speed(0)
score.hideturtle()
score.penup()
score.goto(-250,125)


#answer turtle yes
  Y= turtle.Turtle()
  Y.speed(0)
  Y.hideturtle()
  Y.penup()
  Y.goto(-50,-50)

  #answer turtle No
  N= turtle.Turtle()
  N.speed(0)
  N.hideturtle()
  N.penup()
  N.goto(50, -50)


  #num correct
  cn=0
  score.write("{}".format(cn),font= ('Arial',20))

  #currentquestion
  cq=1
  
  #key functions
  def answerY():
   global select
   select= 'y'
   evaluate()

  def answerN():
    global select
    select= 'n'
    evaluate()

  def evaluate():
    global cn
    global cq
    if correct==select:
      t.clear()
      t.write('CORRECT!',font=('Arial',10))
      time.sleep(1.5)
      score.clear()
      cn+=1
      score.write("{}".format(cn),font= ('Arial',10))
    else:
      t.clear()
      t.write('INCORRECT!The answer was {}'.format(correct),font=('Arial',50))
      time.sleep(1.5)
      t.clear()
    cq+=1
    clearboard()
    getquesnum()

  def getquesnum():
    if cq==2:
      ques2()


  def clearboard():
    t.clear()
    Y.clear()
    N.clear()


  def ques1():
    t.write('question')
    Y.write('Yes')
    N.write('No')
    global correct
    correct= 'n'

  def ques2():
    t.write('question')
    Y.write('Yes')
    N.write('No')
    global correct
    correct= 'y'


  def ques3():
    t.write('question')
    Y.write('Yes')
    N.write('No')
    global correct
    correct= 'y'

  def ques4():
   t.write('question')
   Y.write('Yes')
   N.write('No')
   global correct
   correct= 'n'
   
  def ques5():
    t.write('question')
    Y.write('Yes')
    N.write('No')
    global correct
    correct= 'y'

  s.listen()
  s.onkeypress(answerY,'y')
  s.onkey(answerN,'n')  

  ques1()

我尝试在 get question num 函数下对问题做一个 if else 语句,它仍然没有用。我不确定为什么它没有递增我使用了 cq+=1,并将它放在 if else 语句之外所以它总是会转到下一个问题。

python function increment turtle-graphics python-turtle
© www.soinside.com 2019 - 2024. All rights reserved.