无法弄清楚如何让我的小地图工作

Can't Figure Out how to make my minimap work

我似乎无法找到一种方法让乌龟转到地图上的特定区域,当人们输入像南方这样的期望位置时,我知道当使用 setx 和 sety 线时,它会将它发送到我的坐标绘制出电线 x 起始面积 175 每平方间隔 50 | Y 起始区 380 每平方间隔 50。我没有使用 Pygame 因为我想在学校展示它

from tkinter import *
import tkinter.messagebox as tm
####################LOUIS'S STORY###################
class Theif_Story():

def Map_Starting_Area():
    import turtle
    # X axis = 1 -> 5
    # Y axis = A -> E
    ########Compass#######
    turtle.speed(99)
    turtle.pu()
    turtle.rt(90)
    turtle.fd(150)
    turtle.pd()
    turtle.fd(75)
    turtle.backward(150)
    turtle.fd(75)
    turtle.left(90)
    turtle.fd(75)
    turtle.backward(150)
    turtle.pu()
    turtle.backward(10)
    turtle.write('W')
    turtle.fd(10)
    turtle.pd()
    turtle.fd(150)
    turtle.pu()
    turtle.fd(10)
    turtle.pd()
    turtle.write('E')
    turtle.pu()
    turtle.backward(10)
    turtle.backward(75)
    turtle.rt(90)
    turtle.fd(75)
    turtle.pu()
    turtle.fd(20)
    turtle.pd()
    turtle.write('S')
    turtle.pu()
    turtle.backward(10)
    turtle.backward(170)
    turtle.pd()
    turtle.write('N')
    turtle.pu()
    turtle.backward(225)
    turtle.pd()
    ####################
    #######Grid###########
    turtle.left(90)
    turtle.ht()
    turtle.left(90)
    turtle.forward(250)
    turtle.right(90)
    turtle.forward(250)
    turtle.right(90)
    turtle.forward(250)
    turtle.right(90)
    turtle.forward(250)
    turtle.backward(50)
    turtle.right(90)
    turtle.forward(250)

    turtle.right(90)
    turtle.forward(50)
    turtle.right(90)
    turtle.forward(250)
    turtle.backward(250)

    turtle.left(90)
    turtle.forward(50)
    turtle.right(90)
    turtle.forward(250)
    turtle.backward(250)

    turtle.left(90)
    turtle.forward(50)
    turtle.right(90)
    turtle.forward(250)
    turtle.backward(250)

    turtle.left(90)
    turtle.forward(50)
    turtle.right(90)

    turtle.forward(50)
    turtle.right(90)
    turtle.forward(250)
    turtle.backward(250)
    turtle.left(90)

    turtle.forward(50)
    turtle.right(90)
    turtle.forward(250)
    turtle.backward(250)
    turtle.left(90)

    turtle.forward(50)
    turtle.right(90)
    turtle.forward(250)
    turtle.backward(250)
    turtle.left(90)

    turtle.forward(50)
    turtle.right(90)
    turtle.forward(250)
    turtle.backward(250)
    turtle.left(90)
    turtle.st()
    ############
    # Square = Town
    # Circle = Fight
    # Arrow = Quest Marker
    # Turtle = Weapon Shops
    # Triangle = Potion Shop
    # hollow circle = chest
    turtle.backward(175)
    turtle.right(90)
    turtle.pu()
    turtle.forward(75)
    turtle.shape("square")
    turtle.stamp()
    turtle.shape("classic")
    turtle.forward(150)
    turtle.left(90)
    turtle.fd(150)
    turtle.shape("square")
    turtle.stamp()
    turtle.right(90)
    turtle.shape("arrow")
    turtle.color("blue")
    turtle.stamp()
    turtle.left(90)
    turtle.color("black")
    turtle.shape("classic")
    turtle.lt(90)
    turtle.fd(100)
    turtle.shape("circle")
    turtle.stamp()
    turtle.shape("classic")
    turtle.left(90)
    turtle.forward(100)
    turtle.shape("circle")
    turtle.stamp()
    turtle.shape("classic")
    turtle.rt(90)
    turtle.fd(100)
    turtle.rt(90)
    turtle.fd(50)
    turtle.shape("circle")
    turtle.stamp()
    turtle.shape("classic")
    turtle.rt(90)
    turtle.fd(200)
    turtle.right(90)
    turtle.fd(100)
    turtle.rt(90)
    turtle.fd(10)
    turtle.pd()
    turtle.left(90)
    turtle.circle(10)
    turtle.rt(90)
    turtle.pu()
    turtle.fd(140)
    turtle.color('blue')
    turtle.rt(90)

