forked from s452716/Test
New way to mowe V2
This commit is contained in:
parent
7113805f98
commit
d733270048
11
bin/Classess/Node.py
Normal file
11
bin/Classess/Node.py
Normal file
@ -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 = ""
|
Binary file not shown.
BIN
bin/Classess/__pycache__/Node.cpython-37.pyc
Normal file
BIN
bin/Classess/__pycache__/Node.cpython-37.pyc
Normal file
Binary file not shown.
Binary file not shown.
@ -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.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)]
|
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 = Frame(master, width=FRAME_WIDTH, height=FRAME_HEIGHT, bd=0)
|
||||||
self.main_frame.pack(anchor=NW)
|
self.main_frame.pack(anchor=NW)
|
||||||
self.small_field_canvas = Canvas(self.main_frame, width=FRAME_WIDTH, height=FRAME_HEIGHT, highlightthickness=0,
|
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
|
# Clear Canvases
|
||||||
def Moving(self):
|
def Moving(self):
|
||||||
self.small_field_canvas.delete('all')
|
|
||||||
self.large_image_canvas.delete('all')
|
self.large_image_canvas.delete('all')
|
||||||
|
|
||||||
def PuttingSmallImages(self):
|
def PuttingSmallImages(self):
|
||||||
@ -55,7 +58,9 @@ class Field(object):
|
|||||||
small_image_name = self.small_image_array[column][row]
|
small_image_name = self.small_image_array[column][row]
|
||||||
|
|
||||||
self.small_field_canvas.image = small_image_name
|
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
|
x += self.image_size + self.x_start
|
||||||
row += 1
|
row += 1
|
||||||
|
@ -22,28 +22,17 @@ class Player(object):
|
|||||||
self.arrow_south_image = None
|
self.arrow_south_image = None
|
||||||
self.arrow_west_image = None
|
self.arrow_west_image = None
|
||||||
self.arrow_east_image = None
|
self.arrow_east_image = None
|
||||||
|
self.image_canvas_id = None
|
||||||
|
|
||||||
def MovingRight(self):
|
def MovingRight(self):
|
||||||
if self.current_x + self.step < FRAME_WIDTH:
|
if self.current_x + self.step < FRAME_WIDTH:
|
||||||
self.current_x += self.step
|
self.current_x += self.step
|
||||||
self.current_array_x += 1
|
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):
|
def MovingLeft(self):
|
||||||
if self.current_x - self.step >= self.x_start:
|
if self.current_x - self.step >= self.x_start:
|
||||||
self.current_x -= self.step
|
self.current_x -= self.step
|
||||||
self.current_array_x -= 1
|
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):
|
def MovingUp(self):
|
||||||
if self.current_y - self.step >= self.y_start:
|
if self.current_y - self.step >= self.y_start:
|
||||||
|
@ -5,6 +5,7 @@ from tkinter import *
|
|||||||
from bin.classess.Field import Field
|
from bin.classess.Field import Field
|
||||||
from bin.classess.Mine import Mine
|
from bin.classess.Mine import Mine
|
||||||
from bin.classess.Player import Player
|
from bin.classess.Player import Player
|
||||||
|
from bin.classess.Node import Node
|
||||||
|
|
||||||
WINDOW_X = 533 + 1200
|
WINDOW_X = 533 + 1200
|
||||||
WINDOW_Y = 950
|
WINDOW_Y = 950
|
||||||
@ -32,11 +33,12 @@ def Arrow(direction):
|
|||||||
elif direction == "east":
|
elif direction == "east":
|
||||||
image = player.arrow_east_image
|
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
|
# Putting images
|
||||||
def Fill():
|
def Fill(bool):
|
||||||
|
if bool:
|
||||||
field.PuttingSmallImages()
|
field.PuttingSmallImages()
|
||||||
|
|
||||||
# Drawing red/green rectangles
|
# Drawing red/green rectangles
|
||||||
@ -55,9 +57,19 @@ def DrawingLargeImage():
|
|||||||
|
|
||||||
|
|
||||||
# Drawing rectangle
|
# Drawing rectangle
|
||||||
def Rectangle():
|
# def Rectangle(bool, direction):
|
||||||
field.small_field_canvas.create_rectangle(player.current_x, player.current_y, player.current_x + player.step - 2,
|
# if bool:
|
||||||
player.current_y + player.step - 2, width=3, outline='blue2')
|
# 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):
|
def Next_direction(side):
|
||||||
@ -78,24 +90,36 @@ def Next_direction(side):
|
|||||||
return player.direction
|
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):
|
def Moving(event):
|
||||||
# Moving
|
# Moving
|
||||||
if event.keysym == "Right":
|
if event.keysym == "Right":
|
||||||
# player.MovingRight()
|
# player.MovingRight()
|
||||||
field.Moving()
|
field.Moving()
|
||||||
Fill()
|
Fill(False)
|
||||||
next_direction = Next_direction(event.keysym)
|
next_direction = Next_direction(event.keysym)
|
||||||
Arrow(next_direction)
|
Arrow(next_direction)
|
||||||
elif event.keysym == "Left":
|
elif event.keysym == "Left":
|
||||||
# player.MovingLeft()
|
# player.MovingLeft()
|
||||||
field.Moving()
|
field.Moving()
|
||||||
Fill()
|
Fill(False)
|
||||||
next_direction = Next_direction(event.keysym)
|
next_direction = Next_direction(event.keysym)
|
||||||
Arrow(next_direction)
|
Arrow(next_direction)
|
||||||
elif event.keysym == "Up":
|
elif event.keysym == "Up":
|
||||||
player.Moving()
|
player.Moving()
|
||||||
field.Moving()
|
field.Moving()
|
||||||
Fill()
|
Fill(False)
|
||||||
|
MovingForward()
|
||||||
Arrow(player.direction)
|
Arrow(player.direction)
|
||||||
# elif event.keysym == "space":
|
# elif event.keysym == "space":
|
||||||
# player.MovingDown()
|
# player.MovingDown()
|
||||||
@ -151,6 +175,22 @@ def Action(event):
|
|||||||
CellDesignation(field.state_of_cell_array, "green")
|
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):
|
def PutMines(mines_array):
|
||||||
counter = 0
|
counter = 0
|
||||||
|
|
||||||
@ -246,12 +286,17 @@ def main():
|
|||||||
player.arrow_west_image = images[3]
|
player.arrow_west_image = images[3]
|
||||||
|
|
||||||
# Filling window with images
|
# Filling window with images
|
||||||
Fill()
|
Fill(True)
|
||||||
# Drawing arrow (player)
|
# 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()
|
# Rectangle()
|
||||||
# Binding keyboard press to function
|
# Binding keyboard press to function
|
||||||
field.win.bind("<Key>", Action)
|
field.win.bind("<Key>", Action)
|
||||||
|
field.small_field_canvas.bind("<Button-1>", MouseClickEvent)
|
||||||
# Starting mainloop for window
|
# Starting mainloop for window
|
||||||
field.win.mainloop()
|
field.win.mainloop()
|
||||||
|
|
||||||
|
Loading…
Reference in New Issue
Block a user