Python Turtle screenclick 给出了不正确的定位

发布于 2025-01-16 12:06:30 字数 7270 浏览 0 评论 0原文

我正在创造我自己的危险!游戏的乐趣和乐趣使用 Python 和 Turtle mod 的经验。我试图在用户点击美元金额后向他们读取线索,但点击次数与我设置的字典中的线索或答案不一致。

例如,如果我单击神话下的“$400”,它会在 Youtubers 线索下为我提供“$200”,并且输入的答案都不会返回“正确”的 if 语句。

在这里编码:(为了节省时间,请仔细查看 getgridposition() 和 screenclicked() 函数,我认为我的错误就在那里......)

from turtle import *
import random
import time
global score

s = 6  # s by s grid
L = 100 #each grid element will be L x L pixels
t = Turtle()
score=0
speed(10)

category_names=["Youtubers","  Stones"," Mythology","  Animals","    Words","Hodge Podge"]

point_names2=["$200","$200","$200","$200","$200","$200"]
point_names4=["$400","$400","$400","$400","$400","$400"]
point_names6=["$600","$600","$600","$600","$600","$600"]
point_names8=["$800","$800","$800","$800","$800","$800"]
point_names1=["$1000","$1000","$1000","$1000","$1000","$1000"]

# Question/Answer Content
categories = [
  # Youtubers
  [
    ["By 2018, this youtuber had given out $1 million through his outlandish stunts, which earned him the title of \"YouTube's biggest philanthropist\".", "Who is Mr. Beast?"],
    ["Originally started by Ian Hecox and Daniel Padilla, this Youtube comedy group now has 10 channels. One of which is entitled \"The Big What If\".", "Who is Smosh?"],
    ["This duo got their start from a reality show called \"Commercial Kings\". Now, their entertainment company owns over 13 media productions including Smosh... Not a sponsor.","Who are Rhett and Link?"],
    ["This Swedish video game was one of the first of its kind to gain exposure from Youtube with now over a trillion views. Now that's crafty!","What is Minecraft?"],
    ["The Vlog Squad, a popular group whose videos only last 4 minutes and 20 seconds each, includes this actor who starred in Nickelodeon's \"Drake and Josh\"","Who is Josh Peck?"],
  ],
  # Stones
  [
    ["Although its toy counterpart is rarely made of it, this stone is a metamorphic rock predominantly composed of calcite or dolomite crystals.","What is marble?"],
    ["This stone, latin for Red, is next in line as hard as diamonds. So... you probably shouldn't make any slippers out of it.","What is ruby?"],
    ["This \"Stone\" played the notoriously fashionable villain in the 2021 remake of 101 Dalmations, daaahling!","Who is Emma Stone?"],
    ["Currently located in the British Museum, this holds the key to understanding Egyptian Hieroglyphs.","What is the Rosetta Stone?"],
    ["This is a mythical alchemical substance capable of turning base metals such as mercury into gold or silver.","What is philosopher's stone?"],
  ],
  
  # Mythology
  [
    ["Today's Athens is named after this Greek goddess of wisdon, knowledge, and civilization.","Who is Athena?"],
    ["A nymph by this name was ordered to distract Hera from Zeus's affairs. Once Hera found out, the nymph was cursed to only ever repeat the words of others, others, others.","Who is Echo?"],
    ["This creature was protrayed with the head and tail of a bull and the body of a man.","What is a minotaur?"],
    ["Depending on where you get your story, this daugter of Creon was either murdered by her husband Heracles, or just divorced him after he murdered their children.","Who is Megara?"],
    ["Although a brother to Zeus & Poseidon, this Greek god was not considered an olympian because of his dwellings in the underworld.","Who is Hades?"],
  ],
    # Animals
  [
    ["It's the Italian name for squid, whose meat is firm and chewy.","What is calamari?"],
    ["Shere Kahn, Mowgli's Nemesis.","What is a tiger?"],
    ["Koalas have adapted their diet with an extra long gut to break down poisons in these leaves and sleep 20 hours a day due to a lack of nutrition in the leaves.","What is eucalyptus?"],
    ["This scientific name is used for an animal with a pouch.","What is a marsupial?"],
    ["Emily Dickinson’s poem about this kind of animal begins, \"A narrow fellow in the grass\" and ends, \"zero at the bone.\"","What is a snake?"],
  ],
    # Words
  [
    ["In the Spanish Dictionary, you’ll find zócalo for a main square & this masculine word for shoe.","What is zapato?"],
    ["You’ll find it listed as a synonym for \"enjoy\" or described as a type of condiment","What is relish?"],
    ["The back of the neck.","What is nape?"],
    ["This French feminine word is a person with brown hair.","What is brunette?"],
    ["In \'The Big Bang Theory\", Sheldon uses this interjection to rub a good joke in his friends' faces.","What is bazinga?"],
  ],
   # Hodge Podge
  [
    ["This flavoring comes from a combination of coffee & chocolate.","What is mocha?"],
    ["Blown wind instruments are divided into woodwinds & these.","What is brass?"],
    ["People magazine once said the guys in motley crue sported about 60 of these dermal decorations","What are tattoos?"],
    ["According to Timon and Pumba, this two word Swahili phrase is a problem free philosphy.","What is hakuna matata?"],
    ["This piece in chess can only move in an \"L\" shape across the board.","What is a knight?"],
  ]
]


