class Test(unittest.TestCase):


    def setUp(self):
        #self.sphere1 = SphericalBody(123,80,False, Player("Bazibaz"))
        #self.sphere2 = SphericalBody(123,80,True, Player("Bazibaz"))
        
        self.star = Star(123,34)
        
        self.planet1 = Planet(60,45,12,self.star)
        self.planet2 = Planet(60,45,12,self.star,self.planet1,Player("Bazibaz"))
        
    def test_addPlnt(self):
        self.star.addPlanet(self.planet1)
        self.assertEqual(self.star._planets[0], self.planet1)
 def setUp(self):
     #self.sphere1 = SphericalBody(123,80,False, Player("Bazibaz"))
     #self.sphere2 = SphericalBody(123,80,True, Player("Bazibaz"))
     
     self.star = Star(123,34)
     
     self.planet1 = Planet(60,45,12,self.star)
     self.planet2 = Planet(60,45,12,self.star,self.planet1,Player("Bazibaz"))
Example #3
0
def _prepareGame():
    '''
        Sets up the environment of the game
    '''
    global all_stars, all_planets, gamePanel, updateGUI
    #Initialize graphics
    max_loop = 0
    while(len(all_stars)< NUMBER_OF_STARS):
        new_star_pos = Point3()
        if (len(all_stars)==0):
            new_star_pos = Point3(0,0,0)
        else:
            new_star_pos= Point3((random.random()-0.5)*UNIVERSE_SCALE,
                                 (random.random()-0.5)*UNIVERSE_SCALE, 0)
        # Given that the star is separated enough from its neighboring stars
        # we can add it to the solar system  
        if _isSeparated(all_stars, new_star_pos, DEEP_SPACE_DISTANCE):
            star = Star(position = new_star_pos, radius = MAX_DEAD_STAR_RADIUS)
            #Add observer to star model
            star.attachObserver(updateGUI)
            all_stars.append(star)
            # Add planets to star
            prev_p = None
            radius = MAX_SOLAR_SYSTEM_RADIUS/MAX_NUMBER_OF_PLANETS
            while(star.getNumberOfPlanets() < MAX_NUMBER_OF_PLANETS):
                i = star.getNumberOfPlanets()
                angle = math.pi*2*random.random()
                radius += MIN_DISTANCE_BETWEEN_PLANETS + 3*random.random()
                planet = Planet(radius, angle, MAX_DEAD_PLANET_RADIUS, star)
                planet.parent_star = star
                planet.prev_planet = prev_p
                prev_p = planet
                planet.max_orbital_velocity = math.pow(MAX_PLANET_VELOCITY - (float(i)/MAX_NUMBER_OF_PLANETS) * (MAX_PLANET_VELOCITY - MIN_PLANET_VELOCITY), 2)
                planet.spin_velocity = 70
                star.addPlanet(planet)
                all_planets.append(planet)
            
            for i, planet in enumerate(star.planets()):
                if i==0:
                    continue
                planet.prev_planet.next_planet = planet
                
                
        #Safety check so that we don't loop forever without knowing why
        max_loop = max_loop + 1
        if max_loop > 10*NUMBER_OF_STARS:
            raise Exception("Cannot add all stars based on the current parameters.")