Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- import turtle
- import pdb
- import random
- import time
- def wave():
- turtle.tracer(0)
- turtle.register_shape("bye1.gif")
- turtle.register_shape("bye2.gif")
- wave=turtle.Turtle()
- wave.penup()
- wave.setposition(0,-200)
- while True:
- turtle.tracer(1)
- wave.shape("bye1.gif")
- time.sleep(0.5)
- wave.shape("bye2.gif")
- time.sleep(0.5)
- def set(z,q):
- turtle.clearscreen()
- global wn
- global pics
- global he; global bo; global le; global bt; global h1; global h2; global sw
- global helmbonus; global platebonus; global legsbonus; global bootsbonus; global gauntletsbonus; global swordbonus
- global items1; global itmes2; global items3; global items4; global allitems; global itemslist;
- global health; global l; global h; global inventory; global direction; global imagelist
- wn = turtle.Screen()
- wn.bgcolor("black")
- wn.title("Maze RPG")
- wn.setup(1000, 1000)
- wn.tracer(0)
- turtle.tracer(0)
- pics=["closed_chest.gif","opened_chest.gif","cloud.gif","take.gif","front.gif","left.gif","back.gif","right.gif","walls.gif",
- "left attack.gif","right attack.gif","front attack.gif","back attack.gif",
- "nhead.gif","nbody.gif","nlegs.gif","nboots.gif","nhand1.gif","nhand2.gif","nsword.gif",
- "monster1.gif","monster2.gif","monster3.gif","monster4.gif",
- "boss1.gif", "boss2.gif","boss3.gif","boss4.gif",
- "ghead.gif", "uhead.gif", "vhead.gif","shead.gif",
- "ghelm.gif", "uhelm.gif", "vhelm.gif","shelm.gif",
- "gbody.gif", "ubody.gif", "vbody.gif","sbody.gif",
- "gplate.gif", "uplate.gif","vplate.gif","splate.gif",
- "glegs.gif","ulegs.gif","vlegs.gif","slegs.gif",
- "gleg.gif", "uleg.gif","vleg.gif","sleg.gif",
- "gboots.gif","sboots.gif","vboots.gif","uboots.gif",
- "gboot.gif","sboot.gif","vboot.gif","uboot.gif",
- "ghand1.gif", "ghand2.gif","shand1.gif","shand2.gif","vhand1.gif","vhand2.gif","uhand1.gif","uhand2.gif",
- "ggauntlets.gif","sgauntlets.gif","vgauntlets.gif","ugauntlets.gif",
- "gsword.gif","usword.gif","vsword.gif","ssword.gif",
- "gswords.gif","uswords.gif","vswords.gif","sswords.gif"]
- #portrait
- he="nhead.gif"
- bo="nbody.gif"
- le="nlegs.gif"
- bt="nboots.gif"
- h1="nhand1.gif"
- h2="nhand2.gif"
- sw="nsword.gif"
- #bonuses
- helmbonus= 0
- platebonus = 0
- legsbonus = 0
- bootsbonus = 0
- gauntletsbonus = 0
- swordbonus = 0
- #items
- items1=["Steel Helm","Steel Sword","Steel Plate","Steel Legs","Steel Boots","Steel Gauntlets",
- "nothing","nothing","nothing","nothing"]
- items2=["Gold Helm","Gold Sword","Gold Plate","Gold Legs","Gold Boots","Gold Gauntlets",
- "nothing","nothing","nothing","nothing"]
- items3=["Vibranium Helm","Vibranium Sword","Vibranium Plate","Vibranium Legs","Vibranium Boots","Vibranium Gauntlets",
- "nothing","nothing","nothing","nothing"]
- items4=["Unobtainium Helm","Unobtainium Sword","Unobtainium Plate",
- "Unobtainium Legs","Unobtainium Boots","Unobtainium Gauntlets",
- "nothing","nothing","nothing","nothing"]
- allitems=["",items1,items2,items3,items4]
- itemslist=["Steel Helm","Steel Sword","Steel Plate","Steel Legs","Steel Boots","Steel Gauntlets",
- "Gold Helm","Gold Sword","Gold Plate","Gold Legs","Gold Boots","Gold Gauntlets",
- "Vibranium Helm","Vibranium Sword","Vibranium Plate","Vibranium Legs","Vibranium Boots","Vibranium Gauntlets",
- "Unobtainium Helm", "Unobtainium Sword", "Unobtainium Plate",
- "Unobtainium Legs", "Unobtainium Boots", "Unobtainium Gauntlets"
- ]
- imagelist=["shelm.gif", "sswords.gif", "splate.gif", "sleg.gif", "sboot.gif", "sgauntlets.gif",
- "ghelm.gif", "gswords.gif", "gplate.gif", "gleg.gif", "gboot.gif", "ggauntlets.gif",
- "vhelm.gif", "vswords.gif", "vplate.gif", "vleg.gif", "vboot.gif", "vgauntlets.gif",
- "uhelm.gif", "uswords.gif", "uplate.gif", "uleg.gif", "uboot.gif", "ugauntlets.gif"]
- l=1
- h=0
- health=100
- inventory = []
- direction="up"
- welcome=turtle.Turtle()
- welcome.hideturtle()
- welcome.color("white")
- welcome.penup()
- welcome.setposition(0,250)
- welcome.write("Welcome to the Dungeon!",False, align="center", font=("Arial", 50, "normal"))
- welcome.setposition(0,150)
- welcome.write("press arrows keys to move and A to attack", False, align="center", font=("Arial", 14, "normal"))
- welcome.setposition(0,130)
- welcome.write("click anywhere to start", False, align="center", font=("Arial", 14, "normal"))
- welcome.setposition(0, 70)
- welcome.write("Enjoy your stay!", False, align="center", font=("Arial", 30, "normal"))
- turtle.onscreenclick(start)
- while True:
- wn.update()
- def start(o,O):
- turtle.clearscreen()
- global wn
- global pics
- global he;
- global bo;
- global le;
- global bt;
- global h1;
- global h2;
- global sw
- global helmbonus;
- global platebonus;
- global legsbonus;
- global bootsbonus;
- global gauntletsbonus;
- global swordbonus
- global items1;
- global itmes2;
- global items3;
- global items4;
- global allitems;
- global itemslist;
- global health;
- global l;
- global h;
- global inventory;
- global direction
- wn.bgcolor("black")
- wn.tracer(0)
- for image in pics:
- turtle.register_shape(image)
- class Pen(turtle.Turtle):
- def __init__(self):
- turtle.Turtle.__init__(self)
- self.shape("circle")
- self.turtlesize(3)
- self.penup()
- self.speed(0)
- class Text(turtle.Turtle):
- def __init__(self):
- turtle.Turtle.__init__(self)
- self.color("white")
- self.penup()
- self.hideturtle()
- class Monster(turtle.Turtle):
- def __init__(self, x, y):
- turtle.Turtle.__init__(self)
- self.penup()
- self.setposition(x, y)
- if l == 1:
- self.shape("monster1.gif")
- self.penup()
- self.hp = 50
- self.attack = 10
- elif l == 2:
- self.shape("monster2.gif")
- self.penup()
- self.hp = 100
- self.attack = 20
- elif l == 3:
- self.shape("monster3.gif")
- self.penup()
- self.hp = 150
- self.attack = 30
- elif l == 4:
- self.shape("monster4.gif")
- self.penup()
- self.hp = 200
- self.attack = 35
- class Boss(turtle.Turtle):
- def __init__(self, x, y):
- turtle.Turtle.__init__(self)
- self.penup()
- self.setposition(x, y)
- if l == 1:
- self.shape("boss1.gif")
- self.penup()
- self.hp = 100
- self.attack = 20
- elif l == 2:
- self.shape("boss2.gif")
- self.penup()
- self.hp = 150
- self.attack = 30
- elif l == 3:
- self.shape("boss3.gif")
- self.penup()
- self.hp = 200
- self.attack = 35
- elif l == 4:
- self.shape("boss4.gif")
- self.penup()
- self.hp = 250
- self.attack = 40
- class Player(turtle.Turtle):
- def __init__(self):
- global health
- turtle.Turtle.__init__(self)
- self.shape("front.gif")
- self.penup()
- self.speed(0)
- self.Abonus = 10 + swordbonus
- self.Dbonus = helmbonus + platebonus + legsbonus + bootsbonus + gauntletsbonus
- self.hp = health
- def go_up(self):
- global h
- self.shape("back.gif")
- if (self.xcor(), self.ycor() + 21) in monsterl or (self.xcor(), self.ycor() + 21) in bossl:
- self.hp -= 1
- self.isalive()
- if (self.xcor(), self.ycor() - 21) in walls:
- self.goto((self.xcor(), self.ycor()))
- else:
- self.goto((self.xcor(), self.ycor() - 21))
- elif (self.xcor(), self.ycor() + 21) not in walls and (self.xcor(), self.ycor() + 21) not in chestl and (self.xcor(), self.ycor() + 21) not in bossl:
- self.goto(self.xcor(), self.ycor() + 21)
- elif (self.xcor(), self.ycor() + 21) in chestl:
- checking(self.xcor(), self.ycor() + 21)
- global direction
- direction = "up"
- reveal()
- h=0
- def go_down(self):
- self.shape("front.gif")
- if (self.xcor(), self.ycor() - 21) in monsterl:
- self.hp -= 1
- self.isalive()
- if (self.xcor(), self.ycor() + 21)in walls:
- self.goto((self.xcor(), self.ycor()))
- else:
- self.goto((self.xcor(), self.ycor() + 21))
- elif (self.xcor(), self.ycor() - 21) not in walls and (self.xcor(), self.ycor() - 21) not in chestl:
- self.goto(self.xcor(), self.ycor() - 21)
- elif (self.xcor(), self.ycor() - 21) in chestl:
- checking(self.xcor(), self.ycor() - 21)
- global direction
- direction = "down"
- reveal()
- def go_left(self):
- global h
- self.shape("left.gif")
- if (self.xcor() - 21, self.ycor()) in monsterl:
- self.hp -= 1
- self.isalive()
- if (self.xcor() + 21, self.ycor()) in walls:
- self.goto((self.xcor(), self.ycor()))
- else:
- self.goto((self.xcor() + 21, self.ycor()))
- elif (self.xcor() - 21, self.ycor()) not in walls and (self.xcor() - 21, self.ycor()) not in chestl:
- self.goto(self.xcor() - 21, self.ycor())
- elif (self.xcor() - 21, self.ycor()) in chestl:
- checking(self.xcor() - 21, self.ycor())
- global direction
- direction = "left"
- reveal()
- h = 0
- def go_right(self):
- self.shape("right.gif")
- if (self.xcor() + 21, self.ycor()) in monsterl:
- self.hp -= 1
- self.isalive()
- if (self.xcor() - 21, self.ycor()) in walls:
- self.goto((self.xcor(), self.ycor()))
- else:
- self.goto((self.xcor() - 21, self.ycor()))
- elif (self.xcor() + 21, self.ycor()) not in walls and (self.xcor() + 21, self.ycor()) not in chestl:
- self.goto(self.xcor() + 21, self.ycor())
- elif (self.xcor() + 21, self.ycor()) in chestl:
- checking(self.xcor() + 21, self.ycor())
- global direction
- direction = "right"
- reveal()
- def isalive(self):
- global health
- hptext.undo()
- hp = "HP: " + str(player.hp)
- hptext.setposition(-420, -390)
- hptext.write(hp, False, align="left", font=("Arial", 14, "normal"))
- health = player.hp
- if self.hp < 1:
- turtle.clearscreen()
- wn.bgcolor("Black")
- died=turtle.Turtle()
- died.hideturtle()
- died.color("red")
- died.penup()
- died.write("You Died", False, align="center", font=("Times", 100, "normal"))
- died.setposition(0,-100)
- died.color("white")
- died.write("Click anywhere to try again", False, align="center", font=("Times", 10, "normal"))
- turtle.onscreenclick(set)
- class Chest(turtle.Turtle):
- def __init__(self, x, y):
- turtle.Turtle.__init__(self)
- self.shape("closed_chest.gif")
- self.penup()
- self.speed(0)
- self.goto(x, y)
- def open(self,x,y):
- self.shape("opened_chest.gif")
- if not allitems[l]:
- chesttext.setposition(x, y+8)
- chesttext.write("This chest is empty!", False, align="center", font=("Arial", 10, "normal"))
- turtle.ontimer(un, 1000)
- else:
- item = random.choice(allitems[l])
- if item == "nothing":
- allitems[l].remove(item)
- chesttext.setposition(x,y+8)
- chesttext.write("This chest is empty!", False, align="center", font=("Arial", 10, "normal"))
- turtle.ontimer(un,1000)
- elif item not in inventory:
- inventory.append(item)
- chesttext.setposition(x,y+8)
- chesttext.write(item+"!", False, align="center", font=("Arial", 10, "normal"))
- allitems[l].remove(item)
- display()
- turtle.ontimer(un,1000)
- #instance of classes
- pen=Pen()
- player=Player()
- damagetext = Text()
- hptext = Text()
- atext = Text()
- dtext = Text()
- healtext= Text()
- chesttext= Text()
- gh = Pen()
- gs = Pen()
- gp = Pen()
- gl = Pen()
- gb = Pen()
- gg = Pen()
- sh = Pen()
- ss = Pen()
- sp = Pen()
- sl = Pen()
- sb = Pen()
- sg = Pen()
- vh = Pen()
- vs = Pen()
- vp = Pen()
- vl = Pen()
- vb = Pen()
- vg = Pen()
- uh = Pen()
- us = Pen()
- up = Pen()
- ul = Pen()
- ub = Pen()
- ug = Pen()
- head = turtle.Turtle()
- body = turtle.Turtle()
- legs = turtle.Turtle()
- boots = turtle.Turtle()
- hand1 = turtle.Turtle()
- hand2 = turtle.Turtle()
- sword = turtle.Turtle()
- off = turtle.Turtle()
- pool = turtle.Turtle()
- pool.penup()
- head.penup()
- body.penup()
- legs.penup()
- boots.penup()
- hand1.penup()
- hand2.penup()
- sword.penup()
- off.penup()
- # drawing interface
- head.setposition(-300, -100)
- body.setposition(-296, -191)
- legs.setposition(-310, -261)
- boots.setposition(-316, -303)
- hand1.setposition(-400, -251)
- hand2.setposition(-159, -205)
- sword.setposition(-159,-270)
- sh.setposition(-50, -80)
- ss.setposition(50, -80)
- sp.setposition(150, -80)
- sl.setposition(250, -80)
- sb.setposition(350, -80)
- sg.setposition(450, -80)
- gh.setposition(-50, -180)
- gs.setposition(50, -180)
- gp.setposition(150, -180)
- gl.setposition(250, -180)
- gb.setposition(350, -180)
- gg.setposition(450, -180)
- vh.setposition(-50, -280)
- vs.setposition(50, -280)
- vp.setposition(150, -280)
- vl.setposition(250, -280)
- vb.setposition(350, -280)
- vg.setposition(450, -280)
- uh.setposition(-50, -380)
- us.setposition(50, -380)
- up.setposition(150, -380)
- ul.setposition(250, -380)
- ub.setposition(350, -380)
- ug.setposition(450, -380)
- off.setposition(-316,-350)
- hptext.setposition(-420, -390)
- hptext.write("HP: " + str(player.hp), False, align="left", font=("Arial", 14, "normal"))
- atext.setposition(-300,-390)
- atext.write("Attack Bonus: "+str(player.Abonus), False, align="left", font=("Arial", 14, "normal"))
- dtext.setposition(-300, -420)
- dtext.write("Defence Bonus: "+str(player.Dbonus), False, align="left", font=("Arial", 14, "normal"))
- head.shape(he)
- body.shape(bo)
- legs.shape(le)
- boots.shape(bt)
- hand1.shape(h1)
- hand2.shape(h2)
- sword.shape(sw)
- off.shape("take.gif")
- #chests and monsters and walls list
- chests = []
- chestl = []
- monsters = []
- monsterl = []
- been = []
- walls = []
- bosses=[]
- bossl=[]
- #maze levels
- levels = ["0", "1", "2", "3", "4","5"]
- levels[1] = [
- "xxxxxxxxxxxxxxxxxxxxxxxbxxxxxxxxxxxxxxxxxxxxxxx",
- "xcx x x cx x",
- "xmx xxxxxxxxxxxxxxxxxxxxx xxxxxxx x xxx xxx x x",
- "x x x m x x m x xcx x x x xc x x",
- "x x x x x x x x xmxxxxxxx x x xxxxxxx x x",
- "x x xxxxxxxx xxxxxxxx x xx x x x x x x",
- "x x x x x x xx x xxxxxx xxxx x",
- "x xxxxxxxx xxxx xxxxxxx xx x x x x x",
- "x m x x x xxxxxxxxxxxx x x",
- "xxxxxxxxxxxxxxxxxxxx xx xxxx x x x x x",
- "x x cx x m x xxxxxxxxx x",
- "x xxxxxxxxxx x xxxxx xxxxxxxxxxxxxx x x",
- "x x x x xc x xxx xxxxx",
- "x xxxxxxxx xxxxxxxxxxx x x x xxxxxxxxxx x x",
- "xcxc x x x x x xxx x x",
- "xxxxxxxx xxxxxxxx xx x x xxxxxxxxx xxxx xcx x x",
- "x x x x x x x",
- "xxxxxxxxxxxxxxx xxxxxxxxxxxxxxxxxxxx xxxx xxx x",
- "x x x x x x x",
- "x xxxxxxxxxxx x x xxxxxxxxxxxxxxxxxx x xxxx xxx",
- "x m x x x x x",
- "xxxxxxxxxxx xxx xxxxxxxxxxxxxxxxx xxxxxxxxxxx x",
- "xc x",
- "xxxxxxxxxxxxxxxxxxxxxxkpxxxxxxxxxxxxxxxxxxxxxxx",
- " xxxx ",
- ]
- levels[2] = [
- "xxxxxxxxxxxxxxxxxxxxxxxbxxxxxxxxxxxxxxxxxxxxxxx",
- "x xc xcx",
- "x x xxxxxxxxxxxxxxxxx xxxxxxxxxxxxxxxxxxxxxxx x",
- "x x x xc x x xcx m x x x",
- "x x xxxxxxxxxxxxx x x xx x x xxxxxxxxx x x",
- "x x x mx x x xx xxxxxxxx x x",
- "x x xxxxxxxxxxxxxxx x x xxxxxxxxx x",
- "x x x x xxxxxxxxxxxxx x",
- "x xxxxx xxxx xxxxxxxxxx x x x xxxxxxx",
- "x x x xxxxxxxxx xxx x mx",
- "x xxx xxxxxxxxxxxxxxxxxxx x x x xxxxx",
- "x xcx x x m x x xxxxx xxxxxxx x x",
- "x x xxxxxxxxxx x x x x x x x x x",
- "x x x mxxxxxxxxxxx x x x xxxxx xxxxx x x",
- "x x xxxxxxxx x xmx cx x x",
- "x x xxxx xxxxxxxxxxxxx xxx xxxxxxxxxxx x",
- "x xxxxxxxxcx x x",
- "xxxxxxxxxx x x x x xxxxx x xxxxxxxxxxxxxxxxx",
- "xcm x x m x x x x x x x",
- "xxxx x xxx xxxxxx x x x x x xxxxxxxxxxxxxxxxx x",
- "x x x x x x x mcx x",
- "x xxxx x xxxxxxxxxx xcx xxxxxxxxxxxxxxxxxxxxx x",
- "x x x x x",
- "xxxxxxxxxxxxxxxxxxxxxxkpxxxxxxxxxxxxxxxxxxxxxxx",
- " xx x ",
- ]
- levels[3] = [
- "xxxxxxxxxxxxxxxxxxxxxxxbxxxxxxxxxxxxxxxxxxxxxxx",
- "xc x x x cx xcxmxcx x",
- "xxx xxxxx x x x xx xxxxxxx xxxxxx x x x x x x x",
- "x xc x x x x x m x x x x x x x x",
- "x xxxxx x xx xxxx xxx xx xxxxxx x x xxxxx x",
- "x x x x xxxxxmx x x x x x x x x",
- "x x x x x xxxxx xxx xxxxxx xxxxxx xxx x x",
- "x x xxx x x x x x m x xxx x",
- "xxxxx x x xxx xxx xxxxxxxxxxxxxxxxxxx x x",
- "xm xxxxxxx x x x x x x x x",
- "x x x x xxx xxxxxxxxx x xxxx xxxxxxxx x",
- "xxxxxx xxxxxx x x x x x x",
- "xc x x x xxxxxxx xxxxxxxxxx x x xxxxxxxx",
- "xxxxxxxxx mx x x x x",
- "x xxxxx xxxxxxxxxxxxxxxxxxxxxx xxxxxxxx x",
- "x xxxxx x x x x x",
- "x x x x x x x x xxxxxxxxxxxxxxxxxxxxxxx",
- "xxxxx x x xxxxxxxxxxx x cxm x x",
- "xc x x x cx x xxx xxxxxxxx x x x x",
- "xxx xxxxx xxxxxxxxx x x x x xc xxxxxx xxxx",
- "x x x x xmx x x xxx x",
- "x xxxxxxxxxxxxxxxxxxx x x x xxx xxxxxxxxxxx x",
- "x x x x x",
- "xxxxxxxxxxxxxxxxxxxxxxkpxxxxxxxxxxxxxxxxxxxxxxx",
- " xx x ",
- ]
- levels[4] = [
- "xxxxxxxxxxxxxxxxxxxxxxxbxxxxxxxxxxxxxxxxxxxxxxx",
- "x mx x",
- "x xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx x",
- "x x x x x x",
- "xxxx xxxx xxxxxxx x xxx xxx x xxxxxxx xxxx xxxx",
- "x x x x x x x x x x x x",
- "x m xxxx xxxxxxxxx x x xxxxxxxxx xxxx m x",
- "xxxxxxxx cx x x xc xxxxxxxx",
- "x xxxxxxx xxxx x x xxxx xxxxxxx x",
- "x xxxxx x x x x x x x x xxxxx x",
- "x xxxxxxxx xxxx x x x x xxxx xxxxxxxx x",
- "x xxx cx x xcx xcx x xc xxx x",
- "x x xx xxx xxxxx xxxxxx xxxxxx xxxxx xxx xx x x",
- "xcx xm x x mx xcx",
- "xxx xxxxxxxxxxxxxx xxxx xxxx xxxxxxxxxxxxxx xxx",
- "x xm x x mx x",
- "xxxxxxxx xxxxxxxxxxxx x x xxxxxxxxxxxx xxxxxxxx",
- "x x xm x x x x mx x x",
- "x x xxxxx x x xxxxxx xxxxxx x x xxxxx x x",
- "x x cxxxxxx x x x x x x xxxxxxc x x",
- "x xxxxxxx x x x x x x xxxxxxx x",
- "x x x xxxxxxxxxxx x x xxxxxxxxxxx x x x",
- "xm x x x x x x mx",
- "xxxxxxxxxxxxxxxxxxxxxxkpxxxxxxxxxxxxxxxxxxxxxxx",
- " xx x ",
- ]
- #set up the maze
- def update_bonus():
- player.Abonus = 10 + swordbonus
- player.Dbonus = helmbonus + platebonus + legsbonus + bootsbonus + gauntletsbonus
- def setup_maze(level):
- for y in range(len(level)):
- for x in range(len(level[y])):
- character = level[y][x]
- screen_x = -485 + (x * 21)
- screen_y = 480 - (y * 21)
- if direction=="up":
- if character == "p":
- player.setposition(screen_x, screen_y)
- elif character == "b":
- bosses.append(Boss(screen_x, screen_y))
- bossl.append((screen_x, screen_y))
- elif direction=="down":
- if character == "b":
- player.setposition(screen_x, screen_y)
- if character == "x":
- walls.append((screen_x, screen_y))
- elif character == "c":
- chestl.append((screen_x, screen_y))
- elif character == "m":
- monsterl.append((screen_x, screen_y))
- elif character=="k":
- pool.shape("cloud.gif")
- pool.setposition(screen_x, screen_y)
- def reveal():
- around=[(player.xcor()-21,player.ycor()+21),(player.xcor(),player.ycor()+21),(player.xcor()+21,player.ycor()+21),
- (player.xcor()-21,player.ycor()), (player.xcor()+21,player.ycor()),
- (player.xcor()-21,player.ycor()-21),(player.xcor(),player.ycor()-21),(player.xcor()+21,player.ycor()-21)]
- if (player.xcor(),player.ycor()) in been:
- pass
- else:
- been.append((player.xcor(),player.ycor()))
- for i in around:
- if i in walls:
- a=walls.index(i)
- pen.penup()
- pen.goto(walls[a])
- pen.shape("walls.gif")
- pen.stamp()
- elif i in monsterl:
- w=monsterl.index(i)
- w=str(monsterl[w])
- w=w.replace("(",",")
- w=w.replace(")",",")
- w=w.split(",")
- a=int(w[1])
- b=int(w[2])
- monsters.append(Monster(a,b))
- elif i in chestl:
- v = chestl.index(i)
- v = str(chestl[v])
- v = v.replace("(", ",")
- v = v.replace(")", ",")
- v = v.split(",")
- c=int(v[1])
- d=int(v[2])
- chests.append(Chest(c,d))
- def attack():
- if direction == "left":
- player.shape("left attack.gif")
- turtle.ontimer(back, 200)
- player.penup()
- elif direction == "right":
- player.shape("right attack.gif")
- turtle.ontimer(back, 200)
- player.penup()
- elif direction == "up":
- player.shape("back attack.gif")
- turtle.ontimer(back, 200)
- player.penup()
- elif direction == "down":
- player.shape("front attack.gif")
- turtle.ontimer(back, 200)
- player.penup()
- for monster in monsters:
- if direction == "left" and (player.xcor() - 21, player.ycor()) == (monster.xcor(), monster.ycor()):
- turtle.tracer(1)
- player.goto(player.xcor() - 10, player.ycor())
- damagetext.setposition((monster.xcor(), monster.ycor()))
- damagetext.write("-" + str(player.Abonus))
- monster.hp = monster.hp - player.Abonus
- time.sleep(0.2)
- player.goto(player.xcor() + 10, player.ycor())
- damagetext.undo()
- if monster.hp < 1:
- turtle.tracer(0)
- monsters.remove(monster)
- monsterl.remove((monster.xcor(), monster.ycor()))
- monster.setposition(1000, 1000)
- else:
- time.sleep(0.2)
- monster.goto(monster.xcor() + 10, monster.ycor())
- damagetext.setposition((player.xcor(), player.ycor()))
- damagetext.write("-" + str(max(monster.attack - player.Dbonus, 1)))
- time.sleep(0.2)
- monster.goto(monster.xcor() - 10, monster.ycor())
- damagetext.undo()
- turtle.tracer(0)
- player.hp = player.hp - max(monster.attack - player.Dbonus, 1)
- player.isalive()
- elif direction == "right" and (player.xcor() + 21, player.ycor()) == (monster.xcor(), monster.ycor()):
- turtle.tracer(1)
- player.goto(player.xcor() + 10, player.ycor())
- damagetext.setposition((monster.xcor(), monster.ycor()))
- damagetext.write("-" + str(player.Abonus))
- monster.hp = monster.hp - player.Abonus
- time.sleep(0.2)
- player.goto(player.xcor() - 10, player.ycor())
- damagetext.undo()
- if monster.hp < 1:
- turtle.tracer(0)
- monsters.remove(monster)
- monsterl.remove((monster.xcor(), monster.ycor()))
- monster.setposition(1000, 1000)
- time.sleep(0.2)
- else:
- monster.goto(monster.xcor() - 10, monster.ycor())
- damagetext.setposition((player.xcor(), player.ycor()))
- damagetext.write("-" + str(max(monster.attack - player.Dbonus, 1)))
- time.sleep(0.2)
- monster.goto(monster.xcor() + 10, monster.ycor())
- damagetext.undo()
- turtle.tracer(0)
- player.hp = player.hp - max(monster.attack - player.Dbonus, 1)
- player.isalive()
- elif direction == "up" and (player.xcor(), player.ycor() + 21) == (monster.xcor(), monster.ycor()):
- turtle.tracer(1)
- player.goto(player.xcor(), player.ycor() + 10)
- damagetext.setposition((monster.xcor(), monster.ycor()))
- damagetext.write("-" + str(player.Abonus))
- monster.hp = monster.hp - player.Abonus
- time.sleep(0.2)
- player.goto(player.xcor(), player.ycor() - 10)
- damagetext.undo()
- if monster.hp < 1:
- turtle.tracer(0)
- monsters.remove(monster)
- monsterl.remove((monster.xcor(), monster.ycor()))
- monster.setposition(1000, 1000)
- else:
- time.sleep(0.2)
- monster.goto(monster.xcor(), monster.ycor() - 10)
- damagetext.setposition((player.xcor(), player.ycor()))
- damagetext.write("-" + str(max(monster.attack - player.Dbonus, 1)))
- time.sleep(0.2)
- monster.goto(monster.xcor(), monster.ycor() + 10)
- damagetext.undo()
- turtle.tracer(0)
- player.hp = player.hp - max(monster.attack - player.Dbonus, 1)
- player.isalive()
- elif direction == "down" and (player.xcor(), player.ycor() - 21) == (monster.xcor(), monster.ycor()):
- turtle.tracer(1)
- player.goto(player.xcor(), player.ycor() - 10)
- damagetext.setposition((monster.xcor(), monster.ycor()))
- damagetext.write("-" + str(player.Abonus))
- monster.hp = monster.hp - player.Abonus
- time.sleep(0.2)
- player.goto(player.xcor(), player.ycor() + 10)
- damagetext.undo()
- if monster.hp < 1:
- turtle.tracer(0)
- monsters.remove(monster)
- monsterl.remove((monster.xcor(), monster.ycor()))
- monster.setposition(1000, 1000)
- else:
- time.sleep(0.2)
- monster.goto(monster.xcor(), monster.ycor() + 10)
- damagetext.setposition((player.xcor(), player.ycor()))
- damagetext.write("-" + str(max(monster.attack - player.Dbonus, 1)))
- time.sleep(0.2)
- monster.goto(monster.xcor(), monster.ycor() - 10)
- damagetext.undo()
- turtle.tracer(0)
- player.hp = player.hp - max(monster.attack - player.Dbonus, 1)
- player.isalive()
- for boss in bosses:
- if direction == "up" and (player.xcor(), player.ycor() + 21) == (boss.xcor(), boss.ycor()):
- turtle.tracer(1)
- player.goto(player.xcor(), player.ycor() + 10)
- damagetext.setposition((boss.xcor(), boss.ycor()))
- damagetext.write("-" + str(player.Abonus))
- boss.hp = boss.hp - player.Abonus
- time.sleep(0.2)
- player.goto(player.xcor(), player.ycor() - 10)
- damagetext.undo()
- if boss.hp < 1:
- turtle.tracer(0)
- bosses.remove(boss)
- bossl.remove((boss.xcor(), boss.ycor()))
- boss.setposition(1000, 1000)
- else:
- time.sleep(0.2)
- boss.goto(boss.xcor(), boss.ycor() - 10)
- damagetext.setposition((player.xcor(), player.ycor()))
- damagetext.write("-" + str(max(boss.attack - player.Dbonus, 1)))
- time.sleep(0.2)
- boss.goto(boss.xcor(), boss.ycor() + 10)
- damagetext.undo()
- turtle.tracer(0)
- player.hp = player.hp - max(boss.attack - player.Dbonus, 1)
- player.isalive()
- def back():
- if direction == "left":
- player.shape("left.gif")
- player.penup()
- elif direction == "right":
- player.shape("right.gif")
- player.penup()
- elif direction == "up":
- player.shape("back.gif")
- player.penup()
- elif direction == "down":
- player.shape("front.gif")
- player.penup()
- def checking(x,y):
- for chest in chests:
- if chest.xcor()==x and chest.ycor()==y:
- chest.open(x,y)
- chests.remove(chest)
- def display():
- def shelm(x, y):
- global he
- if "Steel Helm" in inventory:
- global helmbonus
- helmbonus = 1
- update_bonus()
- head.shape("shead.gif")
- he = "shead.gif"
- dtext.undo()
- dtext.write("Defence Bonus: " + str(player.Dbonus), False, align="left", font=("Arial", 14, "normal"))
- def ssword(x, y):
- global sw
- if "Steel Sword" in inventory:
- global swordbonus
- swordbonus = 10
- update_bonus()
- sword.shape("ssword.gif")
- sw="ssword.gif"
- atext.undo()
- atext.write("Attack Bonus: " + str(player.Abonus), False, align="left", font=("Arial", 14, "normal"))
- def splate(x, y):
- global bo
- if "Steel Plate" in inventory:
- global platebonus
- platebonus = 1
- update_bonus()
- body.shape("sbody.gif")
- bo="sbody.gif"
- dtext.undo()
- dtext.write("Defence Bonus: " + str(player.Dbonus), False, align="left", font=("Arial", 14, "normal"))
- def slegs(x, y):
- global le
- if "Steel Legs" in inventory:
- global legsbonus
- legsbonus = 1
- update_bonus()
- legs.shape("slegs.gif")
- le="slegs.gif"
- dtext.undo()
- dtext.write("Defence Bonus: " + str(player.Dbonus), False, align="left", font=("Arial", 14, "normal"))
- def sboots(x, y):
- global bt
- if "Steel Boots" in inventory:
- global bootsbonus
- bootsbonus = 1
- update_bonus()
- boots.shape("sboots.gif")
- bt="sboots.gif"
- dtext.undo()
- dtext.write("Defence Bonus: " + str(player.Dbonus), False, align="left", font=("Arial", 14, "normal"))
- def sgauntlets(x, y):
- global h1
- global h2
- if "Steel Gauntlets" in inventory:
- global gauntletsbonus
- gauntletsbonus = 1
- update_bonus()
- hand1.shape("shand1.gif")
- hand2.shape("shand2.gif")
- h1="shand1.gif"
- h2="shand2.gif"
- dtext.undo()
- dtext.write("Defence Bonus: " + str(player.Dbonus), False, align="left", font=("Arial", 14, "normal"))
- def ghelm(x, y):
- global he
- if "Gold Helm" in inventory:
- global helmbonus
- helmbonus = 2
- update_bonus()
- head.shape("ghead.gif")
- he="ghead.gif"
- dtext.undo()
- dtext.write("Defence Bonus: " + str(player.Dbonus), False, align="left", font=("Arial", 14, "normal"))
- def gsword(x, y):
- global sw
- if "Gold Sword" in inventory:
- global swordbonus
- swordbonus = 20
- update_bonus()
- sword.shape("gsword.gif")
- sw="gsword.gif"
- atext.undo()
- atext.write("Attack Bonus: " + str(player.Abonus), False, align="left", font=("Arial", 14, "normal"))
- def gplate(x, y):
- global bo
- if "Gold Plate" in inventory:
- global platebonus
- platebonus = 2
- update_bonus()
- body.shape("gbody.gif")
- bo="gbody.gif"
- dtext.undo()
- dtext.write("Defence Bonus: " + str(player.Dbonus), False, align="left", font=("Arial", 14, "normal"))
- def glegs(x, y):
- global le
- if "Gold Legs" in inventory:
- global legsbonus
- legsbonus = 2
- update_bonus()
- legs.shape("glegs.gif")
- le="glegs.gif"
- dtext.undo()
- dtext.write("Defence Bonus: " + str(player.Dbonus), False, align="left", font=("Arial", 14, "normal"))
- def gboots(x, y):
- global bt
- if "Gold Boots" in inventory:
- global bootsbonus
- bootsbonus = 2
- update_bonus()
- boots.shape("gboots.gif")
- bt="gboots.gif"
- dtext.undo()
- dtext.write("Defence Bonus: " + str(player.Dbonus), False, align="left", font=("Arial", 14, "normal"))
- def ggauntlets(x, y):
- global h1
- global h2
- if "Gold Gauntlets" in inventory:
- global gauntletsbonus
- gauntletsbonus = 2
- update_bonus()
- hand1.shape("ghand1.gif")
- hand2.shape("ghand2.gif")
- h1="ghand1.gif"
- h2="ghand2.gif"
- dtext.undo()
- dtext.write("Defence Bonus: " + str(player.Dbonus), False, align="left", font=("Arial", 14, "normal"))
- def vhelm(x, y):
- global he
- if "Vibranium Helm" in inventory:
- global helmbonus
- helmbonus = 3
- update_bonus()
- head.shape("vhead.gif")
- he="vhead.gif"
- dtext.undo()
- dtext.write("Defence Bonus: " + str(player.Dbonus), False, align="left", font=("Arial", 14, "normal"))
- def vsword(x, y):
- global sw
- if "Vibranium Sword" in inventory:
- global swordbonus
- swordbonus = 30
- update_bonus()
- sword.shape("vsword.gif")
- sw="vsword.gif"
- atext.undo()
- atext.write("Attack Bonus: " + str(player.Abonus), False, align="left", font=("Arial", 14, "normal"))
- def vplate(x, y):
- global bo
- if "Vibranium Plate" in inventory:
- global platebonus
- platebonus = 3
- update_bonus()
- body.shape("vbody.gif")
- bo="vbody.gif"
- dtext.undo()
- dtext.write("Defence Bonus: " + str(player.Dbonus), False, align="left", font=("Arial", 14, "normal"))
- def vlegs(x, y):
- global le
- if "Vibranium Legs" in inventory:
- global legsbonus
- legsbonus = 3
- update_bonus()
- legs.shape("vlegs.gif")
- le="vlegs.gif"
- dtext.undo()
- dtext.write("Defence Bonus: " + str(player.Dbonus), False, align="left", font=("Arial", 14, "normal"))
- def vboots(x, y):
- global bt
- if "Vibranium Boots" in inventory:
- global bootsbonus
- bootsbonus = 3
- update_bonus()
- boots.shape("vboots.gif")
- bt="vboots.gif"
- dtext.undo()
- dtext.write("Defence Bonus: " + str(player.Dbonus), False, align="left", font=("Arial", 14, "normal"))
- def vgauntlets(x, y):
- global h1
- global h2
- if "Vibranium Gauntlets" in inventory:
- global gauntletsbonus
- gauntletsbonus = 3
- update_bonus()
- hand1.shape("vhand1.gif")
- hand2.shape("vhand2.gif")
- h1="vhand1.gif"
- h2="vhand2.gif"
- dtext.undo()
- dtext.write("Defence Bonus: " + str(player.Dbonus), False, align="left", font=("Arial", 14, "normal"))
- def uhelm(x, y):
- global he
- if "Unobtainium Helm" in inventory:
- global helmbonus
- helmbonus = 4
- update_bonus()
- head.shape("uhead.gif")
- he="uhead.gif"
- dtext.undo()
- dtext.write("Defence Bonus: " + str(player.Dbonus), False, align="left", font=("Arial", 14, "normal"))
- def usword(x, y):
- global sw
- if "Unobtainium Sword" in inventory:
- global swordbonus
- swordbonus = 40
- update_bonus()
- sword.shape("usword.gif")
- sw="usword.gif"
- atext.undo()
- atext.write("Attack Bonus: " + str(player.Abonus), False, align="left", font=("Arial", 14, "normal"))
- def uplate(x, y):
- global bo
- if "Unobtainium Plate" in inventory:
- global platebonus;
- platebonus = 4;
- update_bonus()
- body.shape("ubody.gif")
- bo="ubody.gif"
- dtext.undo()
- dtext.write("Defence Bonus: " + str(player.Dbonus), False, align="left", font=("Arial", 14, "normal"))
- def ulegs(x, y):
- global le
- if "Unobtainium Legs" in inventory:
- global legsbonus
- legsbonus = 4
- update_bonus()
- legs.shape("ulegs.gif")
- le="ulegs.gif"
- dtext.undo()
- dtext.write("Defence Bonus: " + str(player.Dbonus), False, align="left", font=("Arial", 14, "normal"))
- def uboots(x, y):
- global bt
- if "Unobtainium Boots" in inventory:
- global bootsbonus
- bootsbonus = 4
- update_bonus()
- boots.shape("uboots.gif")
- bt="uboots.gif"
- dtext.undo()
- dtext.write("Defence Bonus: " + str(player.Dbonus), False, align="left", font=("Arial", 14, "normal"))
- def ugauntlets(x, y):
- global h1
- global h2
- if "Unobtainium Gauntlets" in inventory:
- global gauntletsbonus
- gauntletsbonus = 4
- update_bonus()
- hand1.shape("uhand1.gif")
- hand2.shape("uhand2.gif")
- h1="uhand1.gif"
- h2="uhand2.gif"
- dtext.undo()
- dtext.write("Defence Bonus: " + str(player.Dbonus), False, align="left", font=("Arial", 14, "normal"))
- buttonlist = [sh, ss, sp, sl, sb, sg, gh, gs, gp, gl, gb, gg, vh, vs, vp, vl, vb, vg, uh, us, up, ul, ub, ug]
- for i in inventory:
- x = itemslist.index(i)
- buttonlist[x].shape(imagelist[x])
- sh.onclick(shelm)
- ss.onclick(ssword)
- sp.onclick(splate)
- sl.onclick(slegs)
- sb.onclick(sboots)
- sg.onclick(sgauntlets)
- gh.onclick(ghelm)
- gs.onclick(gsword)
- gp.onclick(gplate)
- gl.onclick(glegs)
- gb.onclick(gboots)
- gg.onclick(ggauntlets)
- vh.onclick(vhelm)
- vs.onclick(vsword)
- vp.onclick(vplate)
- vl.onclick(vlegs)
- vb.onclick(vboots)
- vg.onclick(vgauntlets)
- uh.onclick(uhelm)
- us.onclick(usword)
- up.onclick(uplate)
- ul.onclick(ulegs)
- ub.onclick(uboots)
- ug.onclick(ugauntlets)
- def toff(x, y):
- global helmbonus
- global swordbonus
- global platebonus
- global legsbonus
- global bootsbonus
- global gauntletsbonus
- global he
- global bo
- global le
- global bt
- global h1
- global h2
- dtext.undo()
- dtext.write("Defence Bonus: 0", False, align="left", font=("Arial", 14, "normal"))
- atext.undo()
- atext.write("Attack Bonus: 1", False, align="left", font=("Arial", 14, "normal"))
- head.shape("nhead.gif")
- body.shape("nbody.gif")
- legs.shape("nlegs.gif")
- boots.shape("nboots.gif")
- hand1.shape("nhand1.gif")
- hand2.shape("nhand2.gif")
- helmbonus = 0
- platebonus = 0
- legsbonus = 0
- bootsbonus = 0
- gauntletsbonus = 0
- swordbonus = 0
- he = "nhead.gif"
- bo = "nbody.gif"
- le = "nlegs.gif"
- bt = "nboots.gif"
- h1 = "nhand1.gif"
- h2 = "nhand2.gif"
- def un():
- chesttext.undo()
- off.onclick(toff)
- display()
- setup_maze(levels[l])
- reveal()
- turtle.listen()
- turtle.onkeypress(player.go_left, "Left")
- turtle.onkeypress(player.go_right, "Right")
- turtle.onkeypress(player.go_up, "Up")
- turtle.onkeypress(player.go_down, "Down")
- turtle.onkey(attack, "a")
- while True:
- if l ==5:
- if player.xcor() == -2 and player.ycor() == 501 and h==0:
- turtle.clearscreen()
- welcome = turtle.Turtle()
- welcome.hideturtle()
- welcome.penup()
- welcome.setposition(0, 250)
- welcome.write("You did it!", False, align="center", font=("Arial", 100, "normal"))
- welcome.setposition(0, 180)
- welcome.write("You got to the exit!", False, align="center", font=("Arial", 30, "normal"))
- welcome.setposition(0, 130)
- welcome.write("Great job!", False, align="center", font=("Arial", 30, "normal"))
- welcome.setposition(0, 50)
- welcome.write("Thanks for visiting!", False, align="center", font=("Arial", 30, "normal"))
- wave()
- h=1
- break
- if player.xcor() == -2 and player.ycor() == 501:
- l += 1
- start(1,1)
- if player.xcor() == -2 and player.ycor() == -24:
- l -= 1
- start(1,1)
- if player.xcor() == -23 and player.ycor()== -3 and h==0:
- turtle.tracer(1)
- healtext.setposition(-23,5)
- healtext.write("The healing cloud heals all your ailments", False, align="center", font=("Arial", 10, "normal"))
- time.sleep(1)
- healtext.undo()
- player.hp=100
- player.isalive()
- h=1
- turtle.tracer(0)
- wn.update()
- set(1,2)
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement