当前位置: 首页>>代码示例>>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;未经允许,请勿转载。