def grid():#makes the play grid
    sign = 1
    t = Turtle()
    l = 100
    screen = Screen()
    speed(0)
    t.penup()
    t.goto(-300,-300)
    t.pendown()
    for _ in range(2):#range 2 gives vertical and horizontal lines; range (1) would just give horizontal

        for _ in range(s):
            t.forward(l * s)
            t.left(sign * 90)
            t.forward(l)
            t.left(sign * 90)
            sign = 0 - sign

        t.forward(l * s)#this stops the line at the top from keeping going zigzag all the way up.
        [t.right, t.left][s % 2](90)
        sign = 0 - sign

def gameboard():
    grid()
gameboard()


def naming():#writes the markings of points
  penup()
  goto(-260,150)#200
  for point in point_names2:
    write(point)
    fd(100)

  goto(-260,50)#400
  for point in point_names4:
    write(point)
    fd(100)
    
  goto(-260,-50)#600
  for point in point_names6:
    write(point)
    fd(100)

  goto(-260,-150)#800
  for point in point_names8:
    write(point)
    fd(100)

  goto(-260,-250)#1000
  for point in point_names1:
    write(point)
    fd(100)


  goto(-280,250)#-260,185; 250 positions the categories vertically

  for category in category_names:#naming of the categories
    write(category)
    fd(100)#90

naming()

def getgridposition(x,y):
  row = (200-y)//100
  col = (x+200)//80
  return [int(col),int(row)]

def whiteout(x,y):
  goto(x,y)
  color("white")
  pendown()
  backward(20)
  pensize (20)
  forward(40)
  pensize(5)
  penup()


def screenclicked(x, y):#runs when the screen is clicked  
  t=Turtle()
  global score
  whiteout(x,y)
  pos=getgridposition(x,y)
  
  col = pos[0]
  row = pos[1]
  

  a=input(categories[col][row][0])
  s=(categories[col][row][1])
  if a.lower()== s.lower():
      points= (row+1)*200
      print("Correct!")
      score=score+points
      print("This is your total score: $" + str(score))
      time.sleep(1)
      print("Select again.")  
  else:
      points= (row+1)*200
      print("I'm sorry, that is incorrect.")
      score=score-points
      print("This is your total score: $" + str(score))
      time.sleep(1)
      print("Select again.")
      
screen = getscreen()#invoke screen clicks 
screen.onclick(screenclicked)

I'm creating my own Jeopardy! game for fun & experience using Python and a Turtle mod. I'm trying to get the clues read to the user after they click a dollar amount, but the clicks aren't aligning with the clues or answers from in the dictionaries I set.

