diff --git a/bin/Classess/Node.py b/bin/Classess/Node.py new file mode 100644 index 0000000..a99ab06 --- /dev/null +++ b/bin/Classess/Node.py @@ -0,0 +1,11 @@ +class Node: + def __init__(self): + self.state = State() + self.parent = None + self.action = None + + +class State: + def __init__(self): + self.coord = [] + self.direction = "" diff --git a/bin/Classess/__pycache__/Field.cpython-37.pyc b/bin/Classess/__pycache__/Field.cpython-37.pyc index 983225f..5a79351 100644 Binary files a/bin/Classess/__pycache__/Field.cpython-37.pyc and b/bin/Classess/__pycache__/Field.cpython-37.pyc differ diff --git a/bin/Classess/__pycache__/Node.cpython-37.pyc b/bin/Classess/__pycache__/Node.cpython-37.pyc new file mode 100644 index 0000000..17f72cd Binary files /dev/null and b/bin/Classess/__pycache__/Node.cpython-37.pyc differ diff --git a/bin/Classess/__pycache__/Player.cpython-37.pyc b/bin/Classess/__pycache__/Player.cpython-37.pyc index bfd1607..01b51a7 100644 Binary files a/bin/Classess/__pycache__/Player.cpython-37.pyc and b/bin/Classess/__pycache__/Player.cpython-37.pyc differ diff --git a/bin/classess/Field.py b/bin/classess/Field.py index 857c626..124ad03 100644 --- a/bin/classess/Field.py +++ b/bin/classess/Field.py @@ -27,6 +27,10 @@ class Field(object): self.small_image_array = [[0 for i in range(self.rows)] for j in range(self.columns)] self.large_image_array = [[0 for i in range(self.rows)] for j in range(self.columns)] + # Modified by Artem to search in the status area + self.canvas_small_images = [] + self.rectangle = 0 + self.main_frame = Frame(master, width=FRAME_WIDTH, height=FRAME_HEIGHT, bd=0) self.main_frame.pack(anchor=NW) self.small_field_canvas = Canvas(self.main_frame, width=FRAME_WIDTH, height=FRAME_HEIGHT, highlightthickness=0, @@ -39,7 +43,6 @@ class Field(object): # Clear Canvases def Moving(self): - self.small_field_canvas.delete('all') self.large_image_canvas.delete('all') def PuttingSmallImages(self): @@ -55,7 +58,9 @@ class Field(object): small_image_name = self.small_image_array[column][row] self.small_field_canvas.image = small_image_name - self.small_field_canvas.create_image(x, y, anchor=NW, image=small_image_name) + self.canvas_small_images.append( + self.small_field_canvas.create_image(x, y, anchor=NW, image=small_image_name)) + # self.small_field_canvas.create_image(x, y, anchor=NW, image=small_image_name) x += self.image_size + self.x_start row += 1 diff --git a/bin/classess/Player.py b/bin/classess/Player.py index 8076e16..00611fa 100644 --- a/bin/classess/Player.py +++ b/bin/classess/Player.py @@ -22,28 +22,17 @@ class Player(object): self.arrow_south_image = None self.arrow_west_image = None self.arrow_east_image = None + self.image_canvas_id = None def MovingRight(self): if self.current_x + self.step < FRAME_WIDTH: self.current_x += self.step self.current_array_x += 1 - # # Changes the line down - # elif self.current_y + self.step < FRAME_HEIGHT: - # self.current_x = self.x_start - # self.current_array_x = 0 - # self.current_array_y += 1 - # self.current_y += self.step def MovingLeft(self): if self.current_x - self.step >= self.x_start: self.current_x -= self.step self.current_array_x -= 1 - # # Changes the line up - # elif self.current_y - self.step >= self.y_start: - # self.current_x = FRAME_WIDTH - self.step - # self.current_array_x = 9 - # self.current_array_y -= 1 - # self.current_y -= self.step def MovingUp(self): if self.current_y - self.step >= self.y_start: diff --git a/bin/main/main.py b/bin/main/main.py index 05fe255..b1494dd 100644 --- a/bin/main/main.py +++ b/bin/main/main.py @@ -5,6 +5,7 @@ from tkinter import * from bin.classess.Field import Field from bin.classess.Mine import Mine from bin.classess.Player import Player +from bin.classess.Node import Node WINDOW_X = 533 + 1200 WINDOW_Y = 950 @@ -32,12 +33,13 @@ def Arrow(direction): elif direction == "east": image = player.arrow_east_image - field.small_field_canvas.create_image(player.current_x, player.current_y, anchor=NW, image=image) + field.small_field_canvas.itemconfig(player.image_canvas_id, image=image) # Putting images -def Fill(): - field.PuttingSmallImages() +def Fill(bool): + if bool: + field.PuttingSmallImages() # Drawing red/green rectangles for el in field.state_of_cell_array: @@ -55,9 +57,19 @@ def DrawingLargeImage(): # Drawing rectangle -def Rectangle(): - field.small_field_canvas.create_rectangle(player.current_x, player.current_y, player.current_x + player.step - 2, - player.current_y + player.step - 2, width=3, outline='blue2') +# def Rectangle(bool, direction): +# if bool: +# field.rectangle = field.small_field_canvas.create_rectangle(player.current_x, player.current_y, player.current_x + player.step - 2, +# player.current_y + player.step - 2, width=3, outline='blue2') +# else: +# if direction == "East" and field.small_field_canvas.coords(field.rectangle)[0] + player.step < FRAME_WIDTH: +# field.small_field_canvas.move(field.rectangle, player.step, 0) +# elif direction == "West" and field.small_field_canvas.coords(field.rectangle)[0] > player.x_start: +# field.small_field_canvas.move(field.rectangle, -player.step, 0) +# elif direction == "North" and field.small_field_canvas.coords(field.rectangle)[1] > player.y_start: +# field.small_field_canvas.move(field.rectangle, 0, -player.step) +# elif direction == "South" and field.small_field_canvas.coords(field.rectangle)[1] + player.step < FRAME_HEIGHT: +# field.small_field_canvas.move(field.rectangle, 0, player.step) def Next_direction(side): @@ -78,24 +90,36 @@ def Next_direction(side): return player.direction +def MovingForward(): + if player.direction == "east" and field.small_field_canvas.coords(player.image_canvas_id)[0] + player.step < FRAME_WIDTH: + field.small_field_canvas.move(player.image_canvas_id, player.step, 0) + elif player.direction == "west" and field.small_field_canvas.coords(player.image_canvas_id)[0] > player.x_start: + field.small_field_canvas.move(player.image_canvas_id, -player.step, 0) + elif player.direction == "north" and field.small_field_canvas.coords(player.image_canvas_id)[1] > player.y_start: + field.small_field_canvas.move(player.image_canvas_id, 0, -player.step) + elif player.direction == "south" and field.small_field_canvas.coords(player.image_canvas_id)[1] + player.step < FRAME_HEIGHT: + field.small_field_canvas.move(player.image_canvas_id, 0, player.step) + + def Moving(event): # Moving if event.keysym == "Right": # player.MovingRight() field.Moving() - Fill() + Fill(False) next_direction = Next_direction(event.keysym) Arrow(next_direction) elif event.keysym == "Left": # player.MovingLeft() field.Moving() - Fill() + Fill(False) next_direction = Next_direction(event.keysym) Arrow(next_direction) elif event.keysym == "Up": player.Moving() field.Moving() - Fill() + Fill(False) + MovingForward() Arrow(player.direction) # elif event.keysym == "space": # player.MovingDown() @@ -151,6 +175,22 @@ def Action(event): CellDesignation(field.state_of_cell_array, "green") +# Modified by Artem to search in the status area +def MouseClickEvent(event): + print(len(field.canvas_small_images), field.canvas_small_images) + for i in range(0, len(field.canvas_small_images)): + print(field.small_field_canvas.coords(field.canvas_small_images[i])) + print("Lewy przycisk myszy zostal nacisniety!") + node = Node() + print(node.state.coord, node.state.direction, node.action, node.parent) + node.state.coord = field.small_field_canvas.coords(field.canvas_small_images[5]) + node.state.direction = "N" + node.action = "l" + node.parent = 1 + print(node.state.coord, node.state.direction, node.parent, node.action) + print("Pozycje myszy: {} {}".format(event.x, event.y)) + + def PutMines(mines_array): counter = 0 @@ -246,12 +286,17 @@ def main(): player.arrow_west_image = images[3] # Filling window with images - Fill() + Fill(True) # Drawing arrow (player) - Arrow(player.direction) + image = player.arrow_east_image + player.image_canvas_id = field.small_field_canvas.create_image(player.current_x, player.current_y, anchor=NW, + image=image) + # Arrow(player.direction) + # Rectangle(True, "None") # Rectangle() # Binding keyboard press to function field.win.bind("", Action) + field.small_field_canvas.bind("", MouseClickEvent) # Starting mainloop for window field.win.mainloop()