Ejemplo n.º 1
0
    def setUp(self):
        # Here we will construct a Test World we can use to verify our systems
        # work well together.
        self.player = Player()
        self.g = Graphics()
        self.sim = Simulation()
        self.sun = SunMoon()

        # Build Test World
        self.worldmap = WorldMap(0, 0, 2, 2)
        self.worldmap.SetMapTile(0, 0,
                                 MapTile('00', 'ohoh', [MapTileTag.FOREST]))
        self.worldmap.SetMapTile(0, 1,
                                 MapTile('01', 'oh one', [MapTileTag.FOREST]))
        self.worldmap.SetMapTile(1, 0, MapTile('10', 'ten',
                                               [MapTileTag.FOREST]))
        self.worldmap.SetMapTile(1, 1,
                                 MapTile('11', 'eleven', [MapTileTag.FOREST]))

        self.worldmap.AddItemAt(0, 1, 'Test Item')

        # Create Test NPC
        self.worldmap.AddNPCAt(1, 0, 'roger')
        self.worldmap.AddNPCAt(1, 0, 'bob')

        self.game = MyGame(worldmap=self.worldmap,
                           sim=self.sim,
                           player1=self.player,
                           graphics=self.g,
                           sun=self.sun)
Ejemplo n.º 2
0
    def gameInfo(self, id):
        game = MyGame.get(id)
        t = Template(open(os.path.join(gametime.TMPL_DIR, "gameInfo.tmpl")).read())
        t.game = game

        for provider in GAME_PROVIDERS.values():
            t.__dict__[provider.site_id] = provider.get_one(game.get_provider_id(provider))
            
        return munge(t)
Ejemplo n.º 3
0
 def addGame(self, title, system, info_id, site_id):
     game = MyGame()
     game.title = title
     game.system = providers.normalize_system(system)
     if site_id in GAME_PROVIDERS:
         provider = GAME_PROVIDERS[site_id]
         game.set_provider_id(provider, info_id)
         game.insert_in_db()
         self.updateInfo(game.id, site_id, info_id, False)
     raise cherrypy.HTTPRedirect("/#Game_{0}".format(game.id))
Ejemplo n.º 4
0
class MyGameTest(unittest.TestCase):
    def setUp(self):
        # Here we will construct a Test World we can use to verify our systems
        # work well together.
        self.player = Player()
        self.g = Graphics()
        self.sim = Simulation()
        self.sun = SunMoon()

        # Build Test World
        self.worldmap = WorldMap(0, 0, 2, 2)
        self.worldmap.SetMapTile(0, 0,
                                 MapTile('00', 'ohoh', [MapTileTag.FOREST]))
        self.worldmap.SetMapTile(0, 1,
                                 MapTile('01', 'oh one', [MapTileTag.FOREST]))
        self.worldmap.SetMapTile(1, 0, MapTile('10', 'ten',
                                               [MapTileTag.FOREST]))
        self.worldmap.SetMapTile(1, 1,
                                 MapTile('11', 'eleven', [MapTileTag.FOREST]))

        self.worldmap.AddItemAt(0, 1, 'Test Item')

        # Create Test NPC
        self.worldmap.AddNPCAt(1, 0, 'roger')
        self.worldmap.AddNPCAt(1, 0, 'bob')

        self.game = MyGame(worldmap=self.worldmap,
                           sim=self.sim,
                           player1=self.player,
                           graphics=self.g,
                           sun=self.sun)

    def test_PlayerCanMove(self):
        # Player starts at 0,0
        self.assertEqual(self.player.position.x, 0)
        self.assertEqual(self.player.position.y, 0)
        # Simulate input command 'e'
        self.game.input_queue.append('e')
        # Move the game forward one step
        self.game.Step()
        # Verify player moved
        self.assertEqual(self.player.position.x, 1)
        self.assertEqual(self.player.position.y, 0)

    def test_NPCTests(self):
        """Tests for NPC Class."""
        self.assertIn('roger', self.worldmap.GetNPCDescriptions(1, 0))
        self.assertIn('bob', self.worldmap.GetNPCDescriptions(1, 0))
Ejemplo n.º 5
0
 def updateInfo(self, id, site_id, info_id=None, redirect=True):
     if site_id in GAME_PROVIDERS:
         provider = GAME_PROVIDERS[site_id]
         game = MyGame.get(id)
         if game:
             if not info_id:
                 info_id = provider.get_match(game.title, game.system)
             if info_id:
                 info = provider.get_info(game.id, info_id)
                 if info:
                     pprint(vars(info))
                     print ""
                     provider.insert_or_update_in_db(info)
                     game.set_provider_id(provider, info_id)
                     game.update_info(provider, info)
     if redirect:
         raise cherrypy.HTTPRedirect("/#Game_{0}".format(id))
Ejemplo n.º 6
0
 def updateGame(self, id, redirect=True):
     game = MyGame.get(id)
     for provider in GAME_PROVIDERS.values():
         self.updateInfo(id, provider.site_id, game.get_provider_id(provider), False)
     if redirect:
         raise cherrypy.HTTPRedirect("/#Game_{0}".format(id))
Ejemplo n.º 7
0
 def updateAllGames(self, redirect=True):
     ids = MyGame.get_all_ids()
     for id in ids:
         self.updateGame(id, False)
     if redirect:
         raise cherrypy.HTTPRedirect("/")
Ejemplo n.º 8
0
 def removeGame(self, id):
     MyGame.delete_from_db(id)
     raise cherrypy.HTTPRedirect("/")
Ejemplo n.º 9
0
 def index(self):
     t = Template(open(os.path.join(gametime.TMPL_DIR, "index.tmpl")).read())
     mygames = MyGame.get_all()
     mygames = sorted(mygames, key=lambda g: (g.my_date, g.title))
     t.mygames = mygames
     return munge(t)