示例#1
0
def run(src_path=None):
    global pass_tests, fail_tests

    if src_path == None:
        import gamemodel
        import gamegraphics
    else:
        spec = importlib.util.spec_from_file_location(
            "gamemodel", src_path + "/gamemodel.py")
        gamemodel = importlib.util.module_from_spec(spec)
        spec.loader.exec_module(gamemodel)

        spec = importlib.util.spec_from_file_location(
            "gamegraphics", src_path + "/gamegraphics.py")
        gamegraphics = importlib.util.module_from_spec(spec)
        spec.loader.exec_module(gamegraphics)

    pass_tests = 0
    fail_tests = 0
    fun_count = 0

    game = gamemodel.Game(10, 3)
    runTests(game)

    ggame = gamegraphics.GraphicGame(gamemodel.Game(10, 3))
    runTestsGraphics(ggame)

    print(
        str(pass_tests) + " out of " + str(pass_tests + fail_tests) +
        " passed.")

    return (fun_count == 0 and fail_tests == 0)
示例#2
0
def textPlay():
    game = gamemodel.Game(10, 3)
    while True:
        angle, vel = textInput(game)
        proj = textFire(game, angle, vel)
        textFinishShot(game, proj)
        print("<press enter to continue>")
        input()
        print('')  # Print an empty line
示例#3
0
    def Put(self, user):
        """Our handler for HTTP PUT requests - this creates a new game for the user.

       URL Path is ignored (but must start with /game_ajax)

       Post params include:
         email: <email address of opponent to invite>
         public: true (if anyone is allowed to view this game)
         game_type: <string identifying game type> 

       Response:
         JSON-encoded ID of the newly-created game
    """
        # Pull the params out of the request and set them in the model object

        player1 = users.GetCurrentUser()
        public = False
        if (self.request.get("public")
                and self.request.get("public").lower() == "true"):
            public = True
        invitee = self.request.get("email")
        status = gamemodel.GAME_STATUS_OPEN
        if invitee:
            status = gamemodel.GAME_STATUS_INVITED
        game_type = self.request.get("game_type")

        # Randomly generate the player's color if it's not supplied
        color = self.request.get("color")
        if color and color != "random":
            color = gamemodel.WHITE if color.lower(
            ) == "white" else gamemodel.BLACK
        else:
            color = random.getrandbits(1)

        newGame = gamemodel.Game(player1=player1,
                                 public=public,
                                 status=status,
                                 game_type=game_type,
                                 player1_color=color)
        if invitee:
            try:
                # See if we have a google user for this invitee
                newGame.player2 = users.User(invitee)
                if newGame.player2 == newGame.player1:
                    self.error(http.HTTP_ERROR)
                    self.response.out.write("Cannot invite yourself to a game")
                    return
            except UserNotFoundError:
                # This user hasn't signed up for an acct yet - just put them in
                # as an invitee
                newGame.invitee = invitee

        # Init the time remaining
        if game_type == gamemodel.GAME_TYPE_BLITZ_5:
            newGame.player1_time = newGame.player2_time = 5 * 60 * 1000
        elif game_type == gamemodel.GAME_TYPE_BLITZ_10:
            newGame.player1_time = newGame.player2_time = 10 * 60 * 1000

        newGame.put()

        # If it's an invitation to a game, send an email
        if status == gamemodel.GAME_STATUS_INVITED:
            subject = "Blitz invitation from %s" % user.nickname()
            lobby_url = self.request.uri
            lobby_url = lobby_url[:lobby_url.rindex("game_ajax")] + "lobby"
            if newGame.player1_time:
                game_name = "Blitz chess"
            else:
                game_name = "chess"
            invitation = """
%s has invited you to play a game of %s.

Visit %s to play!

- the Blitz chess server
      """ % (user.nickname(), game_name, lobby_url)
            mail.SendMail(GAME_SENDER, invitee, subject, invitation)

        # Return the ID to the user in json format
        self.response.set_status(http.HTTP_CREATED)
        self.response.headers['Content-Type'] = 'text/javascript'
        self.response.out.write('"%s"' % str(newGame.key()))
    # For these tests to work, you need to have a getWindow-method in GraphicGame
    w = ggame.getWindow()

    circ_type = type(graphics.Circle(graphics.Point(0,0), 10))
    rect_type = type(graphics.Rectangle(graphics.Point(0,0), graphics.Point(1,1)))

    everything = w.items
    circles = [x for x in w.items if type(x) == circ_type]
    rectangles = [x for x in w.items if type(x) == rect_type]

    assert len(circles) == 2, "there should be two circles drawn after running tests"
    assert len(rectangles) == 2, "there should be two rectangles initially"

    rect_pos = [x.getCenter().getX() for x in rectangles]
    assert -90 in rect_pos and 90 in rect_pos, "rectangles should be at x=-90 and x=90"

    # Fire a red projectile and move it a bit
    ggame.setCurrentWind(0)
    ggame.getCurrentPlayer().fire(30, 30).update(2)
    

    circles = [x for x in w.items if type(x) == circ_type]
    
    assert len(circles) <= 2, "there should never be more than two circles! You need to undraw old cannonballs"

runTests(gamemodel.Game(10,3))

ggame = gamegraphics.GraphicGame(gamemodel.Game(10, 3))
testGraphics(ggame)
示例#5
0
sysfontlarge = pygame.font.Font(font_file_name, 16)

# default font (title)
sysfonttitle = pygame.font.Font(font_file_name, 25)

# frame rate utility
clock = pygame.time.Clock()

# bunning drawer
burning_drawer = burner.BuriningDrawer()

# starry sky drawer
background = Background(infofont, sysfonttitle, sysfontlarge)

# game model
game = gamemodel.Game()

# player control
control = gamemodel.Control()

# field objects
fobjs = gamemodel.FieldObjects(game)

# player object
player = player_def.Player(game, control, fobjs)
fobjs.player = player

# information notify
info = InfoNotification(sysfont, sysfontlarge)

# # ----------------------------------------------------------------