当前位置: 首页>>代码示例>>Python>>正文


Python World.setup方法代码示例

本文整理汇总了Python中world.World.setup方法的典型用法代码示例。如果您正苦于以下问题:Python World.setup方法的具体用法?Python World.setup怎么用?Python World.setup使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在world.World的用法示例。


在下文中一共展示了World.setup方法的6个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。

示例1: ServerPregame

# 需要导入模块: from world import World [as 别名]
# 或者: from world.World import setup [as 别名]
class ServerPregame (Engine):
    """ Sets up the world and creates client identities then sends both to each
    client. Eventually allow for users to modify the initial world settings
    plus personalizations like name or color. """
    # Constructor {{{1
    def __init__ (self, loop, server):
        print 'S: Begin pregame.'
        Engine.__init__(self,loop)
        self.server = server

        self.world = World()

        self.conversations = []

    # Setup {{{1
    def setup (self):
        pipes = self.server.get_pipes()

        # Create identities for the World.
        human_identities = range(len(pipes))
        #ai_identities = self.create_ai_identities()
        #player_identities = human_identities + ai_identities
        target_identities = range(game_settings.target_count)

        print 'Human identites: ', human_identities

        # Create the world.
        self.world.setup(human_identities, target_identities)
        #self.world.setup(player_identities, target_identities)

        # Prepare to send info to the clients.
        for identity in human_identities:
            pipe = pipes[identity]
            setup_world = SetupWorld(self.world, identity)
            self.conversations.append(SimpleSend(pipe, setup_world))

        # Start the conversations.
        for conversation in self.conversations:
            conversation.start()

    # Update, Callbacks, and Methods {{{1
    def update(self, time):
        active_conversations = []
        for conversation in self.conversations:
            if not conversation.finished():
                active_conversations.append(conversation)
                conversation.update()
        if active_conversations: self.conversations = active_conversations
        else: self.exit_engine()

    def successor (self):
        pipes = self.server.get_pipes()
        forum = Forum(*pipes, safe=False)

        return ServerGame(self.loop, forum, self.world)

    def teardown(self):
        pass
开发者ID:alexmitchell,项目名称:PurplePeopleEater,代码行数:60,代码来源:engines.py

示例2: run

# 需要导入模块: from world import World [as 别名]
# 或者: from world.World import setup [as 别名]
def run():
    '''
    The main program loop. Manage the interface between the bot and the game
    engine.
    '''
    world = World()
    bot = Bot(world)
    # The following 2 calls are not conditional to RUNS_LOCALLY as they do
    # stuff either way...
    set_world_profiling(world)
    set_bot_profiling(bot)
    if RUNS_LOCALLY:
        import logging
        log = logging.getLogger('main')
        log.debug('# LOGGER STARTED')
        # the overlay works like the logging: the overlay.overlay object is
        # the Overlay() intantiation
        overlay.target_bot(bot)
    data = []
    while(True):
        try:
            current_line = sys.stdin.readline().strip().lower()
            if not current_line:
                continue  #skip empty lines
            if current_line == 'ready':
                world.setup(data)
                bot.do_setup()
                world.finish_turn()
                data = []
            elif current_line == 'go':
                world.update(data)
                bot.do_turn()
                world.finish_turn()
                data = []
            else:
                data.append(current_line)
        except EOFError as e:  # game is over or game engine has crashed
            print(e)
            break
        except KeyboardInterrupt:  # local user is stopping the game
            print('\nEXECUTION STOPPED BY USER\n')
        except:  # try to stay alive! [don't raise or exit]
            import traceback
            traceback.print_exc(file=sys.stderr)
            sys.stderr.flush()
        finally:
            if RUNS_LOCALLY:
                logging.shutdown()
开发者ID:quasipedia,项目名称:ants,代码行数:50,代码来源:MyBot.py

示例3: Game

# 需要导入模块: from world import World [as 别名]
# 或者: from world.World import setup [as 别名]
class Game(object):
    def __init__(self):
        self.clock = pygame.time.Clock()
        self.world = World()
        self.world.setup(4, 3, 64)
        self.player = Player()
        self.world.addPlayer(self.player)
        area = AreaTest(64, 64)
        area2 = AreaTest2(64, 64)
        area3 = AreaTest3(64, 64)
        self.world.addArea(area)
        self.world.addArea(area2)
        self.world.addArea(area3)
        self.world.loadStartArea(area)
        self.keyPressed = None
        
    def controls(self):
        self.keyPressed = pygame.key.get_pressed()
        for event in pygame.event.get():
            if event.type == QUIT:
                self.quitGame()
            elif event.type == KEYDOWN:
                if event.key == K_SPACE: #Action key
                    d = self.player.facingDirection
                    if not self.player.direction:
                        #return node that the player is facing towards
                        print self.player.mover.getNeighborNode(d)

    def readObjectText(self):
        pass
    
    def pause(self):
        pass
    
    def quitGame(self):
        '''Quit the game'''
        exit()
        
    def gameLoop(self):
        while True:
            dt = self.clock.tick(30) / 1000.0
            self.controls()
            self.world.update(dt, self.keyPressed)
            self.world.render()
            pygame.display.update()
开发者ID:jclarkrichards,项目名称:nodeMovement,代码行数:47,代码来源:game_run.py

示例4: World

# 需要导入模块: from world import World [as 别名]
# 或者: from world.World import setup [as 别名]
import pygame
from forceRegistry import ForceRegistry
from world import World
from entity import Entity

world = World()
world.setup(600, 400)

clock = pygame.time.Clock()

particle = Entity(40, 100)
particle.setSize(16,16)
particle.setMass(20)
particle.setVelocity(60,-100)

particle2 = Entity(440, 100)
particle2.setSize(32,32)
particle2.setMass(40)
particle2.setVelocity(-40,-100)

#Set a static floor object
floor = Entity(0,250)
floor.setSize(350, 60)
floor2 = Entity(550,200)
floor2.setSize(30,50)
floor3 = Entity(70,40)
floor3.setSize(50,20)
floor4 = Entity(100, 100)
floor4.setSize(100,10)
floor5 = Entity(0,200)
floor5.setSize(20,60)
开发者ID:jclarkrichards,项目名称:PhysicsEngine,代码行数:33,代码来源:run.py

示例5: World

# 需要导入模块: from world import World [as 别名]
# 或者: from world.World import setup [as 别名]
import sys

#Initialize our drawing engine which will draw our images on the screen:
import pygame
from pygame.locals import *
from globals import *

pygame.init()

#Import our other game files:
from world import World
from assets import sprites

world = World(background=sprites["grass"])
player = world.load_level("levels/lvl1.txt")
world.setup()

resolution = ((world.size[1]+1)*SPRITE_SIZE, (world.size[0]+1)*SPRITE_SIZE)
screen = pygame.display.set_mode(resolution)

while True:
    for event in pygame.event.get():
        if event.type == QUIT:
            pygame.quit()
            sys.exit()
        if event.type == KEYDOWN:
            if event.key == K_LEFT:
                player.move('l')
            elif event.key == K_RIGHT:
                player.move('r')
            elif event.key == K_UP:
开发者ID:cvanweelden,项目名称:MarbelousAdventure,代码行数:33,代码来源:game.py

示例6: World

# 需要导入模块: from world import World [as 别名]
# 或者: from world.World import setup [as 别名]
import pygame
from entity import Entity
from world import World
from areas import *

clock = pygame.time.Clock()

world = World()
world.setup(4, 3, 64)
player = Entity()
#player.setMoverMinDistance(world.tileSize)
world.addPlayer(player)

area = AreaTest(64, 64)
#area.divideIntoSubAreas(*world.screenSize)
area2 = AreaTest2(64, 64)
#area2.divideIntoSubAreas(*world.screenSize)
area3 = AreaTest3(64, 64)
world.addArea(area)
world.addArea(area2)
world.addArea(area3)
#for val in area.subAreas.keys():
#    print area.subAreas[val].entityOffset
#world.loadNewArea(area)

world.loadStartArea(area, 1)

while True:
    world.handleEvents()
    dt = clock.tick(30) / 1000.0
    world.update(dt)
开发者ID:jclarkrichards,项目名称:nodeMovement,代码行数:33,代码来源:run.py


注:本文中的world.World.setup方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。