2017-08-28 37 views
1

我似乎無法找到一種方法,使人們在地圖上的特定區域,當人們輸入像南方的慾望位置我知道,當使用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) 

回答

1

到目前它我提取剛好夠下面的代碼來創建,讓您移動龜(藍圈)周圍5×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)處來簡化邏輯。希望你可以把它加入你的程序來控制龜的運動。

通常,我會避免在一個海龜程序中的while True:,這實際上應該是基於事件的,但現在看起來似乎是最簡單的解決方案。

+0

謝謝!這應該有所幫助 –

相關問題