Esempio n. 1
0
    def run(self):
        rate = Rate(self.rate)

        self.model.set_all(self.BG_COLOR)
        self.model.set_pixel(self.HEAD[0], self.HEAD[1], self.PIXEL_COLOR)
        self.spawn_food(self.start_food)
        for x, y in self.FOOD_POSITIONS:
            self.model.set_pixel(x, y, self.FOOD_COLOR)

        while True:
            rate.sleep_dur = 1.0 / self.rate
            with self.model:
                self.process_events()
                new_pos = ((self.HEAD[0] + self.DIRECTION[0]) % self.height,
                           (self.HEAD[1] + self.DIRECTION[1]) % self.width)
                #check
                if new_pos in self.queue:
                    break

                self.HEAD = new_pos
                self.model.set_pixel(new_pos[0], new_pos[1], self.PIXEL_COLOR)
                self.queue.append(new_pos)

                if new_pos not in self.FOOD_POSITIONS:
                    x, y = self.queue.pop(0)
                    self.model.set_pixel(x, y, self.BG_COLOR)
                    self.process_extras(x, y)
                else:
                    del self.FOOD_POSITIONS[new_pos]
                    self.spawn_food(1)
                    self.rate += self.rate_increase
                    self.process_extras()
            rate.sleep()
        self.game_over()
        exit()
Esempio n. 2
0
    def run(self):
        rate = Rate(self.rate)

        self.model.set_all(self.BG_COLOR)
        self.model.set_pixel(self.HEAD[0],self.HEAD[1],self.PIXEL_COLOR)
        self.spawn_food(self.start_food)
        for x,y in self.FOOD_POSITIONS:
            self.model.set_pixel(x, y, self.FOOD_COLOR)

        while True:
            rate.sleep_dur=1.0/self.rate
            with self.model:
                self.process_events()
                new_pos=((self.HEAD[0]+self.DIRECTION[0])%self.height, (self.HEAD[1]+self.DIRECTION[1])%self.width)
                #check
                if new_pos in self.queue:
                    break


                self.HEAD=new_pos
                self.model.set_pixel(new_pos[0],new_pos[1],self.PIXEL_COLOR)
                self.queue.append(new_pos)

                if new_pos not in self.FOOD_POSITIONS:
                    x, y=self.queue.pop(0)
                    self.model.set_pixel(x, y, self.BG_COLOR)
                    self.process_extras(x, y)
                else:
                    del self.FOOD_POSITIONS[new_pos]
                    self.spawn_food(1)
                    self.rate+=self.rate_increase
                    self.process_extras()
            rate.sleep()
        self.game_over()
        exit()
Esempio n. 3
0
    def run(self):
        rate = Rate(self.rate)
        self.model.set_all(self.BG_COLOR)
        self.model.set_pixel(self.HEAD1[0],self.HEAD1[1],self.P1COLOR)
        self.model.set_pixel(self.HEAD2[0],self.HEAD2[1],self.P2COLOR)

        self.spawn_food(self.start_food)
        for x,y in self.FOOD_POSITIONS:
            self.model.set_pixel(x, y, self.FOOD_COLOR)

        while True:
            rate.sleep_dur=1.0/self.rate
            with self.model:
                self.process_events()
                new_pos=((self.HEAD1[0]+self.DIRECTION1[0])%self.height, (self.HEAD1[1]+self.DIRECTION1[1])%self.width)
                new_pos2=((self.HEAD2[0]+self.DIRECTION2[0])%self.height, (self.HEAD2[1]+self.DIRECTION2[1])%self.width)

                #check
                if new_pos in self.queue1 or new_pos in self.queue2:
                    gagnant="J2"
                    break

                if new_pos2 in self.queue2 or new_pos2 in self.queue1:
                    gagnant="J1"
                    break

                self.HEAD1=new_pos
                self.HEAD2=new_pos2

                self.model.set_pixel(new_pos[0],new_pos[1],self.P1COLOR)
                self.model.set_pixel(new_pos2[0],new_pos2[1],self.P2COLOR)

                self.queue1.append(new_pos)
                self.queue2.append(new_pos2)

                if new_pos not in self.FOOD_POSITIONS:
                    x, y=self.queue1.pop(0)
                    self.model.set_pixel(x, y, self.BG_COLOR)
                    self.process_extras(x, y)
                else:
                    del self.FOOD_POSITIONS[new_pos]
                    self.spawn_food(1)
                    self.rate+=self.rate_increase
                    self.process_extras()

                if new_pos2 not in self.FOOD_POSITIONS:
                    x, y=self.queue2.pop(0)
                    self.model.set_pixel(x, y, self.BG_COLOR)
                    self.process_extras(x, y)
                else:
                    del self.FOOD_POSITIONS[new_pos2]
                    self.spawn_food(1)
                    self.rate+=self.rate_increase
                    self.process_extras()
            rate.sleep()
        self.game_over(gagnant)
        exit()