Exemple #1
0
 def test_snake_eat_grow(self):
     snake1 = gameobject.Snake()
     self.assertEqual(snake1.points, 0)
     self.assertEqual(snake1.length, gameobject.Snake.SNAKE_START_LENGTH)
     
     snake1.eat(gameobject.Fruit(gameobject.Location(1,1), 5))
     self.assertEqual(snake1.points, 5)
     self.assertEqual(snake1.length, gameobject.Snake.SNAKE_START_LENGTH + 1)
Exemple #2
0
 def test_lof_filterfruit(self):
     lof1 = gameobject.ListOfFruit()
     snake1 = gameobject.Snake()
     fruit1 = gameobject.Fruit(gameobject.Location(1, 1), 5)
     
     lof1.addfruit(fruit1)
     self.assertEqual(len(lof1.fruits), 1)
     
     snake1.eat(fruit1)
     self.assertEqual(len(lof1.fruits), 1)
     
     lof1.filterfruit()
     self.assertEqual(len(lof1.fruits), 0)
Exemple #3
0
    for body in range(1, len(snake.snake_body)):
        if h_box.hitbox_object_object(snake.snake_body[body].location.x, snake.snake_body[0].location.x, HIT_BOX_RANGE-2) and h_box.hitbox_object_object(snake.snake_body[body].location.y, snake.snake_body[0].location.y, HIT_BOX_RANGE-2):
            gameLoop = start()
    
    for fruit in lof.fruits:
        if h_box.hitbox_object_object(fruit.location.x, snake.snake_body[0].location.x, HIT_BOX_RANGE) and h_box.hitbox_object_object(fruit.location.y, snake.snake_body[0].location.y, HIT_BOX_RANGE):
            snake.eat(fruit)
            fruit.getate = True
        
    for bomb in lob.bombs:
        if h_box.hitbox_object_object(bomb.location.x, snake.snake_body[0].location.x, HIT_BOX_RANGE) and h_box.hitbox_object_object(bomb.location.y, snake.snake_body[0].location.y, HIT_BOX_RANGE):
            snake.eat(bomb)                    
            bomb.getactivated = True
    
    if len(lof.fruits) == 0:
      lof.fruits.append(gameobject.Fruit(FRUIT_POINTS[random.randint(0, 4)], gameobject.Location(random.uniform(20, SCREEN_WIDTH-20), random.uniform(50, SCREEN_HEIGHT-20))))
      
    if len(lob.bombs) == 0:
      lob.bombs.append(gameobject.Bomb(gameobject.Location(random.randrange(20, SCREEN_WIDTH-20), random.randrange(50, SCREEN_HEIGHT-20))))

    # Move the snake and its body location
    snake.move()
        
    # Remove the fruit or bomb that get ate by the snake
    lof.filterfruit()
    lob.filterbomb()
    
    # Keep refresh the game since some event might occur
    g = game.Game(snake, lof, lob)
    
    message_to_screen("Score: " + str(snake.points), SCORE_DISPLAY_LOCATION,(0, 0, 0), False)
Exemple #4
0
 def test_lof_addfruit(self):
     lof1 = gameobject.ListOfFruit()
     self.assertEqual(len(lof1.fruits), 0)
     
     lof1.addfruit(gameobject.Fruit(gameobject.Location(1, 1), 5))
     self.assertEqual(len(lof1.fruits), 1)
Exemple #5
0
 def test_fruit_snake_eat(self):
     fruit1 = gameobject.Fruit(gameobject.Location(1, 1), 3)
     snake1 = gameobject.Snake()
     self.assertEqual(fruit1.getate, False)
     snake1.eat(fruit1)
     self.assertEqual(fruit1.getate, True)
Exemple #6
0
 def test_fruit_init(self):
     fruit1 = gameobject.Fruit(gameobject.Location(1, 1), 2)
     self.assertEqual(fruit1.location, gameobject.Location(1, 1))
     self.assertEqual(fruit1.points, 2)