For example, if I click "$400" under Mythology, it gives me the "$200" under Youtubers clue, and neither answer typed returns the "Correct" if statement.

Coding here: (to save time, look closely at the getgridposition() and screenclicked() functions, I think my error is somewhere in there...)

from turtle import *
import random
import time
global score

s = 6  # s by s grid
L = 100 #each grid element will be L x L pixels
t = Turtle()
score=0
speed(10)

category_names=["Youtubers","  Stones"," Mythology","  Animals","    Words","Hodge Podge"]

point_names2=["$200","$200","$200","$200","$200","$200"]
point_names4=["$400","$400","$400","$400","$400","$400"]
point_names6=["$600","$600","$600","$600","$600","$600"]
point_names8=["$800","$800","$800","$800","$800","$800"]
point_names1=["$1000","$1000","$1000","$1000","$1000","$1000"]

# Question/Answer Content
categories = [
  # Youtubers
  [
    ["By 2018, this youtuber had given out $1 million through his outlandish stunts, which earned him the title of \"YouTube's biggest philanthropist\".", "Who is Mr. Beast?"],
    ["Originally started by Ian Hecox and Daniel Padilla, this Youtube comedy group now has 10 channels. One of which is entitled \"The Big What If\".", "Who is Smosh?"],
    ["This duo got their start from a reality show called \"Commercial Kings\". Now, their entertainment company owns over 13 media productions including Smosh... Not a sponsor.","Who are Rhett and Link?"],
    ["This Swedish video game was one of the first of its kind to gain exposure from Youtube with now over a trillion views. Now that's crafty!","What is Minecraft?"],
    ["The Vlog Squad, a popular group whose videos only last 4 minutes and 20 seconds each, includes this actor who starred in Nickelodeon's \"Drake and Josh\"","Who is Josh Peck?"],
  ],
  # Stones
  [
    ["Although its toy counterpart is rarely made of it, this stone is a metamorphic rock predominantly composed of calcite or dolomite crystals.","What is marble?"],
    ["This stone, latin for Red, is next in line as hard as diamonds. So... you probably shouldn't make any slippers out of it.","What is ruby?"],
    ["This \"Stone\" played the notoriously fashionable villain in the 2021 remake of 101 Dalmations, daaahling!","Who is Emma Stone?"],
    ["Currently located in the British Museum, this holds the key to understanding Egyptian Hieroglyphs.","What is the Rosetta Stone?"],
    ["This is a mythical alchemical substance capable of turning base metals such as mercury into gold or silver.","What is philosopher's stone?"],
  ],
  
  # Mythology
  [
    ["Today's Athens is named after this Greek goddess of wisdon, knowledge, and civilization.","Who is Athena?"],
    ["A nymph by this name was ordered to distract Hera from Zeus's affairs. Once Hera found out, the nymph was cursed to only ever repeat the words of others, others, others.","Who is Echo?"],
    ["This creature was protrayed with the head and tail of a bull and the body of a man.","What is a minotaur?"],
    ["Depending on where you get your story, this daugter of Creon was either murdered by her husband Heracles, or just divorced him after he murdered their children.","Who is Megara?"],
    ["Although a brother to Zeus & Poseidon, this Greek god was not considered an olympian because of his dwellings in the underworld.","Who is Hades?"],
  ],
    # Animals
  [
    ["It's the Italian name for squid, whose meat is firm and chewy.","What is calamari?"],
    ["Shere Kahn, Mowgli's Nemesis.","What is a tiger?"],
    ["Koalas have adapted their diet with an extra long gut to break down poisons in these leaves and sleep 20 hours a day due to a lack of nutrition in the leaves.","What is eucalyptus?"],
    ["This scientific name is used for an animal with a pouch.","What is a marsupial?"],
    ["Emily Dickinson’s poem about this kind of animal begins, \"A narrow fellow in the grass\" and ends, \"zero at the bone.\"","What is a snake?"],
  ],
    # Words
  [
    ["In the Spanish Dictionary, you’ll find zócalo for a main square & this masculine word for shoe.","What is zapato?"],
    ["You’ll find it listed as a synonym for \"enjoy\" or described as a type of condiment","What is relish?"],
    ["The back of the neck.","What is nape?"],
    ["This French feminine word is a person with brown hair.","What is brunette?"],
    ["In \'The Big Bang Theory\", Sheldon uses this interjection to rub a good joke in his friends' faces.","What is bazinga?"],
  ],
   # Hodge Podge
  [
    ["This flavoring comes from a combination of coffee & chocolate.","What is mocha?"],
    ["Blown wind instruments are divided into woodwinds & these.","What is brass?"],
    ["People magazine once said the guys in motley crue sported about 60 of these dermal decorations","What are tattoos?"],
    ["According to Timon and Pumba, this two word Swahili phrase is a problem free philosphy.","What is hakuna matata?"],
    ["This piece in chess can only move in an \"L\" shape across the board.","What is a knight?"],
  ]
]


