def test_legs(self): ralph = Centipede() ralph.friends = ['Steve', 'Daniel', 'Guido'] ralph.favorite_show = "Monty Python's Flying Circus" ralph.age = '31' self.assertEqual(ralph.age, '31', "ralph doesn't know how old he is") self.assertEqual(ralph.__repr__(), 'friends,favorite_show,age')
def test_stomach(self): ralph = Centipede() ralph('chocolate') ralph('bbq') ralph('cookies') ralph('salad') self.assertEqual(ralph.__str__(), 'chocolate,bbq,cookies,salad')
def test_individuality(self): ralph = Centipede() self.assertEqual(ralph.__str__(), '') #new 'pede with empty stomach ralph('chocolate') ralph('bbq') mary = Centipede() #another 'pede with empty stomach self.assertEqual(mary.__str__(), '')
def __init__(self, showbase, usersData, gameData): self.showbase = showbase self.usersData = usersData self.gameData = gameData random.seed(self.gameData.randSeed) # Initialize the collision traverser. self.cTrav = CollisionTraverser() # Initialize the handler. self.collHandEvent = CollisionHandlerEvent() self.collHandEvent.addInPattern('into-%in') self.world = World(showbase) for user in self.usersData: user.centipede = Centipede(showbase, len(self.usersData), self.addToCollisions) if user.thisPlayer: self.centipede = user.centipede self.centipede.attachRing(showbase) self.foods = [] for i in range(self.gameData.maxFoods): self.foods.append(Food(self.showbase, i, self.addToCollisions)) self.ticks = 0
def __init__(self, showbase, usersData, gameData): DirectObject.__init__(self) self.showbase = showbase self.usersData = usersData self.gameData = gameData random.seed(self.gameData.randSeed) # Initialize the collision traverser. self.cTrav = CollisionTraverser() # Initialize the handler. self.collHandEvent = CollisionHandlerEvent() self.collHandEvent.addInPattern('into-%in') self.world = World(showbase) self.ambientLight = showbase.render.attachNewNode( AmbientLight("ambientLight")) # Set the color of the ambient light self.ambientLight.node().setColor((.1, .1, .1, 1)) # add the newly created light to the lightAttrib # showbase.render.setLight(self.ambientLight) self.spotlight = None numberOfPlayers = len(self.usersData) for index, user in enumerate(self.usersData): user.centipede = Centipede(showbase, index, numberOfPlayers, self.addToCollisions) if user.thisPlayer: self.centipede = user.centipede self.centipede.attachRing(showbase) self.spotlight = self.centipede.head.attachNewNode( PointLight("playerSpotlight")) self.spotlight.setPos(LVector3(0, 0, 8)) # Now we create a spotlight. Spotlights light objects in a given cone # They are good for simulating things like flashlights self.spotlight.node().setAttenuation( LVector3(.025, 0.0005, 0.0001)) self.spotlight.node().setColor((0.35, 0.35, .35, 1)) self.spotlight.node().setSpecularColor((0.01, 0.01, 0.01, 1)) showbase.render.setLight(self.spotlight) self.perPixelEnabled = True self.shadowsEnabled = True #if self.spotlight: # self.spotlight.node().setShadowCaster(True, 512, 512) showbase.render.setShaderAuto() self.foods = [] for i in range(self.gameData.maxFoods): self.foods.append(Food(self.showbase, i, self.addToCollisions))
newX = randrange(0, width) newY = randrange(0, height) mushroomList.append(Mushroom([newX,newY])) return mushroomList pygame.init() size = width, height = 800, 600 black = 0, 0, 0 screen = pygame.display.set_mode(size) pos = [300,400] imageLocation = "./images/shooter.png" Status = Enum('Status', 'win lose') shooter = Shooter(imageLocation, pos, width, height) centipede = Centipede([-1,0],[500,1], width, height, 13) allSpriteGroup = pygame.sprite.Group() allSpriteGroup.add(shooter) allSpriteGroup.add(centipede) # A group containing all of the lasers the Shooter shoots laserGroup = pygame.sprite.Group() # A group containing all mushrooms in the game mushroomGroup = pygame.sprite.Group() mushroomGroup.add(randomlyGenerateMushrooms(width, height)) # All the non player character sprites npcGroups = [laserGroup, centipede, mushroomGroup] while 1:
def test_protected(self): ralph = Centipede() self.assertRaises(AttributeError, setattr, ralph, "legs", []) self.assertRaises(AttributeError, setattr, ralph, "stomach", [])