예제 #1
0
#####
import maze
from binary_tree import Binary_tree

print('##################################')
print('testing Cell class')
#define 3 cells, link them, set/get neighbours
c1 = maze.Cell(4, 4)
c2 = maze.Cell(4, 5)
c3 = maze.Cell(1, 5)
print(c1)
print(c2)
c1.link(c2, False)
c1.link(c3)
print(c1.get_links(), c2.get_links())
print(c1.is_linked(c2))
print(c2.is_linked(c1))
print(c1.is_linked(c3))
print(c3.is_linked(c1))
print(c1.get_neighbors())
c1.set_neighbors('north', c3)
print(c1.get_neighbors())

print('##################################')
print('testing Grid class')
g = maze.Grid(4, 4)
print(len(g))
print(g[2, 2])
print(g[0, 4])
print(g[4, 0])
print(g[4, 4])
예제 #2
0
 def setUp(self):
     self.cell = maze.Cell(2,3)
예제 #3
0
def update():
   if (mario.dir != maze.STAND):
       old_heading = mario.heading()
       if (mario.dir == maze.LEFT): new_heading = 180
       elif (mario.dir == maze.RIGHT): new_heading = 0
       elif (mario.dir == maze.UP): new_heading = 90
       else: new_heading = 270
       if (old_heading != new_heading):
          old_speed = mario.speed()
          mario.speed(0)
          mario.setheading(new_heading)
          mario.speed(old_speed)


       new_cell = maze.Cell(mario.cell.x, mario.cell.y)
       if (mario.dir == maze.LEFT): new_cell.x -= 1
       elif (mario.dir == maze.RIGHT): new_cell.x += 1
       elif (mario.dir == maze.UP): new_cell.y += 1
       else: new_cell.y -= 1
#SCORE TABELA
       if (not is_wall(new_cell)):
          mario.forward(maze.cell_size)
          mario.cell = new_cell
          if(mario.cell in items) and mario.lives>0:
            mario.shape("circle")
            mario.color(maze.bg_color)
            mario.shapesize(0.8)
            mario.stamp()
            mario.color("darkblue", "white")
            mario.shape("turtle")
            mario.score += 10

            items.remove(mario.cell)
            score_drawer.undo()
            score_drawer.goto (-287, 250)
            score_drawer.write("SCORE = {0}".format(int(mario.score)), move=False, \
                               font=("Tempus Sans ITC", 12, "bold"))

# ############## LEVEL 2 E GECIS
          elif mario.score==gecis*10 and mario.score!=100:

            mario.home()
            lost_drawer.penup()
            lost_drawer.goto(0, -280)
            lost_drawer.pendown()
            lost_drawer.write("LEVEL 2",align = "center", font= ("Tempus Sans ITC", 20, "bold"))
            mario.heading()
            mario.hideturtle()

            drawer.clear()
            level2()

            mario.score=50.1
            mario.showturtle()

# ############## LEVEL 3 E GECIS
          if mario.score==150.1:
            drawer.clear()
            level3()
            mario.score=150.2
            lost_drawer.penup()
            lost_drawer.goto(0, -280)
            lost_drawer.pendown()
            lost_drawer.write("LEVEL 3",align = "center", font= ("Tempus Sans ITC", 20, "bold"))
            lost_drawer.undo()
            mario.heading()
          if mario.score == 300.2:
                lost_drawer.penup()

                lost_drawer.goto(0,0)
                lost_drawer.pendown()
                mario.hideturtle()
                mario.move_to_home()
                for i in range(100) :

                    lost_drawer.write("YOU WON",align = "center", font= ("Tempus Sans ITC", 31, "bold"))
                    lost_drawer.undo()

#LIVES TABELA
          if(mario.cell in traps):
            mario.move_to_home()
            mario.dir= maze.STAND
            mario.lives -= 1
            life_drawer.undo()
            life_drawer.goto (218, 250)

            if mario.lives > 0:

                lost_drawer.pendown()
                life_drawer.clear()

                lost_drawer.color = ("white")
                life_drawer.write("LIVES = {0}".format(mario.lives), move=False, \
                         font=("Tempus Sans ITC", 12, "bold"))
#LOST YAZISI
            elif mario.lives<=0:
                lost_drawer.write("YOU LOST",align = "center", font= ("Tempus Sans ITC", 25, "bold"))
                mario.hideturtle()
                mario.goto(0,0)
                mario.heading()

       else:
          mario.dir = maze.STAND
       wn.title("Mario at ({0}, {1})  SCORE={2}".format(mario.cell.x, mario.cell.y, int(mario.score)))

   wn.ontimer(update,100)