def grid():#makes the play grid
    sign = 1
    t = Turtle()
    l = 100
    screen = Screen()
    speed(0)
    t.penup()
    t.goto(-300,-300)
    t.pendown()
    for _ in range(2):#range 2 gives vertical and horizontal lines; range (1) would just give horizontal

        for _ in range(s):
            t.forward(l * s)
            t.left(sign * 90)
            t.forward(l)
            t.left(sign * 90)
            sign = 0 - sign

        t.forward(l * s)#this stops the line at the top from keeping going zigzag all the way up.
        [t.right, t.left][s % 2](90)
        sign = 0 - sign

def gameboard():
    grid()
gameboard()


def naming():#writes the markings of points
  penup()
  goto(-260,150)#200
  for point in point_names2:
    write(point)
    fd(100)

  goto(-260,50)#400
  for point in point_names4:
    write(point)
    fd(100)
    
  goto(-260,-50)#600
  for point in point_names6:
    write(point)
    fd(100)

  goto(-260,-150)#800
  for point in point_names8:
    write(point)
    fd(100)

  goto(-260,-250)#1000
  for point in point_names1:
    write(point)
    fd(100)


  goto(-280,250)#-260,185; 250 positions the categories vertically

  for category in category_names:#naming of the categories
    write(category)
    fd(100)#90

naming()

def getgridposition(x,y):
  row = (200-y)//100
  col = (x+200)//80
  return [int(col),int(row)]

def whiteout(x,y):
  goto(x,y)
  color("white")
  pendown()
  backward(20)
  pensize (20)
  forward(40)
  pensize(5)
  penup()


def screenclicked(x, y):#runs when the screen is clicked  
  t=Turtle()
  global score
  whiteout(x,y)
  pos=getgridposition(x,y)
  
  col = pos[0]
  row = pos[1]
  

  a=input(categories[col][row][0])
  s=(categories[col][row][1])
  if a.lower()== s.lower():
      points= (row+1)*200
      print("Correct!")
      score=score+points
      print("This is your total score: 
quot; + str(score))
      time.sleep(1)
      print("Select again.")  
  else:
      points= (row+1)*200
      print("I'm sorry, that is incorrect.")
      score=score-points
      print("This is your total score: 
quot; + str(score))
      time.sleep(1)
      print("Select again.")
      
screen = getscreen()#invoke screen clicks 
screen.onclick(screenclicked)

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

美人迟暮 2025-01-23 12:06:30

考虑到你的棋盘结构,你的 getgridposition() 确实看起来不正确:

def getgridposition(x,y):
  row = (200-y)//100
  col = (x+200)//80
  return [int(col),int(row)]

更像下面的东西使游戏基本上可以玩,但并不完美:

from math import floor

def getgridposition(x, y):
    col = floor(x / 100) + 3
    row = 2 - floor((y + 50) / 100)

    return (col, row)