import random
import time
import turtle

Wooden_Chest_Item_List = 'Wooden Short Blade', 'Wooden Axe', 'Wooden Stick', 'Wooden Long Blade', 'Stone Short Blade', 'Stone Axe', 'Stone Wand', 'Stone Long Blade', 'Iron Short Blade', 'Iron Axe', 'Iron Wand', 'Iron Long Blade', 'Diamond Short Blade', 'Diamond Axe', 'Diamond Wand', 'Diamond Long Blade'
Weapon_Chest = random.choice(Wooden_Chest_Item_List)

Potion_Use_Per_Battle = 3
Life = 100
Foe = random.randint(25, 150)
Player_Dmg = 25
Magic_Dmg = 10
Foe_Dmg = 15
Fists = Player_Dmg
Weapon = Fists

Wooden_Short_Blade = Player_Dmg + 3
Wooden_Stick = Magic_Dmg + 5
Wooden_Axe = Player_Dmg + 4
Wooden_Long_Blade = Player_Dmg + 5

Stone_Short_Blade = Player_Dmg + 5
Stone_Axe = Player_Dmg + 6
Stone_Wand = Magic_Dmg + 7
Stone_Long_Blade = Player_Dmg + 7

Iron_Short_Blade = Player_Dmg + 7
Iron_Axe = Player_Dmg + 8
Iron_Wand = Magic_Dmg + 9
Iron_Long_Blade = Player_Dmg + 9

Diamond_Short_Blade = Player_Dmg + 9
Diamond_Axe = Player_Dmg + 10
Diamond_Wand = Magic_Dmg + 11
Diamond_Long_Blade = Player_Dmg + 11
Bupe_Doop = Player_Dmg + Magic_Dmg + 5 ##Louis's Custom Weopon

Small_Health_Potion_Amount = random.randint(0,3)
Medium_Health_Potion_Amount = random.randint(0,3)
Large_Health_Potion_Amount = random.randint(0,3)


print('You Continue with your Journey')
print('You leave the protection of your farm and head into the open land')
print(Map_Starting_Area())
print('You Come to a cross road')
print('Would you like to go South, West or East ')
Direction = str(input())
if Direction == 'South':
    turtle.sety(330)
    turtle.update()
elif Direction == 'East':
    turtle.setx(225)
    turtle.update()
elif Direction == 'West':
    turtle.setx(125)
    turtle.update()
print('Which way do you go')
Direction2 = str(input())
if Direction2 == 'South':
    turtle.sety(330) #Stuck on this part since theirs 3 diffrent solution
    turtle.update()
elif Direction2 == 'East':
    turtle.setx(225)
    turtle.update
elif Direction2 == 'West':
    turtle.setx(125)
    turtle.update()
    print('You encounter a raverous Spider! do you wish to fight it?')
    Fight = str(input())
    if Fight == 'Yes':
        #########Battle Code Warrior############
        import random
        import time


        While_Loop = 1
        ###########Battle 1############
        print("""Spider Appers, You Need to do 10 dmg to kill this enemy!!!""")
        print('============================================')
        while While_Loop == 1:
                if Foe >= 0:
                    time.sleep(1)
                    print('You did', Player_Dmg,'Dmg')
                    Foe = Foe - Player_Dmg
                    print('Your Foe has ',Foe,'Hp left')
                    print('=============================')
                    time.sleep(0.5)
                    Player_Dmg = random.randrange(0,10)
                    if Foe <= 0:
                        print('You killed it')
                        break

                    else:
                        time.sleep(1)
                        if life >= 0:
                            life = life - Foe_Dmg
                            print('You took ', Foe_Dmg,'Dmg')
                            print('You Have', life, 'Hp left')
                            print('=============================')
                            time.sleep(0.5)
                            Foe_Dmg = random.randrange(0, 10)
                            if life <= 0:
                                print('You are dead')

                else:
                    print('You die')
                    life = 0
                    break

    elif Fight == 'No':
        print('You Sprint Frantically away from the spider while it chases you down!')
        turtle.backward(100)
