{"id":827,"date":"2026-04-09T21:25:26","date_gmt":"2026-04-09T17:25:26","guid":{"rendered":"https:\/\/avdeevk.ru\/?p=827"},"modified":"2026-04-09T21:26:28","modified_gmt":"2026-04-09T17:26:28","slug":"python-middle-game-wolf_and_eggs","status":"publish","type":"post","link":"https:\/\/avdeevk.ru\/index.php\/2026\/04\/09\/python-middle-game-wolf_and_eggs\/","title":{"rendered":"Python.Middle: \u0418\u0433\u0440\u0430 &#171;\u0412\u043e\u043b\u043a \u0438 \u044f\u0439\u0446\u0430&#187;"},"content":{"rendered":"\n<p>\u0412 \u0438\u0433\u0440\u0435 7 \u0444\u0430\u0439\u043b\u043e\u0432:<\/p>\n\n\n\n<ol class=\"wp-block-list\">\n<li>WEConf.py | \u0424\u0430\u0439\u043b \u043a\u043e\u043d\u0444\u0438\u0433\u0443\u0440\u0430\u0446\u0438\u0438<\/li>\n<\/ol>\n\n\n\n<pre class=\"wp-block-code\"><code>class WEConf:\n    scWidth = 400 # \u0448\u0438\u0440\u0438\u043d\u0430 \u043e\u043a\u043d\u0430\n    scHeight = 600 # \u0432\u044b\u0441\u043e\u0442\u0430 \u043e\u043a\u043d\u0430\n    white = (255,255,255) # \u0431\u0435\u043b\u044b\u0439 \u0446\u0432\u0435\u0442\n    black = (0, 0, 0) # \u0447\u0451\u0440\u043d\u044b\u0439 \u0446\u0432\u0435\u0442\n    red = (255,0,0) # \u043a\u0440\u0430\u0441\u043d\u044b\u0439 \u0446\u0432\u0435\u0442\n    clock = 60 # \u0447\u0430\u0441\u0442\u043e\u0442\u0430 \u043e\u0431\u043d\u043e\u0432\u043b\u0435\u043d\u0438\u044f \u0438\u0433\u0440\u044b\/\u044d\u043a\u0440\u0430\u043d\u0430<\/code><\/pre>\n\n\n\n<p>2. CollObject.py | \u0424\u0430\u0439\u043b \u0434\u043b\u044f \u0410\u0431\u0441\u0442\u0440\u0430\u043a\u0442\u043d\u043e\u0433\u043e \u043a\u043b\u0430\u0441\u0441\u0430 Colladable Object, \u043a\u043e\u0442\u043e\u0440\u044b\u0439 \u0441\u043e\u0434\u0435\u0440\u0436\u0438\u0442 \u0432\u0441\u0435 \u041e\u0411\u0429\u0418\u0415 \u043c\u0435\u0442\u043e\u0434\u044b \u0434\u043b\u044f \u0432\u0441\u0435\u0445 \u0443\u0447\u0430\u0441\u0442\u043d\u0438\u043a\u043e\u0432 \u0438\u0433\u0440\u043e\u0432\u043e\u0433\u043e \u043f\u0440\u043e\u0446\u0435\u0441\u0441\u0430, \u043a\u043e\u0442\u043e\u0440\u044b\u0435 \u0434\u043e\u043b\u0436\u043d\u044b \u0432\u0437\u0430\u0438\u043c\u043e\u0434\u0435\u0439\u0441\u0442\u0432\u043e\u0432\u0430\u0442\u044c (\u0441\u043e\u0437\u0434\u0430\u0432\u0430\u0442\u044c \u043a\u043e\u043b\u043b\u0438\u0437\u0438\u0438)<\/p>\n\n\n\n<pre class=\"wp-block-code\"><code>from WEConf import WEConf as conf\nclass CollObject():\n# \u043e\u0441\u043d\u043e\u0432\u043d\u044b\u0435 \u041f\u041e\u041b\u042f (\u0421\u0412\u041e\u0419\u0421\u0422\u0412\u0410) \u043e\u0431\u044a\u0435\u043a\u0442\u0430 \u0434\u043b\u044f \u043a\u043e\u043b\u043b\u0438\u0437\u0438\u0439: \n# \u043a\u043e\u043e\u0440\u0434\u0438\u043d\u0430\u0442\u0430 \u043d\u0443\u043b\u044f \u043e\u0431\u044a\u0435\u043a\u0442\u0430 \u0438\n# \u0448\u0438\u0440\u0438\u043d\u0430(width) \u0441 \u0432\u044b\u0441\u043e\u0442\u043e\u0439(height)\n    x = 0\n    y = 0\n    h = 0\n    w = 0\n# \u0414\u0430\u043b\u044c\u0448\u0435 \u0438\u0434\u0443\u0442 \u041c\u0415\u0422\u041e\u0414\u042b \u043a\u043b\u0430\u0441\u0441\u0430\n\n    def collide(self, collObject): # \u043f\u0440\u043e\u0432\u0435\u0440\u043a\u0430 \u043a\u043e\u043b\u043b\u0438\u0437\u0438\u0438 \u0441 \u0434\u0440\u0443\u0433\u0438\u043c \u043e\u0431\u044a\u0435\u043a\u0442\u043e\u043c\n        return collObject.y + collObject.h > self.y and collObject.x + collObject.w > self.x and collObject.x &lt; self.x + collObject.w\n    \n    def getParams(self): # \u043f\u043e\u043b\u0443\u0447\u0435\u043d\u0438\u0435 \u043e\u0441\u043d\u043e\u0432\u043d\u044b\u0445 \u0421\u0412\u041e\u0419\u0421\u0422\u0412 \u043e\u0431\u044a\u0435\u043a\u0442\u0430 \u0432 \u0432\u0438\u0434\u0435 \u043a\u043e\u0440\u0442\u0435\u0436\u0430 ()\n        return (self.x, self.y, self.w, self.h)\n    \n    def checkRight(self): # \u043f\u0440\u043e\u0432\u0435\u0440\u043a\u0430 \u0441 \u043f\u0435\u0440\u0435\u0441\u0435\u0447\u0435\u043d\u0438\u0435\u043c \u044d\u043a\u0440\u0430\u043d\u0430 \u0441\u043f\u0440\u0430\u0432\u0430\n        return self.x &lt; conf.scWidth - self.w\n\n    def checkLeft(self):# \u043f\u0440\u043e\u0432\u0435\u0440\u043a\u0430 \u0441 \u043f\u0435\u0440\u0435\u0441\u0435\u0447\u0435\u043d\u0438\u0435\u043c \u044d\u043a\u0440\u0430\u043d\u0430 \u0441\u043b\u0435\u0432\u0430\n        return self.x > 0\n    \n    def checkBott(self):# \u043f\u0440\u043e\u0432\u0435\u0440\u043a\u0430 \u0441 \u043f\u0435\u0440\u0435\u0441\u0435\u0447\u0435\u043d\u0438\u0435\u043c \u044d\u043a\u0440\u0430\u043d\u0430 \u0441\u043d\u0438\u0437\u0443\n        return self.y > conf.scHeight<\/code><\/pre>\n\n\n\n<p>3. Player.py | Egg\u041a\u043b\u0430\u0441\u0441 \u0418\u0433\u0440\u043e\u043a\u0430<\/p>\n\n\n\n<pre class=\"wp-block-code\"><code>from CollObject import CollObject\nfrom WEConf import WEConf as conf\n\nclass Player(CollObject):\n    def __init__(self): # \u043a\u043e\u043d\u0441\u0442\u0440\u0443\u043a\u0442\u043e\u0440\n        self.w = 50\n        self.h = 50\n        self.x = conf.scWidth\/2 - self.w\/2\n        self.y = conf.scHeight - self.h\n        self.playerSpeed = 5\n\n    def moveLeft(self): # \u0434\u0432\u0438\u0436\u0435\u043d\u0438\u0435 \u0432\u043b\u0435\u0432\u043e\n        if self.checkLeft():\n            self.x -= self.playerSpeed\n            \n    def moveRight(self): # \u0434\u0432\u0438\u0436\u0435\u043d\u0438\u0435 \u0432\u043f\u0440\u0430\u0432\u043e\n        if self.checkRight():\n            self.x += self.playerSpeed<\/code><\/pre>\n\n\n\n<p>4. Egg.py | \u041a\u043b\u0430\u0441\u0441 &#171;\u042f\u0439\u0446\u0430&#187;<\/p>\n\n\n\n<pre class=\"wp-block-code\"><code>from CollObject import CollObject\nfrom WEConf import WEConf as conf\nimport random\n\nclass Egg(CollObject):\n    def __init__(self):\n        self.w = 30\n        self.h = 30\n        self.eggSpeed = 3\n\n    def move(self):\n        self.y += self.eggSpeed\n    \n    def spawn(self): # \u0440\u043e\u0436\u0434\u0435\u043d\u0438\u0435\/\u043f\u0435\u0440\u0435\u0440\u043e\u0436\u0434\u0435\u043d\u0438\u0435 \u043e\u0431\u044a\u0435\u043a\u0442\u0430\n        self.x = random.randint(0,conf.scWidth-self.w)\n        self.y = 0\n        self.eggSpeed += 0.1\n\n    def borderTouch(self):\n        if self.checkBott():\n            self.spawn()\n            return True\n\n<\/code><\/pre>\n\n\n\n<p>5. Counters.py | \u0424\u0430\u0439\u043b \u0441\u043e \u0441\u0447\u0451\u0442\u043e\u043c<\/p>\n\n\n\n<pre class=\"wp-block-code\"><code>class Counters: # \u043f\u0440\u043e\u0441\u0442\u043e \u043a\u043b\u0430\u0441\u0441, \u0434\u0435\u0440\u0436\u0430\u0449\u0438\u0439 \u043e\u0434\u043d\u043e \u043f\u043e\u043b\u0435(\u0441\u0432\u043e\u0439\u0441\u0442\u0432\u043e) \u0441\u043e \u0441\u0447\u0451\u0442\u043e\u043c. \n    score = 0<\/code><\/pre>\n\n\n\n<p>6. WEGame.py | \u0421\u0430\u043c\u044b\u0439 \u0431\u043e\u043b\u044c\u0448\u043e\u0439 \u0444\u0430\u0439\u043b &#8212; \u043a\u043e\u043d\u0442\u0440\u043e\u043b\u043b\u0435\u0440 \u0438\u0433\u0440\u044b(\u0441\u0430\u043c\u0430 \u0438\u0433\u0440\u0430), \u043a\u043e\u0442\u043e\u0440\u044b\u0439 \u043e\u0442\u0432\u0435\u0447\u0430\u0435\u0442 \u0437\u0430 \u0432\u0441\u0435 \u0441\u043e\u0431\u044b\u0442\u0438\u044f, \u043a\u043e\u0442\u043e\u0440\u044b\u0435 \u043f\u0440\u043e\u0438\u0441\u0445\u043e\u0434\u044f\u0442 \u0432 \u0418\u0433\u0440\u0435<\/p>\n\n\n\n<pre class=\"wp-block-code\"><code>import pygame\nfrom WEConf import WEConf as conf\nfrom Player import Player\nfrom Egg import Egg\nfrom Counters import Counters\n\nclass WEGame():\n    def __init__(self):\n        pygame.init()\n        self.clock = pygame.time.Clock()\n        self.screen = pygame.display.set_mode((conf.scWidth, conf.scHeight))\n        pygame.display.set_caption(\"\u0412\u043e\u043b\u043a \u0438 \u044f\u0439\u0446\u0430\")\n\n        self.font = pygame.font.SysFont(None,30)\n        self.counters = Counters()\n        self.player = Player()\n        self.egg = Egg()\n        self.egg.spawn()\n        self.isRunning = True\n\n    def updateScene(self):\n        self.screen.fill(conf.white)\n        pygame.draw.rect(self.screen, conf.black, self.player.getParams())\n        pygame.draw.ellipse(self.screen, conf.red, self.egg.getParams())\n        scoreText = self.font.render(\"\u0421\u0447\u0451\u0442: \" + str(self.counters.score), True, conf.black)\n        self.screen.blit(scoreText, (10,10) )\n        pygame.display.update()\n        self.clock.tick(conf.clock)\n\n    def run(self):\n        for event in pygame.event.get():\n            if event.type == pygame.QUIT or ( event.type == pygame.KEYDOWN and \n                                            event.key == pygame.K_ESCAPE ):\n                self.isRunning = False\n\n        keys = pygame.key.get_pressed()\n        if keys&#91;pygame.K_LEFT]:\n            self.player.moveLeft()\n\n        if keys&#91;pygame.K_RIGHT]:\n            self.player.moveRight()\n        \n        self.egg.move()\n\n        if self.player.collide(self.egg):\n            self.egg.spawn()\n            self.counters.score += 1\n        \n        if self.egg.borderTouch():\n            self.egg.spawn()\n            self.counters.score -= 1\n\n    def startRun(self):\n        while self.isRunning:\n            self.updateScene()\n            self.run()\n        pygame.quit()    \n<\/code><\/pre>\n\n\n\n<p>7. main.py | \u0422\u043e\u0447\u043a\u0430 \u0432\u0445\u043e\u0434\u0430 \u0432 \u0418\u0433\u0440\u0443 (\u0437\u0430\u043f\u0443\u0441\u043a\u0430\u0435\u043c\u044b\u0439 \u0444\u0430\u0439\u043b)<\/p>\n\n\n\n<pre class=\"wp-block-code\"><code>from WEGame import WEGame\n\nif __name__ == \"__main__\":\n    game = WEGame()\n    game.startRun()<\/code><\/pre>\n\n\n\n<p>\u0410\u0440\u0445\u0438\u0432 \u0441\u043e \u0432\u0441\u0435\u043c \u0444\u0430\u0439\u043b\u0430\u043c\u0438: <\/p>\n\n\n\n<div class=\"wp-block-file\"><a id=\"wp-block-file--media-baadf854-6449-46a3-be21-5402fd4765db\" href=\"https:\/\/avdeevk.ru\/wp-content\/uploads\/2026\/04\/WolfAndEggsGame.zip\">WolfAndEggsGame<\/a><a href=\"https:\/\/avdeevk.ru\/wp-content\/uploads\/2026\/04\/WolfAndEggsGame.zip\" class=\"wp-block-file__button wp-element-button\" download aria-describedby=\"wp-block-file--media-baadf854-6449-46a3-be21-5402fd4765db\">\u0421\u043a\u0430\u0447\u0430\u0442\u044c<\/a><\/div>\n","protected":false},"excerpt":{"rendered":"<p>\u0412 \u0438\u0433\u0440\u0435 7 \u0444\u0430\u0439\u043b\u043e\u0432: 2. CollObject.py | \u0424\u0430\u0439\u043b \u0434\u043b\u044f \u0410\u0431\u0441\u0442\u0440\u0430\u043a\u0442\u043d\u043e\u0433\u043e \u043a\u043b\u0430\u0441\u0441\u0430 Colladable Object, \u043a\u043e\u0442\u043e\u0440\u044b\u0439 \u0441\u043e\u0434\u0435\u0440\u0436\u0438\u0442 \u0432\u0441\u0435 \u041e\u0411\u0429\u0418\u0415 \u043c\u0435\u0442\u043e\u0434\u044b \u0434\u043b\u044f \u0432\u0441\u0435\u0445 \u0443\u0447\u0430\u0441\u0442\u043d\u0438\u043a\u043e\u0432 \u0438\u0433\u0440\u043e\u0432\u043e\u0433\u043e \u043f\u0440\u043e\u0446\u0435\u0441\u0441\u0430, \u043a\u043e\u0442\u043e\u0440\u044b\u0435 \u0434\u043e\u043b\u0436\u043d\u044b \u0432\u0437\u0430\u0438\u043c\u043e\u0434\u0435\u0439\u0441\u0442\u0432\u043e\u0432\u0430\u0442\u044c (\u0441\u043e\u0437\u0434\u0430\u0432\u0430\u0442\u044c \u043a\u043e\u043b\u043b\u0438\u0437\u0438\u0438) 3. Player.py | Egg\u041a\u043b\u0430\u0441\u0441 \u0418\u0433\u0440\u043e\u043a\u0430 4. Egg.py | \u041a\u043b\u0430\u0441\u0441 &#171;\u042f\u0439\u0446\u0430&#187; 5. Counters.py | \u0424\u0430\u0439\u043b \u0441\u043e \u0441\u0447\u0451\u0442\u043e\u043c 6. WEGame.py | \u0421\u0430\u043c\u044b\u0439 \u0431\u043e\u043b\u044c\u0448\u043e\u0439 \u0444\u0430\u0439\u043b &#8212; \u043a\u043e\u043d\u0442\u0440\u043e\u043b\u043b\u0435\u0440 \u0438\u0433\u0440\u044b(\u0441\u0430\u043c\u0430 \u0438\u0433\u0440\u0430), \u043a\u043e\u0442\u043e\u0440\u044b\u0439<\/p>\n","protected":false},"author":1,"featured_media":0,"comment_status":"open","ping_status":"open","sticky":false,"template":"","format":"standard","meta":{"ngg_post_thumbnail":0,"footnotes":""},"categories":[30,31,12],"tags":[],"class_list":["post-827","post","type-post","status-publish","format-standard","hentry","category-topit","category-topit-tuts","category-tuts"],"_links":{"self":[{"href":"https:\/\/avdeevk.ru\/index.php\/wp-json\/wp\/v2\/posts\/827","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/avdeevk.ru\/index.php\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/avdeevk.ru\/index.php\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/avdeevk.ru\/index.php\/wp-json\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"https:\/\/avdeevk.ru\/index.php\/wp-json\/wp\/v2\/comments?post=827"}],"version-history":[{"count":3,"href":"https:\/\/avdeevk.ru\/index.php\/wp-json\/wp\/v2\/posts\/827\/revisions"}],"predecessor-version":[{"id":832,"href":"https:\/\/avdeevk.ru\/index.php\/wp-json\/wp\/v2\/posts\/827\/revisions\/832"}],"wp:attachment":[{"href":"https:\/\/avdeevk.ru\/index.php\/wp-json\/wp\/v2\/media?parent=827"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/avdeevk.ru\/index.php\/wp-json\/wp\/v2\/categories?post=827"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/avdeevk.ru\/index.php\/wp-json\/wp\/v2\/tags?post=827"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}