但是你也应该尝试对此进行编码(以及你的其他元素)代码)根据您的电路板尺寸(即您的 sL 常量。)以下是我在尝试理解您的问题时对您的代码进行的修改:

from turtle import Screen, Turtle
from math import floor

SIZE = 6  # s by s grid
LENGTH = 100  # each grid element will be L x L pixels

category_names = ["Youtubers", "  Stones", " Mythology", "  Animals", "    Words", "Hodge Podge"]

point_names2 = ["$200"] * SIZE
point_names4 = ["$400"] * SIZE
point_names6 = ["$600"] * SIZE
point_names8 = ["$800"] * SIZE
point_names10 = ["$1000"] * SIZE

# Question/Answer Content
categories = [
    # Youtubers
    [
        ["By 2018, this youtuber had given out $1 million through his outlandish stunts, which earned him the title of \"YouTube's biggest philanthropist\".", "Who is Mr. Beast?"],
        ["Originally started by Ian Hecox and Daniel Padilla, this Youtube comedy group now has 10 channels. One of which is entitled \"The Big What If\".", "Who is Smosh?"],
        ["This duo got their start from a reality show called \"Commercial Kings\". Now, their entertainment company owns over 13 media productions including Smosh... Not a sponsor.", "Who are Rhett and Link?"],
        ["This Swedish video game was one of the first of its kind to gain exposure from Youtube with now over a trillion views. Now that's crafty!", "What is Minecraft?"],
        ["The Vlog Squad, a popular group whose videos only last 4 minutes and 20 seconds each, includes this actor who starred in Nickelodeon's \"Drake and Josh\"", "Who is Josh Peck?"],
    ],
    # Stones
    [
        ["Although its toy counterpart is rarely made of it, this stone is a metamorphic rock predominantly composed of calcite or dolomite crystals.", "What is marble?"],
        ["This stone, latin for Red, is next in line as hard as diamonds. So... you probably shouldn't make any slippers out of it.", "What is ruby?"],
        ["This \"Stone\" played the notoriously fashionable villain in the 2021 remake of 101 Dalmations, daaahling!", "Who is Emma Stone?"],
        ["Currently located in the British Museum, this holds the key to understanding Egyptian Hieroglyphs.", "What is the Rosetta Stone?"],
        ["This is a mythical alchemical substance capable of turning base metals such as mercury into gold or silver.", "What is philosopher's stone?"],
    ],
    # Mythology
    [
        ["Today's Athens is named after this Greek goddess of wisdom, knowledge, and civilization.", "Who is Athena?"],
        ["A nymph by this name was ordered to distract Hera from Zeus's affairs. Once Hera found out, the nymph was cursed to only ever repeat the words of others, others, others.", "Who is Echo?"],
        ["This creature was portrayed with the head and tail of a bull and the body of a man.", "What is a minotaur?"],
        ["Depending on where you get your story, this daughter of Creon was either murdered by her husband Heracles, or just divorced him after he murdered their children.", "Who is Megara?"],
        ["Although a brother to Zeus & Poseidon, this Greek god was not considered an olympian because of his dwellings in the underworld.", "Who is Hades?"],
    ],
    # Animals
    [
        ["It's the Italian name for squid, whose meat is firm and chewy.", "What is calamari?"],
        ["Shere Kahn, Mowgli's Nemesis.", "What is a tiger?"],
        ["Koalas have adapted their diet with an extra long gut to break down poisons in these leaves and sleep 20 hours a day due to a lack of nutrition in the leaves.", "What is eucalyptus?"],
        ["This scientific name is used for an animal with a pouch.", "What is a marsupial?"],
        ["Emily Dickinson’s poem about this kind of animal begins, \"A narrow fellow in the grass\" and ends, \"zero at the bone.\"", "What is a snake?"],
    ],
    # Words
    [
        ["In the Spanish Dictionary, you’ll find zócalo for a main square & this masculine word for shoe.", "What is zapato?"],
        ["You’ll find it listed as a synonym for \"enjoy\" or described as a type of condiment", "What is relish?"],
        ["The back of the neck.", "What is nape?"],
        ["This French feminine word is a person with brown hair.", "What is brunette?"],
        ["In \'The Big Bang Theory\", Sheldon uses this interjection to rub a good joke in his friends' faces.", "What is bazinga?"],
    ],
    # Hodge Podge
    [
        ["This flavoring comes from a combination of coffee & chocolate.", "What is mocha?"],
        ["Blown wind instruments are divided into woodwinds & these.", "What is brass?"],
        ["People magazine once said the guys in motley crüe sported about 60 of these dermal decorations", "What are tattoos?"],
        ["According to Timon and Pumba, this two word Swahili phrase is a problem free philosophy.", "What is hakuna matata?"],
        ["This piece in chess can only move in an \"L\" shape across the board.", "What is a knight?"],
    ]
]

