2017-08-28 3 views
1

Ich kann nicht scheinen, einen Weg zu finden, die Schildkröte zu bestimmten Bereichen auf der Karte zu bekommen, wenn Leute in den Wunschort wie Süden eingeben, weiß ich, dass, wenn die setx und sety Linien verwenden dass es wird es an die coords senden ich kartiert die schnüre x startbereich 175 jeder sqaure ist 50 auseinander | Y Startbereich 380 jeder Platz ist 50 auseinander. Ich verwende Pygame nicht, da ich es in der Schule präsentieren wollenKann nicht herausfinden, wie meine Minikarte funktioniert

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) 

Antwort

1

ich unten gerade genug Code extrahiert haben, ein Beispiel zu erstellen, die Sie die Schildkröte (blauer Kreis) bewegen lässt um einen 5 x 5 Raster mit den Befehlen Nord, Süd, Ost & Westen an der Konsole:

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 

der Code verhindert, dass Ihre Schildkröte aus dem Netz zu verlassen. Ich habe das Gitter auf (0, 0) zentriert, um die Logik zu vereinfachen. Hoffentlich können Sie dies in Ihr Programm integrieren, um die Bewegung der Schildkröte zu kontrollieren.

Normalerweise würde ich ein while True: in einem Turtle-Programm vermeiden, das wirklich ereignisbasiert sein sollte, aber für jetzt scheint es die einfachste Lösung.

+0

Danke! Dies sollte helfen –

Verwandte Themen