當前位置: 首頁>>代碼示例>>Python>>正文


Python Graphics.update方法代碼示例

本文整理匯總了Python中graphics.Graphics.update方法的典型用法代碼示例。如果您正苦於以下問題:Python Graphics.update方法的具體用法?Python Graphics.update怎麽用?Python Graphics.update使用的例子?那麽, 這裏精選的方法代碼示例或許可以為您提供幫助。您也可以進一步了解該方法所在graphics.Graphics的用法示例。


在下文中一共展示了Graphics.update方法的3個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的Python代碼示例。

示例1: __init__

# 需要導入模塊: from graphics import Graphics [as 別名]
# 或者: from graphics.Graphics import update [as 別名]
class Shapescape:
    # Initialize the boid view
    def __init__(self):
        self.win_width = 1024
        self.win_height = 768
        pygame.init()
        self.init_window()
        
        #title screen
        title_screen = TitleScreen(self.screen)
        title_screen.do_loop()

        self.game_loop()
        
        #gameover screen
        if globalvars.failed:
            gameover_screen = GameOver(self.screen, self.scoreboard)
            gameover_screen.do_loop()
    
    # Prepares the boid view
    def init_window(self): 
        # Initialize window
        self.screen = pygame.display.set_mode((self.win_width, self.win_height))
        pygame.display.set_caption('Shapescape')
        
        pygame.mouse.set_visible(1)
        
    # Continuesly renders the boid swarm
    def game_loop(self):
        clock = pygame.time.Clock()

        #Initialize
        self.scoreboard = Scoreboard()
        self.timer = CountDown()
        self.control = Control()
        self.graphics = Graphics(self.scoreboard, self.timer);
        self.player = Player(self.graphics)
        self.world = World(self.graphics, self.player) 
        self.logic = Logic(self.player, self.world, self.graphics, self.scoreboard, self.timer, self.control)
        
        while globalvars.run_game:
            delta = clock.tick(30) # fps

            # Catch input event
            for event in pygame.event.get():
                if event.type == QUIT:
                    return
                else:
                    self.control.update(event)
                
            # Update 
            self.logic.update(delta)
            self.world.update(delta)
            self.graphics.update(self.screen, delta)
            
            # Render
            self.graphics.draw(self.screen, delta);
            self.screen.blit(self.player.speedmsg, (0, 35))
            self.screen.blit(self.player.rotmsg, (0, 55))            
              
            pygame.display.flip()        
開發者ID:ivanvenosdel,項目名稱:colored-shapes,代碼行數:63,代碼來源:main.py

示例2: Game

# 需要導入模塊: from graphics import Graphics [as 別名]
# 或者: from graphics.Graphics import update [as 別名]
class Game(object):
    ''' Handles a game instance '''

    def __init__(self):
        ''' Initialize starting state'''
        self.graphics = Graphics()
        self.log = logging.getLogger("Game");
        logging.basicConfig(filename='main.log', level=DEBUG_LEVEL)
        self.log_handler = CursesHandler(self.graphics.windows["log"])
        self.log_handler.setLevel(DEBUG_LEVEL)
        self.log.addHandler(self.log_handler)
        self.commands = Commands(self)
        self.cursor_pos = [0,0]
        self.game_mode = GameModes.normal
        self.world = World(log_handler=self.log_handler)

        try:
            # Try to load a level from a text file and add it to the world
            # self.world.add_level(self.world.read_level('../data/testworld'))
            # self.world.get_current_level().add_entity(entity.creatures.SpaceOrk(5,5))
            self.world.add_level(
                    self.world.generate_level(
                        self.graphics.max_x, self.graphics.world_height))

            #Place player at spawn
            self.player = entity.creatures.Player(1,1)
            for ent in self.world.get_current_level().entities:
                if ent.__class__ == entity.world.PlayerSpawn:
                    self.player = entity.creatures.Player(ent.position[0],ent.position[1])

            self.world.get_current_level().add_entity(self.player)
        except Exception:
            # use better exception
            self.exit(1)

        self.log.debug("Game started")

    def run(self):
        ''' Draw the world and get input '''
        try:
            self.graphics.draw_world(self.world)
            self.graphics.show_stats(self.player)
            self.graphics.update()
            while True:
                self.parse_command(self.graphics.get_input())
                if self.game_mode == GameModes.cursor or self.game_mode == GameModes.look:
                    self.graphics.clear()
                    self.graphics.draw_world(self.world)
                    self.graphics.draw_cursor(self.cursor_pos)
                if self.game_mode == GameModes.look:
                    for ent in self.world.get_current_tile(self.cursor_pos):
                        self.log.info(ent.name)
                self.graphics.show_stats(self.player)
                self.graphics.update()
        except (Exception, KeyboardInterrupt):
            self.exit(1)

    def turn(self):
        ''' Take a turn; redraw world, run ai... '''
        try:
            for ent in self.world.get_current_level().entities:
                if hasattr(ent, "die"):
                    if ent.die():
                        continue
                if issubclass(ent.__class__, entity.base.Creature):
                    ent.turn(self.player)
            self.graphics.clear()
            self.graphics.draw_world(self.world)
        except (Exception, KeyboardInterrupt):
            self.exit(1)



    def exit(self, status):
        ''' Shutdown curses, close files, and print errors if any'''
        self.log.debug("exiting")
        self.graphics.exit()
        if sys.exc_info()[2] is not None:
            print(traceback.format_exc())
        sys.exit(status)


    def parse_command(self, command):
        ''' Executes the function associated with a command string '''
        self.log.debug(command)
        if hasattr(self.commands, command):
            try:
                self.commands.__class__.__dict__[command](self.commands)
            except (Exception, KeyboardInterrupt):
                self.exit(1)
        else:
            self.log.error("Command not found")
