diff --git a/part1_basic/final_test/README.md b/code_of_future/part1_basic/final_test/README.md similarity index 100% rename from part1_basic/final_test/README.md rename to code_of_future/part1_basic/final_test/README.md diff --git a/part1_basic/final_test/app.py b/code_of_future/part1_basic/final_test/app.py similarity index 100% rename from part1_basic/final_test/app.py rename to code_of_future/part1_basic/final_test/app.py diff --git a/part1_basic/final_test/clicker.ahk b/code_of_future/part1_basic/final_test/clicker.ahk similarity index 100% rename from part1_basic/final_test/clicker.ahk rename to code_of_future/part1_basic/final_test/clicker.ahk diff --git a/part1_basic/final_test/img.png b/code_of_future/part1_basic/final_test/img.png similarity index 100% rename from part1_basic/final_test/img.png rename to code_of_future/part1_basic/final_test/img.png diff --git a/part1_basic/lesson1/README.md b/code_of_future/part1_basic/lesson1/README.md similarity index 100% rename from part1_basic/lesson1/README.md rename to code_of_future/part1_basic/lesson1/README.md diff --git a/part1_basic/lesson1/my_first_program.py b/code_of_future/part1_basic/lesson1/my_first_program.py similarity index 100% rename from part1_basic/lesson1/my_first_program.py rename to code_of_future/part1_basic/lesson1/my_first_program.py diff --git a/part1_basic/lesson10/README.md b/code_of_future/part1_basic/lesson10/README.md similarity index 100% rename from part1_basic/lesson10/README.md rename to code_of_future/part1_basic/lesson10/README.md diff --git a/part1_basic/lesson10/app.py b/code_of_future/part1_basic/lesson10/app.py similarity index 100% rename from part1_basic/lesson10/app.py rename to code_of_future/part1_basic/lesson10/app.py diff --git a/part1_basic/lesson2/README.md b/code_of_future/part1_basic/lesson2/README.md similarity index 100% rename from part1_basic/lesson2/README.md rename to code_of_future/part1_basic/lesson2/README.md diff --git a/part1_basic/lesson2/calculator.py b/code_of_future/part1_basic/lesson2/calculator.py similarity index 100% rename from part1_basic/lesson2/calculator.py rename to code_of_future/part1_basic/lesson2/calculator.py diff --git a/part1_basic/lesson3/README.md b/code_of_future/part1_basic/lesson3/README.md similarity index 100% rename from part1_basic/lesson3/README.md rename to code_of_future/part1_basic/lesson3/README.md diff --git a/part1_basic/lesson3/cinema.py b/code_of_future/part1_basic/lesson3/cinema.py similarity index 100% rename from part1_basic/lesson3/cinema.py rename to code_of_future/part1_basic/lesson3/cinema.py diff --git a/part1_basic/lesson4/README.md b/code_of_future/part1_basic/lesson4/README.md similarity index 100% rename from part1_basic/lesson4/README.md rename to code_of_future/part1_basic/lesson4/README.md diff --git a/part1_basic/lesson4/app.py b/code_of_future/part1_basic/lesson4/app.py similarity index 100% rename from part1_basic/lesson4/app.py rename to code_of_future/part1_basic/lesson4/app.py diff --git a/part1_basic/lesson5/README.md b/code_of_future/part1_basic/lesson5/README.md similarity index 100% rename from part1_basic/lesson5/README.md rename to code_of_future/part1_basic/lesson5/README.md diff --git a/part1_basic/lesson5/app.py b/code_of_future/part1_basic/lesson5/app.py similarity index 100% rename from part1_basic/lesson5/app.py rename to code_of_future/part1_basic/lesson5/app.py diff --git a/part1_basic/lesson6/README.md b/code_of_future/part1_basic/lesson6/README.md similarity index 100% rename from part1_basic/lesson6/README.md rename to code_of_future/part1_basic/lesson6/README.md diff --git a/part1_basic/lesson6/app.py b/code_of_future/part1_basic/lesson6/app.py similarity index 100% rename from part1_basic/lesson6/app.py rename to code_of_future/part1_basic/lesson6/app.py diff --git a/part1_basic/lesson7/README.md b/code_of_future/part1_basic/lesson7/README.md similarity index 100% rename from part1_basic/lesson7/README.md rename to code_of_future/part1_basic/lesson7/README.md diff --git a/part1_basic/lesson7/app.py b/code_of_future/part1_basic/lesson7/app.py similarity index 100% rename from part1_basic/lesson7/app.py rename to code_of_future/part1_basic/lesson7/app.py diff --git a/part1_basic/lesson8/README.md b/code_of_future/part1_basic/lesson8/README.md similarity index 100% rename from part1_basic/lesson8/README.md rename to code_of_future/part1_basic/lesson8/README.md diff --git a/part1_basic/lesson8/app.py b/code_of_future/part1_basic/lesson8/app.py similarity index 100% rename from part1_basic/lesson8/app.py rename to code_of_future/part1_basic/lesson8/app.py diff --git a/part1_basic/lesson9/README.md b/code_of_future/part1_basic/lesson9/README.md similarity index 100% rename from part1_basic/lesson9/README.md rename to code_of_future/part1_basic/lesson9/README.md diff --git a/part1_basic/lesson9/app.py b/code_of_future/part1_basic/lesson9/app.py similarity index 100% rename from part1_basic/lesson9/app.py rename to code_of_future/part1_basic/lesson9/app.py diff --git a/part2_OOP/lesson1/README.md b/code_of_future/part2_OOP/lesson1/README.md similarity index 100% rename from part2_OOP/lesson1/README.md rename to code_of_future/part2_OOP/lesson1/README.md diff --git a/part2_OOP/lesson1/bubble_sort.py b/code_of_future/part2_OOP/lesson1/bubble_sort.py similarity index 100% rename from part2_OOP/lesson1/bubble_sort.py rename to code_of_future/part2_OOP/lesson1/bubble_sort.py diff --git a/part2_OOP/lesson2/README.md b/code_of_future/part2_OOP/lesson2/README.md similarity index 100% rename from part2_OOP/lesson2/README.md rename to code_of_future/part2_OOP/lesson2/README.md diff --git a/part2_OOP/lesson2/matrix.py b/code_of_future/part2_OOP/lesson2/matrix.py similarity index 100% rename from part2_OOP/lesson2/matrix.py rename to code_of_future/part2_OOP/lesson2/matrix.py diff --git a/part2_OOP/lesson3/README.md b/code_of_future/part2_OOP/lesson3/README.md similarity index 100% rename from part2_OOP/lesson3/README.md rename to code_of_future/part2_OOP/lesson3/README.md diff --git a/part2_OOP/lesson3/cars.py b/code_of_future/part2_OOP/lesson3/cars.py similarity index 100% rename from part2_OOP/lesson3/cars.py rename to code_of_future/part2_OOP/lesson3/cars.py diff --git a/part2_OOP/lesson4/README.md b/code_of_future/part2_OOP/lesson4/README.md similarity index 100% rename from part2_OOP/lesson4/README.md rename to code_of_future/part2_OOP/lesson4/README.md diff --git a/part2_OOP/lesson4/animals.py b/code_of_future/part2_OOP/lesson4/animals.py similarity index 100% rename from part2_OOP/lesson4/animals.py rename to code_of_future/part2_OOP/lesson4/animals.py diff --git a/part2_OOP/lesson5/README.md b/code_of_future/part2_OOP/lesson5/README.md similarity index 100% rename from part2_OOP/lesson5/README.md rename to code_of_future/part2_OOP/lesson5/README.md diff --git a/part2_OOP/lesson5/file_read.py b/code_of_future/part2_OOP/lesson5/file_read.py similarity index 100% rename from part2_OOP/lesson5/file_read.py rename to code_of_future/part2_OOP/lesson5/file_read.py diff --git a/part2_OOP/lesson5/file_write.py b/code_of_future/part2_OOP/lesson5/file_write.py similarity index 100% rename from part2_OOP/lesson5/file_write.py rename to code_of_future/part2_OOP/lesson5/file_write.py diff --git a/part2_OOP/lesson5/sample.txt b/code_of_future/part2_OOP/lesson5/sample.txt similarity index 100% rename from part2_OOP/lesson5/sample.txt rename to code_of_future/part2_OOP/lesson5/sample.txt diff --git a/part2_OOP/lesson5/user_input.txt b/code_of_future/part2_OOP/lesson5/user_input.txt similarity index 100% rename from part2_OOP/lesson5/user_input.txt rename to code_of_future/part2_OOP/lesson5/user_input.txt diff --git a/part2_OOP/lesson6/README.md b/code_of_future/part2_OOP/lesson6/README.md similarity index 100% rename from part2_OOP/lesson6/README.md rename to code_of_future/part2_OOP/lesson6/README.md diff --git a/part2_OOP/lesson6/app.py b/code_of_future/part2_OOP/lesson6/app.py similarity index 100% rename from part2_OOP/lesson6/app.py rename to code_of_future/part2_OOP/lesson6/app.py diff --git a/part2_OOP/lesson6/poetry.lock b/code_of_future/part2_OOP/lesson6/poetry.lock similarity index 100% rename from part2_OOP/lesson6/poetry.lock rename to code_of_future/part2_OOP/lesson6/poetry.lock diff --git a/part2_OOP/lesson6/pyproject.toml b/code_of_future/part2_OOP/lesson6/pyproject.toml similarity index 100% rename from part2_OOP/lesson6/pyproject.toml rename to code_of_future/part2_OOP/lesson6/pyproject.toml diff --git a/part2_OOP/lesson6/snake/__init__.py b/code_of_future/part2_OOP/lesson6/snake/__init__.py similarity index 100% rename from part2_OOP/lesson6/snake/__init__.py rename to code_of_future/part2_OOP/lesson6/snake/__init__.py diff --git a/part2_OOP/lesson6/snake/food.py b/code_of_future/part2_OOP/lesson6/snake/food.py similarity index 100% rename from part2_OOP/lesson6/snake/food.py rename to code_of_future/part2_OOP/lesson6/snake/food.py diff --git a/part2_OOP/lesson6/snake/game.py b/code_of_future/part2_OOP/lesson6/snake/game.py similarity index 75% rename from part2_OOP/lesson6/snake/game.py rename to code_of_future/part2_OOP/lesson6/snake/game.py index 9eb5e64..bd507d1 100644 --- a/part2_OOP/lesson6/snake/game.py +++ b/code_of_future/part2_OOP/lesson6/snake/game.py @@ -2,8 +2,7 @@ import os import time import pygame as pg -from pygame.key import name -import pygame_menu as pgm +import pygame_menu from .snake import Snake from .food import Food @@ -28,27 +27,30 @@ class Game: self.menu = None self.snake = Snake() self.foods_array = [] + self.game_speed = 0 def game_init(self): pg.init() def get_menu(self): self.set_bg() - self.menu = pgm.Menu('Snakessss game', 400, 300, theme=pgm.pygame_menu.themes.THEME_DARK) + self.menu = pygame_menu.Menu('Snakessss game', 400, 300, theme=pygame_menu.themes.THEME_BLUE) self.menu.add.button('Start new game', self.start_new_game) if self.started: self.menu.add.button('Restore game', self.restore_game) - self.menu.add.selector('Speed', [('Slow', 40), ('Medium', 25), ('Fast', 10)], onchange=self.set_speed) - self.menu.add.button('Exit', pgm.pygame_menu.events.EXIT) + self.menu.add.selector('Speed', [('Slow', 0), ('Medium', 1), ('Fast', 2)], onchange=self.set_speed, onreturn=self.restore_game) + self.menu._widgets[-1].set_value(self.game_speed) + self.menu.add.button('Exit', pygame_menu.events.EXIT) self.menu.mainloop(self.screen) def disable_menu(self): - self.menu.disable() + if self.menu is not None: + self.menu.disable() - def set_speed(self, value, difficulty): - self.snake.speed = difficulty + def set_speed(self, tuple_celected, difficulty): + self.game_speed = difficulty + self.snake.set_speed(speed=self.game_speed) - def set_title(self): pg.display.set_caption(self.title) @@ -56,14 +58,19 @@ class Game: self.screen.blit(self.bg, (0, 0)) def start_new_game(self): + print(self.game_speed, self.snake.speed) self.started = True self.paused = False self.disable_menu() self.need_reset = True - def restore_game(self): - self.disable_menu() - self.paused = False + def restore_game(self, *args, **kwargs): + if self.started: + self.disable_menu() + self.paused = False + else: + self.start_new_game() + def save_game(self): pass @@ -72,10 +79,14 @@ class Game: pass def gameover(self): - surf = self.font.render('Game over', True, (20, 20, 20)) + surf = self.font.render('GAME OVER', True, (20, 20, 20)) rect = surf.get_rect() + score = self.font.render(f'Score: {self.score}', True, (20, 20, 20)) + rect2 = score.get_rect() rect.midtop = (390, 250) + rect2.midtop = (390, 320) self.screen.blit(surf, rect) + self.screen.blit(score, rect2) pg.display.flip() time.sleep(3) @@ -89,6 +100,7 @@ class Game: for f in self.foods_array: if self.snake.get_head_coords() == f.get_coords(): + self.score += 5 * self.snake.length self.foods_array.remove(f) self.snake.length += 1 @@ -99,23 +111,24 @@ class Game: pg.display.update() - if self.snake.impacted: - self.gameover() self.started = False + self.gameover() def mainloop(self): while not self.done: if self.need_reset: - self.snake.reset() + self.snake.reset(speed=self.game_speed) self.start_new_game() self.need_reset = False for event in pg.event.get(): if event.type == pg.QUIT: self.done = True + pressed = pg.key.get_pressed() + if pressed[pg.K_ESCAPE]: self.paused = False if self.paused else True if self.paused: @@ -124,12 +137,15 @@ class Game: if pressed[pg.K_UP]: if self.snake.direction != 'down': self.snake.direction = 'up' + if pressed[pg.K_DOWN]: if self.snake.direction != 'up': self.snake.direction = 'down' + if pressed[pg.K_LEFT]: if self.snake.direction != 'right': self.snake.direction = 'left' + if pressed[pg.K_RIGHT]: if self.snake.direction != 'left': self.snake.direction = 'right' diff --git a/part2_OOP/lesson6/snake/img/bg.png b/code_of_future/part2_OOP/lesson6/snake/img/bg.png similarity index 100% rename from part2_OOP/lesson6/snake/img/bg.png rename to code_of_future/part2_OOP/lesson6/snake/img/bg.png diff --git a/part2_OOP/lesson6/snake/img/body_h.png b/code_of_future/part2_OOP/lesson6/snake/img/body_h.png similarity index 100% rename from part2_OOP/lesson6/snake/img/body_h.png rename to code_of_future/part2_OOP/lesson6/snake/img/body_h.png diff --git a/part2_OOP/lesson6/snake/img/body_ld_ur.png b/code_of_future/part2_OOP/lesson6/snake/img/body_ld_ur.png similarity index 100% rename from part2_OOP/lesson6/snake/img/body_ld_ur.png rename to code_of_future/part2_OOP/lesson6/snake/img/body_ld_ur.png diff --git a/part2_OOP/lesson6/snake/img/body_lu_dr.png b/code_of_future/part2_OOP/lesson6/snake/img/body_lu_dr.png similarity index 100% rename from part2_OOP/lesson6/snake/img/body_lu_dr.png rename to code_of_future/part2_OOP/lesson6/snake/img/body_lu_dr.png diff --git a/part2_OOP/lesson6/snake/img/body_rd_ul.png b/code_of_future/part2_OOP/lesson6/snake/img/body_rd_ul.png similarity index 100% rename from part2_OOP/lesson6/snake/img/body_rd_ul.png rename to code_of_future/part2_OOP/lesson6/snake/img/body_rd_ul.png diff --git a/part2_OOP/lesson6/snake/img/body_ru_dl.png b/code_of_future/part2_OOP/lesson6/snake/img/body_ru_dl.png similarity index 100% rename from part2_OOP/lesson6/snake/img/body_ru_dl.png rename to code_of_future/part2_OOP/lesson6/snake/img/body_ru_dl.png diff --git a/part2_OOP/lesson6/snake/img/body_v.png b/code_of_future/part2_OOP/lesson6/snake/img/body_v.png similarity index 100% rename from part2_OOP/lesson6/snake/img/body_v.png rename to code_of_future/part2_OOP/lesson6/snake/img/body_v.png diff --git a/part2_OOP/lesson6/snake/img/mouse1.png b/code_of_future/part2_OOP/lesson6/snake/img/mouse1.png similarity index 100% rename from part2_OOP/lesson6/snake/img/mouse1.png rename to code_of_future/part2_OOP/lesson6/snake/img/mouse1.png diff --git a/part2_OOP/lesson6/snake/img/mouse2.png b/code_of_future/part2_OOP/lesson6/snake/img/mouse2.png similarity index 100% rename from part2_OOP/lesson6/snake/img/mouse2.png rename to code_of_future/part2_OOP/lesson6/snake/img/mouse2.png diff --git a/part2_OOP/lesson6/snake/img/snake_down.png b/code_of_future/part2_OOP/lesson6/snake/img/snake_down.png similarity index 100% rename from part2_OOP/lesson6/snake/img/snake_down.png rename to code_of_future/part2_OOP/lesson6/snake/img/snake_down.png diff --git a/part2_OOP/lesson6/snake/img/snake_left.png b/code_of_future/part2_OOP/lesson6/snake/img/snake_left.png similarity index 100% rename from part2_OOP/lesson6/snake/img/snake_left.png rename to code_of_future/part2_OOP/lesson6/snake/img/snake_left.png diff --git a/part2_OOP/lesson6/snake/img/snake_right.png b/code_of_future/part2_OOP/lesson6/snake/img/snake_right.png similarity index 100% rename from part2_OOP/lesson6/snake/img/snake_right.png rename to code_of_future/part2_OOP/lesson6/snake/img/snake_right.png diff --git a/part2_OOP/lesson6/snake/img/snake_up.png b/code_of_future/part2_OOP/lesson6/snake/img/snake_up.png similarity index 100% rename from part2_OOP/lesson6/snake/img/snake_up.png rename to code_of_future/part2_OOP/lesson6/snake/img/snake_up.png diff --git a/part2_OOP/lesson6/snake/snake.py b/code_of_future/part2_OOP/lesson6/snake/snake.py similarity index 94% rename from part2_OOP/lesson6/snake/snake.py rename to code_of_future/part2_OOP/lesson6/snake/snake.py index ce2fdae..3dd0f64 100644 --- a/part2_OOP/lesson6/snake/snake.py +++ b/code_of_future/part2_OOP/lesson6/snake/snake.py @@ -24,13 +24,16 @@ class Snake: self.direction = 'right' self.direction_prev = 'right' - self.length = 10 - self.speed = 40 # скорость движения змейки чем меньше, тем быстрее + self.length = 2 + self.speed = 30 # скорость движения змейки чем меньше, тем быстрее self.counter = 0 # Просто счетчик, для регулировки скорости нужен self.body = kwargs.get('body', [('h', 60, 300), ('h', 30, 300)]) self.impacted = False - def reset(self): + def set_speed(self, **kwargs): + self.speed = (30, 20, 10)[kwargs.get('speed', 30)] + + def reset(self, **kwargs): self.x = 90 self.y = 300 self.body = [('h', 60, 300), ('h', 30, 300)] @@ -38,7 +41,7 @@ class Snake: self.direction_prev = 'right' self.impacted = False self.length = 2 - self.speed = 40 + self.set_speed(**kwargs) def get_head_coords(self): return self.x, self.y