def gameboard():  # makes the play grid
    turtle.penup()
    turtle.goto(-LENGTH/2 * SIZE, -LENGTH/2 * SIZE)
    turtle.pendown()

    angle = 90

    for _ in range(2):  # range 2 gives vertical and horizontal lines; range (1) would just give horizontal

        for _ in range(SIZE):
            turtle.forward(LENGTH * SIZE)
            turtle.left(angle)
            turtle.forward(LENGTH)
            turtle.left(angle)
            angle = -angle

        turtle.forward(LENGTH * SIZE)  # this stops the line at the top from keeping going zigzag all the way up.
        [turtle.right, turtle.left][SIZE % 2](90)
        angle = -angle

def naming():  # writes the markings of points
    turtle.penup()
    turtle.setheading(0)
    turtle.goto(-260, 150)  # 200

    for point in point_names2:
        turtle.write(point)
        turtle.forward(100)

    turtle.goto(-260, 50)  # 400

    for point in point_names4:
        turtle.write(point)
        turtle.forward(100)

    turtle.goto(-260, -50)  # 600

    for point in point_names6:
        turtle.write(point)
        turtle.forward(100)

    turtle.goto(-260, -150)  # 800

    for point in point_names8:
        turtle.write(point)
        turtle.forward(100)

    turtle.goto(-260, -250)  # 1000

    for point in point_names10:
        turtle.write(point)
        turtle.forward(100)

    turtle.goto(-280, 250)  # -260,185; 250 positions the categories vertically

    for category in category_names:  # naming of the categories
        turtle.write(category)
        turtle.forward(100)  # 9 0

def getgridposition(x, y):
    col = floor(x / LENGTH) + 3
    row = 2 - floor((y + LENGTH/2) / LENGTH)

    return (col, row)

def whiteout(x, y):
    turtle.goto(x, y)
    turtle.color("white")
    turtle.pensize(20)

    turtle.pendown()
    turtle.backward(20)
    turtle.forward(40)
    turtle.penup()

    turtle.pensize(5)

score = 0

def screenclicked(x, y):  # runs when the screen is clicked
    global score

    col, row = getgridposition(x, y)

    if not (0 <= col < len(CATEGORIES) and 0 <= row < len(CATEGORIES[0])):
        return

    whiteout(x, y)

    a = input(categories[col][row][0])
    s = categories[col][row][1]

    if a.lower() == s.lower():
        points = (row+1) * 200
        print("Correct!")
        score += points
        print("This is your total score: $" + str(score))
        print("Select again.")
    else:
        points = (row+1) * 200
        print("I'm sorry, that is incorrect.")
        score -= points
        print("This is your total score: $" + str(score))
        print("Select again.")

turtle = Turtle()
turtle.hideturtle()
turtle.speed('fastest')

screen = Screen()  # invoke screen clicks

gameboard()

naming()

screen.onclick(screenclicked)
screen.mainloop()

Given your board structure, your getgridposition() does seem incorrect:

def getgridposition(x,y):
  row = (200-y)//100
  col = (x+200)//80
  return [int(col),int(row)]

Something more like the following makes the game basically playable but isn't perfect:

from math import floor

def getgridposition(x, y):
    col = floor(x / 100) + 3
    row = 2 - floor((y + 50) / 100)

    return (col, row)

But you should also try to code this (and other elements of your code) in terms of the dimensions of your board (i.e. your s and L constants.) Below is my rework of your code that I did while trying to understand your problem:

from turtle import Screen, Turtle
from math import floor

SIZE = 6  # s by s grid
LENGTH = 100  # each grid element will be L x L pixels

category_names = ["Youtubers", "  Stones", " Mythology", "  Animals", "    Words", "Hodge Podge"]

point_names2 = ["$200"] * SIZE
point_names4 = ["$400"] * SIZE
point_names6 = ["$600"] * SIZE
point_names8 = ["$800"] * SIZE
point_names10 = ["$1000"] * SIZE

# Question/Answer Content
categories = [
    # Youtubers
    [
        ["By 2018, this youtuber had given out $1 million through his outlandish stunts, which earned him the title of \"YouTube's biggest philanthropist\".", "Who is Mr. Beast?"],
        ["Originally started by Ian Hecox and Daniel Padilla, this Youtube comedy group now has 10 channels. One of which is entitled \"The Big What If\".", "Who is Smosh?"],
        ["This duo got their start from a reality show called \"Commercial Kings\". Now, their entertainment company owns over 13 media productions including Smosh... Not a sponsor.", "Who are Rhett and Link?"],
        ["This Swedish video game was one of the first of its kind to gain exposure from Youtube with now over a trillion views. Now that's crafty!", "What is Minecraft?"],
        ["The Vlog Squad, a popular group whose videos only last 4 minutes and 20 seconds each, includes this actor who starred in Nickelodeon's \"Drake and Josh\"", "Who is Josh Peck?"],
    ],
    # Stones
    [
        ["Although its toy counterpart is rarely made of it, this stone is a metamorphic rock predominantly composed of calcite or dolomite crystals.", "What is marble?"],
        ["This stone, latin for Red, is next in line as hard as diamonds. So... you probably shouldn't make any slippers out of it.", "What is ruby?"],
        ["This \"Stone\" played the notoriously fashionable villain in the 2021 remake of 101 Dalmations, daaahling!", "Who is Emma Stone?"],
        ["Currently located in the British Museum, this holds the key to understanding Egyptian Hieroglyphs.", "What is the Rosetta Stone?"],
        ["This is a mythical alchemical substance capable of turning base metals such as mercury into gold or silver.", "What is philosopher's stone?"],
    ],
    # Mythology
    [
        ["Today's Athens is named after this Greek goddess of wisdom, knowledge, and civilization.", "Who is Athena?"],
        ["A nymph by this name was ordered to distract Hera from Zeus's affairs. Once Hera found out, the nymph was cursed to only ever repeat the words of others, others, others.", "Who is Echo?"],
        ["This creature was portrayed with the head and tail of a bull and the body of a man.", "What is a minotaur?"],
        ["Depending on where you get your story, this daughter of Creon was either murdered by her husband Heracles, or just divorced him after he murdered their children.", "Who is Megara?"],
        ["Although a brother to Zeus & Poseidon, this Greek god was not considered an olympian because of his dwellings in the underworld.", "Who is Hades?"],
    ],
    # Animals
    [
        ["It's the Italian name for squid, whose meat is firm and chewy.", "What is calamari?"],
        ["Shere Kahn, Mowgli's Nemesis.", "What is a tiger?"],
        ["Koalas have adapted their diet with an extra long gut to break down poisons in these leaves and sleep 20 hours a day due to a lack of nutrition in the leaves.", "What is eucalyptus?"],
        ["This scientific name is used for an animal with a pouch.", "What is a marsupial?"],
        ["Emily Dickinson’s poem about this kind of animal begins, \"A narrow fellow in the grass\" and ends, \"zero at the bone.\"", "What is a snake?"],
    ],
    # Words
    [
        ["In the Spanish Dictionary, you’ll find zócalo for a main square & this masculine word for shoe.", "What is zapato?"],
        ["You’ll find it listed as a synonym for \"enjoy\" or described as a type of condiment", "What is relish?"],
        ["The back of the neck.", "What is nape?"],
        ["This French feminine word is a person with brown hair.", "What is brunette?"],
        ["In \'The Big Bang Theory\", Sheldon uses this interjection to rub a good joke in his friends' faces.", "What is bazinga?"],
    ],
    # Hodge Podge
    [
        ["This flavoring comes from a combination of coffee & chocolate.", "What is mocha?"],
        ["Blown wind instruments are divided into woodwinds & these.", "What is brass?"],
        ["People magazine once said the guys in motley crüe sported about 60 of these dermal decorations", "What are tattoos?"],
        ["According to Timon and Pumba, this two word Swahili phrase is a problem free philosophy.", "What is hakuna matata?"],
        ["This piece in chess can only move in an \"L\" shape across the board.", "What is a knight?"],
    ]
]