開發者ID:ottopasuuna,項目名稱:cyberogue,代碼行數:94,代碼來源:game.py

示例3: __init__

# 需要導入模塊: from graphics import Graphics [as 別名]
# 或者: from graphics.Graphics import update [as 別名]
class Game:
    '''
    A runner class to run one full full game.
    
    The Game class is customizable in the following ways:
    * maximumRounds - The absolute maximum number of rounds to be played in the game before a tie is declared, defaults to 250. A value of 0 means that there is no maximum number of rounds.
    * minimumRounds - The minimum number of rounds to be run when doing decay ending, defaults to 0.
    * decay - The probability of any given round taking place, defaults to 1.
    
    @note: A decay of .01 give an expected length of ~100 rounds. Decay calculations do not begin until after minimumRounds rounds have passed.
    '''

    maximumRounds = 0
    ''' The maximum number of rounds in the game. A value of 0 means there is no maximum number of rounds. '''
    
    decay = 1
    '''
    The decay rate of the game, i.e. the probability that the next round will take place.
    
    @note: A decay of .99 gives an expected length of ~100 rounds, which is a reasonable default value for a game.
    Decay calculations do not begin until after minimumRounds rounds have passed.
    '''
    
    minimumRounds = 0
    '''
    The minimum number of rounds in the game.
    
    @note: This is the number of rounds that are run before the decay logic is applied to determine the end of the game.
    '''
    
    numRounds = 0
    ''' The number of rounds so far. '''
    
    graphics = None
    '''
    The Graphics object used for displaying the game.
    
    If the value is None, then no graphics are displayed.
    '''
    
    synchronizeGraphics = False
    ''' Flag used to indicate whether the game update loop should synchronize with the graphics or not. '''
    
    board = None
    ''' The Board object for the game. '''
    
    gameOver = False
    ''' Flag indicating whether the game is done or not. '''
    
    scripts = None
    ''' Stash of scripts used for re-running the game. '''

    def __init__(self, scripts, useGraphics = False, synchronizeGraphics = False, maximumRounds = DEFAULT_MAXIMUM_ROUNDS, decay = 1, minimumRounds = 0):
        '''
        Constructor for Game class.
        
        @param scripts: A dict of robotBehavior objects keyed to the script's name.
        @param useGraphics: The Graphics object being used to render the graphics object. If graphics is None, no graphical display will be done.
        @param synchronizeGraphics: If graphics are being used, making this True will cause the game loop to update at the same rate as the graphics loop,
        rather than running as fast as it can. This is available for debugging purposes.
        @param maximumRounds: The maximum number of rounds in the game.
        @param decay: The decay rate of the game, i.e. the probability that the next round will take place.
        @param minimumRounds: The minimum number of rounds in the game.
        '''
        
        # ====================
        # INITIALIZE VARIABLES
        # ====================
        
        # initialize passed in variables
        self.maximumRounds = maximumRounds
        self.decay = decay
        self.minimumRounds = minimumRounds
        self.scripts = scripts
        
        # if graphics are being used, initialize graphics
        if useGraphics: 
            self.graphics = Graphics()
            self.synchronizeGraphics = synchronizeGraphics
        
    def run(self):
        '''
        Runs the game simulation and returns the winner.
        
        @return: A list containing the names of all the robots that survived the round.
        '''
        
        # reset important variables
        self.numRounds = 0
        self.gameOver = False
        self.board = Board(self.scripts)
        
        # ==============
        # START GRAPHICS
        # ==============
        
        # if graphics not None, start graphics runner
        if not (self.graphics is None):
            
            # give graphics object initial board state
#.........這裏部分代碼省略.........
開發者ID:CSSDePaul,項目名稱:Computerized-Robot-Arena-Program,代碼行數:103,代碼來源:game.py


注:本文中的graphics.Graphics.update方法示例由純淨天空整理自Github/MSDocs等開源代碼及文檔管理平台,相關代碼片段篩選自各路編程大神貢獻的開源項目,源碼版權歸原作者所有,傳播和使用請參考對應項目的License;未經允許,請勿轉載。