示例#1
0
    def test_remove_animal(self):
        jungle = Jungle()
        dog = Predator(power=10, speed=70)

        jungle.add_animal(dog)
        self.assertDictEqual(jungle.animals, {dog.id: dog})

        jungle.remove_animal(dog)
        self.assertDictEqual(jungle.animals, {})
示例#2
0
    def test_jungle_is_iterable(self):
        jungle = Jungle()
        animals = [Predator(power=10, speed=70), Predator(power=5, speed=40)]
        for animal in animals:
            jungle.add_animal(animal)

        try:
            animals_from_jungle = [a for a in jungle]
            self.assertEqual(animals, animals_from_jungle)
        except TypeError:
            self.assertTrue(False, "Jungle is not iterable")
示例#3
0
文件: main.py 项目: benjhatch/Snake
from jungle import Jungle
import pygame as pg
import time

run = True
timeLimit = int(input("Enter snake speed (try 100): "))
keyHit = False

#change me...use wasd for first snake
#rows, cols, size, number of snakes, length of snakes, number of apples, number added on contact with apple
jungle = Jungle()
pg.init()

while run:
    jungle.screen.fill((0, 0, 0))
    for event in pg.event.get():
        if event.type == pg.QUIT:
            run = False
        if event.type == pg.KEYDOWN and event.key in jungle.keys:
            tuple = jungle.keys[event.key]
            snake = jungle.snakes[tuple[0]]
            snake.changeDir(tuple[1])
    jungle.moveSnakes()
    pg.display.update()
    time.sleep(timeLimit / 5000)
示例#4
0
 def setUp(self):
     self.jungle = Jungle()