Esempio n. 1
0
 def test_snake_init(self):
     snake1 = gameobject.Snake()
     self.assertEqual(snake1.speed, gameobject.Snake.SNAKE_SPEED)
     self.assertEqual(snake1.life, gameobject.Snake.SNAKE_LIFE)
     self.assertEqual(snake1.length, gameobject.Snake.SNAKE_START_LENGTH)
     self.assertEqual(snake1.facing, gameobject.Direction.l)
     self.assertEqual(snake1.location, gameobject.Location(gameobject.Snake.SNAKE_START_X_LOCATION, gameobject.Snake.SNAKE_START_Y_LOCATION))
Esempio n. 2
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)
Esempio n. 3
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)
Esempio n. 4
0
 def test_lob_filterbomb(self):
     lob1 = gameobject.ListOfBomb()
     snake1 = gameobject.Snake()
     bomb1 = gameobject.Bomb(gameobject.Location(1, 1))
     
     lob1.addbomb(bomb1)
     self.assertEqual(len(lob1.bombs), 1)
     
     snake1.eat(bomb1)
     self.assertEqual(len(lob1.bombs), 1)
     
     lob1.filterbomb()
     self.assertEqual(len(lob1.bombs), 0)
Esempio n. 5
0
                if event.key == pygame.K_s:
                    return True
                if event.key == pygame.K_q:
                    return False
            if event.type == pygame.QUIT:
                return False
                    
        window.fill(BACKGROUND_COLOR)
        message_to_screen("Snake Game", [200, 150], (0, 0, 0), True)
        message_to_screen("Press S to start the Game, press Q to quit the Game", [50, 210], (0, 0, 0), True)
            
        pygame.display.update()
        clock.tick(5)

# Create all the game object
snake = gameobject.Snake(SCREEN_WIDTH/2, SCREEN_HEIGHT/2)
lof = gameobject.ListOfFruit()
lob = gameobject.ListOfBomb()
h_box = hitbox.hitbox()
g = game.Game(snake, lof, lob)
render_g = render.Render()

gameLoop = start()

while gameLoop:
    window.fill(BACKGROUND_COLOR)
    render_g.render_game(window, g)
    
    if snake.snake_body[0].location.x < 0 or snake.snake_body[0].location.y < 0 or snake.snake_body[0].location.x > SCREEN_WIDTH or snake.snake_body[0].location.y > SCREEN_HEIGHT:
        gameLoop = start()
        if gameLoop == True:
Esempio n. 6
0
 def test_bomb_snake_eat(self):
     bomb1 = gameobject.Bomb(gameobject.Location(2,2))
     snake1 = gameobject.Snake()
     self.assertEqual(bomb1.getactivated, False)
     snake1.eat(bomb1)
     self.assertEqual(bomb1.getactivated, True)
Esempio n. 7
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)
Esempio n. 8
0
 def test_snake_dead(self):
     snake1 = gameobject.Snake()
     self.assertFalse(snake1.dead())
     
     snake1.life = 0
     self.assertTrue(snake1.dead())
Esempio n. 9
0
 def test_snake_move(self):
     snake1 = gameobject.Snake()
     self.assertEqual(snake1.location.x, gameobject.Snake.SNAKE_START_X_LOCATION)
     snake1.move()
     self.assertEqual(snake1.location.x, gameobject.Snake.SNAKE_START_X_LOCATION - 1)