def gameboard():  # makes the play grid
    turtle.penup()
    turtle.goto(-LENGTH/2 * SIZE, -LENGTH/2 * SIZE)
    turtle.pendown()

    angle = 90

    for _ in range(2):  # range 2 gives vertical and horizontal lines; range (1) would just give horizontal

        for _ in range(SIZE):
            turtle.forward(LENGTH * SIZE)
            turtle.left(angle)
            turtle.forward(LENGTH)
            turtle.left(angle)
            angle = -angle

        turtle.forward(LENGTH * SIZE)  # this stops the line at the top from keeping going zigzag all the way up.
        [turtle.right, turtle.left][SIZE % 2](90)
        angle = -angle

def naming():  # writes the markings of points
    turtle.penup()
    turtle.setheading(0)
    turtle.goto(-260, 150)  # 200

    for point in point_names2:
        turtle.write(point)
        turtle.forward(100)

    turtle.goto(-260, 50)  # 400

    for point in point_names4:
        turtle.write(point)
        turtle.forward(100)

    turtle.goto(-260, -50)  # 600

    for point in point_names6:
        turtle.write(point)
        turtle.forward(100)

    turtle.goto(-260, -150)  # 800

    for point in point_names8:
        turtle.write(point)
        turtle.forward(100)

    turtle.goto(-260, -250)  # 1000

    for point in point_names10:
        turtle.write(point)
        turtle.forward(100)

    turtle.goto(-280, 250)  # -260,185; 250 positions the categories vertically

    for category in category_names:  # naming of the categories
        turtle.write(category)
        turtle.forward(100)  # 9 0

def getgridposition(x, y):
    col = floor(x / LENGTH) + 3
    row = 2 - floor((y + LENGTH/2) / LENGTH)

    return (col, row)

def whiteout(x, y):
    turtle.goto(x, y)
    turtle.color("white")
    turtle.pensize(20)

    turtle.pendown()
    turtle.backward(20)
    turtle.forward(40)
    turtle.penup()

    turtle.pensize(5)

score = 0

def screenclicked(x, y):  # runs when the screen is clicked
    global score

    col, row = getgridposition(x, y)

    if not (0 <= col < len(CATEGORIES) and 0 <= row < len(CATEGORIES[0])):
        return

    whiteout(x, y)

    a = input(categories[col][row][0])
    s = categories[col][row][1]

    if a.lower() == s.lower():
        points = (row+1) * 200
        print("Correct!")
        score += points
        print("This is your total score: 
quot; + str(score))
        print("Select again.")
    else:
        points = (row+1) * 200
        print("I'm sorry, that is incorrect.")
        score -= points
        print("This is your total score: 
quot; + str(score))
        print("Select again.")

turtle = Turtle()
turtle.hideturtle()
turtle.speed('fastest')

screen = Screen()  # invoke screen clicks

gameboard()

naming()

screen.onclick(screenclicked)
screen.mainloop()
~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文