예제 #4
0
def level3():
    mario.dir=maze.STAND
    mario.move_to_home()
    rng = random.Random()
    global gecis
    global walls
    global items
    global traps
    #ELMA RANDOM
    elma_sayisi=15
    items = []

    gecis=elma_sayisi
    item_apple =elma_sayisi
    while (item_apple > 0):
       i = rng.randint(-maze.width+1, maze.width-1)
       j = rng.randint(-maze.height+1, maze.height-1)
       new_cell = maze.Cell(i,j)
       if ((i == 0 and j == 0) or new_cell in items):
          continue
       else:
          items.append(new_cell)
          item_apple -= 1

    print(items)
    lost_drawer.penup()
    lost_drawer.goto(0, -280)
    lost_drawer.pendown()
    lost_drawer.write("LEVEL 3",align = "center", font= ("Tempus Sans ITC", 20, "bold"))
    drawer.color("black", "darkgreen")
    drawer.shape("circle")
    drawer.shapesize(0.8)
    for cell in items:
        (x,y) = cell.to_coord()
        drawer.goto(x,y)
        drawer.stamp()

    #KUTU RANDOM
    walls = []
    wall_count = 10
    while (wall_count > 0):
       i = rng.randint(-maze.width+1, maze.width-1)
       j = rng.randint(-maze.height+1, maze.height-1)
       new_cell = maze.Cell(i,j)
       if ((i == 0 and j == 0) or new_cell in walls or new_cell in items):
          continue
       else:
          walls.append(new_cell)
          wall_count -= 1
    print(walls)

    #TUZAK RANDOM
    traps = []
    trap_x = 11
    while (trap_x > 0):
       i = rng.randint(-maze.width+1, maze.width-1)
       j = rng.randint(-maze.height+1, maze.height-1)
       new_cell = maze.Cell(i,j)
       if ((i == 0 and j == 0) or new_cell in traps or new_cell in items):
          continue
       else:
          traps.append(new_cell)
          trap_x -= 1
    print(traps)
    drawer.color("black", "red")
    drawer.shape("triangle")
    drawer.shapesize(0.8)
    for cell in traps:
        (x,y) = cell.to_coord()
        drawer.goto(x,y)
        drawer.stamp()
    drawer.fillcolor("black")
    for cell in walls:
        (x,y) = cell.to_coord(True)
        x += 1
        y -= 1
        maze.fill_rect(drawer, x, y, maze.cell_size-2, maze.cell_size-2)
    lost_drawer.clear()
#LISTS FOR 3
    myfile = open("3rdLevelItems.txt", "w")
    myfile.write("3rdLevelApples")
    myfile.write(str(items))
    myfile.write("\n")
    myfile.write("3rdLevelTraps")
    myfile.write(str(traps))
    myfile.write("\n")
    myfile.write("3rdLevelWalls")
    myfile.write(str(walls))
    myfile.write("\n")
    myfile.close()
예제 #5
0
def debug():
    maze.clear_cell(drawer, maze.Cell(6,6))
    mario.move_to_cell(maze.Cell(0,0))
예제 #6
0
wn.onkey(turn_up, "Up")
wn.onkey(turn_down, "Down")
wn.onkey(start, "s")
wn.onkey(start, "S")
wn.onkey(debug, "d")
#MARIO OZELLIK
mario.hideturtle()
mario.shapesize(0.7)
mario.color("darkblue", "white")
#ORTA YAZI
for t in [drawer, score_drawer]:
    t.fillcolor("black")
    t.speed(0)
    t.hideturtle()
    t.penup()
(x,y) = maze.Cell(0,maze.height+2).to_coord()
score_drawer.goto(x,y-8)
score_drawer.goto(0,250)
score_drawer.color("black")
score_drawer.write("Press 'S' to begin the game", align = "center", font= ("Tempus Sans ITC", 12, "bold") )

# # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # #
# CERCEVE
cerceveci.penup()
cerceveci.hideturtle()
cerceveci.speed(100)
short_side = maze.cell_size
long_side_w = (2*maze.width+3)*maze.cell_size
long_side_h = (2*maze.height+3)*maze.cell_size
(x,y) = maze.Cell(-maze.width-1, maze.height+1).to_coord(True)
maze.fill_rect(cerceveci,x,y,short_side, long_side_h)