elif Direction2 == 'South':
    turtle.fd(50)

我在下面提取了足够的代码来创建一个示例,让您可以在控制台上使用北、南、东和西命令在 5 x 5 的网格周围移动海龟(蓝色圆圈):

import turtle

GRID_UNIT = 50
GRID_SIZE = 5  # code below assumes this is an odd number

def Map_Starting_Area():

    turtle.pu()
    turtle.goto(-GRID_SIZE/2 * GRID_UNIT, -GRID_SIZE/2 * GRID_UNIT)
    turtle.ht()
    turtle.pd()

    ####### Grid ###########

    for _ in range(GRID_SIZE // 2):
        turtle.forward(GRID_SIZE * GRID_UNIT)
        turtle.left(90)
        turtle.forward(GRID_UNIT)
        turtle.left(90)
        turtle.forward(GRID_SIZE * GRID_UNIT)
        turtle.right(90)
        turtle.forward(GRID_UNIT)
        turtle.right(90)

    turtle.forward(GRID_SIZE * GRID_UNIT)
    turtle.left(90)
    turtle.forward(GRID_UNIT)
    turtle.left(90)
    turtle.forward(GRID_SIZE * GRID_UNIT)
    turtle.left(90)

    for _ in range(GRID_SIZE // 2):
        turtle.forward(GRID_SIZE * GRID_UNIT)
        turtle.left(90)
        turtle.forward(GRID_UNIT)
        turtle.left(90)
        turtle.forward(GRID_SIZE * GRID_UNIT)
        turtle.right(90)
        turtle.forward(GRID_UNIT)
        turtle.right(90)

    turtle.forward(GRID_SIZE * GRID_UNIT)
    turtle.left(90)
    turtle.forward(GRID_UNIT)
    turtle.left(90)
    turtle.forward(GRID_SIZE * GRID_UNIT)
    turtle.pu()
    turtle.home()

    turtle.st()

turtle.speed('fastest')

Map_Starting_Area()

turtle.color('blue')
turtle.shape('circle')

print('You Continue with your Journey')
print('You leave the protection of your farm and head into the open land')
print('You Come to a cross road')

while True:
    direction = input('Would you like to go North, South, East or West: ').lower()

    if direction == 'north' and turtle.ycor() < GRID_UNIT * (GRID_SIZE//2 - 0.5):
        turtle.sety(turtle.ycor() + GRID_UNIT)
    elif direction == 'south' and turtle.ycor() > -GRID_UNIT * (GRID_SIZE//2 - 0.5):
        turtle.sety(turtle.ycor() - GRID_UNIT)
    elif direction == 'east' and turtle.xcor() < GRID_UNIT * (GRID_SIZE//2 - 0.5):
        turtle.setx(turtle.xcor() + GRID_UNIT)
    elif direction == 'west' and turtle.xcor() > -GRID_UNIT * (GRID_SIZE//2 - 0.5):
        turtle.setx(turtle.xcor() - GRID_UNIT)

    elif direction == 'quit':
        break

该代码阻止您的乌龟离开网格。我将网格以 (0, 0) 为中心以简化逻辑。希望你能把它结合到你的程序中来控制海龟的运动。

通常情况下,我会避免在 turtle 程序中使用 while True:,这确实应该是基于事件的,但目前看来这是最简单的解决方案。