Small edit
This commit is contained in:
parent
ad1681e561
commit
485a0ebf13
@ -38,40 +38,33 @@ class Field(object):
|
|||||||
bg='gray')
|
bg='gray')
|
||||||
self.large_image_canvas.place(x=FRAME_WIDTH + 5, y=3)
|
self.large_image_canvas.place(x=FRAME_WIDTH + 5, y=3)
|
||||||
|
|
||||||
# # Putting images
|
# Clear Canvases
|
||||||
# def Fill(self):
|
def Moving(self):
|
||||||
# x = self.x_start
|
self.small_field_canvas.delete('all')
|
||||||
# y = self.y_start
|
self.large_image_canvas.delete('all')
|
||||||
#
|
|
||||||
# row = 0
|
|
||||||
# column = 0
|
|
||||||
#
|
|
||||||
# # Drawing small images
|
|
||||||
# for i in range(self.columns):
|
|
||||||
# for j in range(self.rows):
|
|
||||||
# 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)
|
|
||||||
#
|
|
||||||
# x += self.image_size + self.x_start
|
|
||||||
# row += 1
|
|
||||||
# y += self.image_size + self.y_start
|
|
||||||
# x = self.x_start
|
|
||||||
# column += 1
|
|
||||||
# row = 0
|
|
||||||
#
|
|
||||||
# # Drawing red/green rectangles
|
|
||||||
# for el in self.state_of_cell_array:
|
|
||||||
# if el[0] != 0:
|
|
||||||
# self.small_field_canvas.create_rectangle(el[0], el[1], el[0] + step - 2,
|
|
||||||
# el[1] + step - 2, width=3, outline=el[2])
|
|
||||||
#
|
|
||||||
# DrawingLargeImage()
|
|
||||||
# self.DrawingLargeImage()
|
|
||||||
|
|
||||||
# def DrawingLargeImage(self):
|
def PuttingSmallImages(self):
|
||||||
# large_img_name = self.large_image_array[player.current_array_y][player.current_array_x]
|
x = self.x_start
|
||||||
#
|
y = self.y_start
|
||||||
# self.large_image_canvas.image = large_img_name
|
|
||||||
# self.large_image_canvas.create_image(0, 0, anchor=NW, image=large_img_name)
|
row = 0
|
||||||
|
column = 0
|
||||||
|
|
||||||
|
# Putting small images
|
||||||
|
for i in range(self.columns):
|
||||||
|
for j in range(self.rows):
|
||||||
|
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)
|
||||||
|
|
||||||
|
x += self.image_size + self.x_start
|
||||||
|
row += 1
|
||||||
|
y += self.image_size + self.y_start
|
||||||
|
x = self.x_start
|
||||||
|
column += 1
|
||||||
|
row = 0
|
||||||
|
|
||||||
|
def PuttingLargeImage(self, large_img_name):
|
||||||
|
self.large_image_canvas.image = large_img_name
|
||||||
|
self.large_image_canvas.create_image(0, 0, anchor=NW, image=large_img_name)
|
||||||
|
@ -19,60 +19,32 @@ class Player(object):
|
|||||||
self.current_array_x = 0
|
self.current_array_x = 0
|
||||||
self.current_array_y = 0
|
self.current_array_y = 0
|
||||||
|
|
||||||
# def Moving(self, event):
|
def MovingRight(self):
|
||||||
# # Moving
|
if self.current_x + self.step < FRAME_WIDTH:
|
||||||
# if event.keysym == "Right":
|
self.current_x += self.step
|
||||||
# if self.current_x + self.step < FRAME_WIDTH:
|
self.current_array_x += 1
|
||||||
# self.current_x += self.step
|
elif self.current_y + self.step < FRAME_HEIGHT:
|
||||||
# field.small_field_canvas.delete('all')
|
self.current_x = self.x_start
|
||||||
# field.large_image_canvas.delete('all')
|
self.current_array_x = 0
|
||||||
# self.current_array_x += 1
|
self.current_array_y += 1
|
||||||
# field.Fill()
|
self.current_y += self.step
|
||||||
# self.Rectangle()
|
|
||||||
# elif self.current_y + self.step < FRAME_HEIGHT:
|
|
||||||
# self.current_x = self.x_start
|
|
||||||
# field.small_field_canvas.delete('all')
|
|
||||||
# field.large_image_canvas.delete('all')
|
|
||||||
# self.current_array_x = 0
|
|
||||||
# self.current_array_y += 1
|
|
||||||
# self.current_y += self.step
|
|
||||||
# field.Fill()
|
|
||||||
# self.Rectangle()
|
|
||||||
# elif event.keysym == "Left":
|
|
||||||
# if self.current_x - self.step >= self.x_start:
|
|
||||||
# self.current_x -= self.step
|
|
||||||
# field.small_field_canvas.delete('all')
|
|
||||||
# field.large_image_canvas.delete('all')
|
|
||||||
# self.current_array_x -= 1
|
|
||||||
# field.Fill()
|
|
||||||
# self.Rectangle()
|
|
||||||
# elif self.current_y - self.step >= self.y_start:
|
|
||||||
# self.current_x = FRAME_WIDTH - self.step
|
|
||||||
# field.small_field_canvas.delete('all')
|
|
||||||
# field.large_image_canvas.delete('all')
|
|
||||||
# self.current_array_x = 9
|
|
||||||
# self.current_array_y -= 1
|
|
||||||
# self.current_y -= self.step
|
|
||||||
# field.Fill()
|
|
||||||
# self.Rectangle()
|
|
||||||
# elif event.keysym == "Up":
|
|
||||||
# if self.current_y - self.step >= self.y_start:
|
|
||||||
# self.current_y -= self.step
|
|
||||||
# field.small_field_canvas.delete('all')
|
|
||||||
# field.large_image_canvas.delete('all')
|
|
||||||
# self.current_array_y -= 1
|
|
||||||
# field.Fill()
|
|
||||||
# self.Rectangle()
|
|
||||||
# elif event.keysym == "Down":
|
|
||||||
# if self.current_y + self.step < FRAME_HEIGHT:
|
|
||||||
# self.current_y += self.step
|
|
||||||
# field.small_field_canvas.delete('all')
|
|
||||||
# field.large_image_canvas.delete('all')
|
|
||||||
# self.current_array_y += 1
|
|
||||||
# field.Fill()
|
|
||||||
# self.Rectangle()
|
|
||||||
|
|
||||||
# # Drawing rectangle
|
def MovingLeft(self):
|
||||||
# def Rectangle(self):
|
if self.current_x - self.step >= self.x_start:
|
||||||
# field.small_field_canvas.create_rectangle(self.current_x, self.current_y, self.current_x + self.step - 2,
|
self.current_x -= self.step
|
||||||
# self.current_y + self.step - 2, width=3, outline='blue2')
|
self.current_array_x -= 1
|
||||||
|
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:
|
||||||
|
self.current_y -= self.step
|
||||||
|
self.current_array_y -= 1
|
||||||
|
|
||||||
|
def MovingDown(self):
|
||||||
|
if self.current_y + self.step < FRAME_HEIGHT:
|
||||||
|
self.current_y += self.step
|
||||||
|
self.current_array_y += 1
|
||||||
|
Binary file not shown.
Binary file not shown.
@ -19,32 +19,13 @@ field = Field()
|
|||||||
|
|
||||||
# Putting images
|
# Putting images
|
||||||
def Fill():
|
def Fill():
|
||||||
x = field.x_start
|
field.PuttingSmallImages()
|
||||||
y = field.y_start
|
|
||||||
|
|
||||||
row = 0
|
|
||||||
column = 0
|
|
||||||
|
|
||||||
# Drawing small images
|
|
||||||
for i in range(field.columns):
|
|
||||||
for j in range(field.rows):
|
|
||||||
small_image_name = field.small_image_array[column][row]
|
|
||||||
|
|
||||||
field.small_field_canvas.image = small_image_name
|
|
||||||
field.small_field_canvas.create_image(x, y, anchor=NW, image=small_image_name)
|
|
||||||
|
|
||||||
x += field.image_size + field.x_start
|
|
||||||
row += 1
|
|
||||||
y += field.image_size + field.y_start
|
|
||||||
x = field.x_start
|
|
||||||
column += 1
|
|
||||||
row = 0
|
|
||||||
|
|
||||||
# Drawing red/green rectangles
|
# Drawing red/green rectangles
|
||||||
for el in field.state_of_cell_array:
|
for el in field.state_of_cell_array:
|
||||||
if el[0] != 0:
|
if el[0] != 0:
|
||||||
field.small_field_canvas.create_rectangle(el[0], el[1], el[0] + player.step - 2,
|
field.small_field_canvas.create_rectangle(el[0], el[1], el[0] + player.step - 2,
|
||||||
el[1] + player.step - 2, width=3, outline=el[2])
|
el[1] + player.step - 2, width=3, outline=el[2])
|
||||||
|
|
||||||
DrawingLargeImage()
|
DrawingLargeImage()
|
||||||
|
|
||||||
@ -52,8 +33,7 @@ def Fill():
|
|||||||
def DrawingLargeImage():
|
def DrawingLargeImage():
|
||||||
large_img_name = field.large_image_array[player.current_array_y][player.current_array_x]
|
large_img_name = field.large_image_array[player.current_array_y][player.current_array_x]
|
||||||
|
|
||||||
field.large_image_canvas.image = large_img_name
|
field.PuttingLargeImage(large_img_name)
|
||||||
field.large_image_canvas.create_image(0, 0, anchor=NW, image=large_img_name)
|
|
||||||
|
|
||||||
|
|
||||||
# Drawing rectangle
|
# Drawing rectangle
|
||||||
@ -65,55 +45,25 @@ def Rectangle():
|
|||||||
def Moving(event):
|
def Moving(event):
|
||||||
# Moving
|
# Moving
|
||||||
if event.keysym == "Right":
|
if event.keysym == "Right":
|
||||||
if player.current_x + player.step < FRAME_WIDTH:
|
player.MovingRight()
|
||||||
player.current_x += player.step
|
field.Moving()
|
||||||
field.small_field_canvas.delete('all')
|
Fill()
|
||||||
field.large_image_canvas.delete('all')
|
Rectangle()
|
||||||
player.current_array_x += 1
|
|
||||||
Fill()
|
|
||||||
Rectangle()
|
|
||||||
elif player.current_y + player.step < FRAME_HEIGHT:
|
|
||||||
player.current_x = player.x_start
|
|
||||||
field.small_field_canvas.delete('all')
|
|
||||||
field.large_image_canvas.delete('all')
|
|
||||||
player.current_array_x = 0
|
|
||||||
player.current_array_y += 1
|
|
||||||
player.current_y += player.step
|
|
||||||
Fill()
|
|
||||||
Rectangle()
|
|
||||||
elif event.keysym == "Left":
|
elif event.keysym == "Left":
|
||||||
if player.current_x - player.step >= player.x_start:
|
player.MovingLeft()
|
||||||
player.current_x -= player.step
|
field.Moving()
|
||||||
field.small_field_canvas.delete('all')
|
Fill()
|
||||||
field.large_image_canvas.delete('all')
|
Rectangle()
|
||||||
player.current_array_x -= 1
|
|
||||||
Fill()
|
|
||||||
Rectangle()
|
|
||||||
elif player.current_y - player.step >= player.y_start:
|
|
||||||
player.current_x = FRAME_WIDTH - player.step
|
|
||||||
field.small_field_canvas.delete('all')
|
|
||||||
field.large_image_canvas.delete('all')
|
|
||||||
player.current_array_x = 9
|
|
||||||
player.current_array_y -= 1
|
|
||||||
player.current_y -= player.step
|
|
||||||
Fill()
|
|
||||||
Rectangle()
|
|
||||||
elif event.keysym == "Up":
|
elif event.keysym == "Up":
|
||||||
if player.current_y - player.step >= player.y_start:
|
player.MovingUp()
|
||||||
player.current_y -= player.step
|
field.Moving()
|
||||||
field.small_field_canvas.delete('all')
|
Fill()
|
||||||
field.large_image_canvas.delete('all')
|
Rectangle()
|
||||||
player.current_array_y -= 1
|
|
||||||
Fill()
|
|
||||||
Rectangle()
|
|
||||||
elif event.keysym == "Down":
|
elif event.keysym == "Down":
|
||||||
if player.current_y + player.step < FRAME_HEIGHT:
|
player.MovingDown()
|
||||||
player.current_y += player.step
|
field.Moving()
|
||||||
field.small_field_canvas.delete('all')
|
Fill()
|
||||||
field.large_image_canvas.delete('all')
|
Rectangle()
|
||||||
player.current_array_y += 1
|
|
||||||
Fill()
|
|
||||||
Rectangle()
|
|
||||||
|
|
||||||
|
|
||||||
def ImagesInArray(directory, array):
|
def ImagesInArray(directory, array):
|
||||||
@ -156,8 +106,6 @@ def Action(event):
|
|||||||
def main():
|
def main():
|
||||||
# Creating the main window of an application
|
# Creating the main window of an application
|
||||||
win_size = f'{WINDOW_X}x{WINDOW_Y}'
|
win_size = f'{WINDOW_X}x{WINDOW_Y}'
|
||||||
# global win
|
|
||||||
# win = Tk()
|
|
||||||
field.win.title("Sapper")
|
field.win.title("Sapper")
|
||||||
field.win.configure(bg='gray')
|
field.win.configure(bg='gray')
|
||||||
field.win.geometry(win_size)
|
field.win.geometry(win_size)
|
||||||
|
Loading…
Reference in New Issue
Block a user