예제 #1
0
    def eat(self):
        self.audio.food()

        self.eatedApples += 1

        if (self.eatedApples >= 10):
            self.nextLevel()
            self.isPause = True
            self.snake = Snake()
        else:
            self.snake.addBody()

        self.setApple()
예제 #2
0
    def restart(self):
        #clear variables
        self.isFail = False
        self.isPause = False
        self.isWin = False

        self.eatedApples = 0

        #first level
        self.curLevel = 1
        self.level = Level(self.curLevel)

        #restart game elements
        self.snake = Snake()
        self.setApple()

        #music controller
        self.audio = Audio()
예제 #3
0
    def __init__(self, curLevel=1):
        #game elements
        self.snake = Snake()
        self.level = Level(curLevel)
        self.setApple()

        self.curLevel = curLevel
        self.eatedApples = 0

        #player loose
        self.isFail = False

        #pause
        self.isPause = False

        #is win game
        self.isWin = False

        #music controller
        self.audio = Audio()
예제 #4
0
def create_host():
    game_name = ''.join(random.choice(string.ascii_uppercase + string.digits) for _ in range(5))
    game_name = "abvd"
    create_game(game_name)
    res, _ = HostScreen("Your host data", game_name, width, height).run(game_name)
    # вот здесь надо от юзеров получать змейки и кидать в массив
    # По идее, надо просто передать змейку хосту и там уже всё запускать
    snakes = [
        Snake(name, width=width, height=height)
        for name in get_game(game_name)["snakes"]
    ]
    for ind, snake in enumerate(snakes):
        body, direction = body_choice(ind, width, height)
        if body is not None and direction is not None:
            snake.body = body
            snake.head_pos = body[0]
            snake.direction = direction

    game = Game(snakes, width=width, height=height, speed=speed, host_addr=game_name)
    game.scores = [0 for i in game.scores]
    update_game_var(game_name, "state", game.to_dict())
    update_game_var(game_name, "status", PLAYING)
    play(host=game_name, player_name="HOST")