本文整理汇总了Python中Engine.Engine类的典型用法代码示例。如果您正苦于以下问题:Python Engine类的具体用法?Python Engine怎么用?Python Engine使用的例子?那么恭喜您, 这里精选的类代码示例或许可以为您提供帮助。
在下文中一共展示了Engine类的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: __init__
def __init__(self):
import Driver.ConnectionListUpdater
import CommandEngine
Engine.__init__(self)
attributes = {
'roomMap' : {},
'roomList' : []
}
for key in attributes.keys():
self.attributes[key] = attributes[key]
self.addEventHandlerByNameWithAdjusters('Engine.EventHandlers.RoomEngine.PlayerLoginEventHandler', None)
self.addEventHandlerByNameWithAdjusters('Engine.EventHandlers.RoomEngine.PlayerLogoutEventHandler', None)
RoomEngine.instance = self
for subscriber in RoomEngine.subscribers:
self.addEventSubscriber(subscriber)
RoomEngine.subscribers = []
self.buildWorld()
Driver.ConnectionListUpdater.addEventSubscriber(self)
CommandEngine.addEventSubscriber(self)
示例2: __init__
def __init__(self):
from Driver import LoginListener
import threading
import CommandEngine
Engine.__init__(self)
attributes = {
'openConnectionsSemaphore' : threading.BoundedSemaphore(3),
'newConnectionSemaphore' : threading.BoundedSemaphore(1),
'closedConnectionSemaphore' : threading.BoundedSemaphore(1),
'connectionList' : [],
'newConnections' : [],
'closedConnections' : []
}
for key in attributes.keys():
self.attributes[key] = attributes[key]
self.addEventHandlerByNameWithAdjusters('Engine.EventHandlers.ConnectionEngine.PlayerLoginHandler', None)
self.addEventHandlerByNameWithAdjusters('Engine.EventHandlers.ConnectionEngine.PlayerLogoutHandler', None)
ConnectionEngine.instance = self
LoginListener.addEventSubscriber(self)
CommandEngine.addEventSubscriber(self)
示例3: __init__
def __init__(self, btcTrader, apiName, authId, authPass):
Engine.__init__(self, apiName, btcTrader, 1) # refresh rate of 1 second. In the futur with the websockets we will probably put 0 and use some kind of select
self.req = self.CreateRequester(authId, authPass)
self.depth = {}
self.clock = Clock()
self.first = 1
self.account = Account()
示例4: __init__
def __init__(self):
Engine.__init__(self)
import CommandEngine
import threading
import Driver.ConnectionListUpdater
attributes = {
'playerSetSemaphore' : threading.BoundedSemaphore(1),
'playerMap' : {},
'playerList' : [],
'npcMap' : {}
}
for key in attributes.keys():
self.attributes[key] = attributes[key]
ActorEngine.instance = self
self.addEventHandlerByNameWithAdjusters('Engine.EventHandlers.ActorEngine.PlayerLoginEventHandler', None)
self.addEventHandlerByNameWithAdjusters('Engine.EventHandlers.ActorEngine.PlayerLogoutEventHandler', None)
self.addEventHandlerByNameWithAdjusters('Engine.EventHandlers.ActorEngine.BroadcastEventHandler', None)
for subscriber in ActorEngine.subscribers:
self.addEventSubscriber(subscriber)
ActorEngine.subscribers = []
Driver.ConnectionListUpdater.addEventSubscriber(self)
CommandEngine.addEventSubscriber(self)
示例5: __init__
def __init__(self):
import Driver.UpdateDriver
import ActorEngine
Engine.__init__(self)
attributes = {
'commandList' : {},
'emoteList': []
}
for key in attributes.keys():
self.attributes[key] = attributes[key]
self.addEventHandlerByNameWithAdjusters('Engine.EventHandlers.CommandEngine.CommandExecutionEventHandler', None)
CommandEngine.instance = self
for subscriber in CommandEngine.subscribers:
self.addEventSubscriber(subscriber)
CommandEngine.subscribers = []
self.buildCommandList()
Driver.UpdateDriver.addEventSubscriber(self)
ActorEngine.addEventSubscriber(self)
示例6: __init__
class Program:
"""
General program template
- init function for program component initialization
- main loop
* check events -> handle (event)
* update
"""
def __init__(self):
"""
init function
"""
self.interface = Interface()
self.engine = Engine()
self.run()
def run(self):
"""
main loop
"""
while True:
self.check_events()
self.update()
def check_events(self):
"""
pygame event handling (edit this for more events)
"""
for event in pygame.event.get():
if event.type == pygame.QUIT:
pygame.quit()
sys.exit()
if event.type == pygame.MOUSEBUTTONDOWN:
mousex, mousey = event.pos
response = self.interface.click(mousex,mousey)
self.handle(response)
def handle(self,response):
"""
handle responses to events
"""
self.engine.send(response)
def update(self):
"""
update state of program components
"""
self.engine.update()
self.interface.update(self.engine.get_updates())
示例7: main
def main(arguments):
if len(arguments) > 4:
print "Sorry, there were too many arguments."
print "You only need to include the number of rows, columns and the required length to win."
print "In that order."
return 0
elif len(arguments) < 4:
print "Sorry, there were not enough arguments"
print "You need to include number of rows, columns and the required length to win the game."
print "In that order."
return 0
try:
num_rows = int(arguments[1])
num_cols = int(arguments[2])
length_to_win = int(arguments[3])
except ValueError:
print "Please input only numbers"
return 0
print "Welcome to Connect 4 in python!"
load_or_save = str(raw_input("Would you like to continue your old game? Yes or no? :"))
if load_or_save.lower() == 'yes':
board = Board(0,0)
board.load_board()
else:
board = Board(num_rows, num_cols)
board.create_board()
engine = Engine(num_rows, num_cols, length_to_win, board)
board.print_board()
while(1):
try:
player_number = int(raw_input("Enter the number of players: "))
if player_number < 1:
print "Please use a number larger than 0!"
else:
break
except ValueError:
print "Please use a number!"
print "If at any time you would like to save your game, simply type save."
while (True):
for player in range(player_number):
column = -1
input = raw_input("Pick a column for your token player %d: " % (player))
if input.lower() == 'save':
board.save_board()
print "Your game has been saved."
return 0
break
try:
column = int(input)
print engine.place_token(column, player)
except ValueError:
print "You didn't save or use an acceptable number. You're turn is over."
board.print_board()
if engine.winner() != -1:
print "Congratulations player %d!!\nYou won conncect 4!" %(player)
return 0
示例8: restart
def restart(self):
"""Restart the game."""
if not self.restartRequested:
self.restartRequested = True
self.input.broadcastSystemEvent("restartRequested")
else:
# evilynux - With self.audio.close(), calling self.quit() results in
# a crash. Calling the parent directly as a workaround.
Engine.quit(self)
示例9: __init__
def __init__(self, btcTrader):
Engine.__init__(self, "Interface", btcTrader, 0.0333333) # 1/30 --> 30 frame per seconds
self.currentConsole = 0
self.commandLine = ""
self.cursorPosition = 0
self.printset = set(string.printable)
self.PushMsg("Hola !")
self.PushMsg("PageUp / PageDown to change of market.")
self.PushMsg("Type help to see the list of available commands.")
示例10: mainfunc
def mainfunc():
"""The entry point. Note, if you want dont want argument parsing, feel free to directly use Engine class"""
engine = None
skippass2 = False
datadumpdirectory = None
indexgit = None
customindexfile = None
indexentries = None
testentries = None
indexgitbranch = "master"
cmdargs = initparser().parse_args()
# Set up the parameters to Engine, based on argument parsing.
if cmdargs.indexgiturl is not None and cmdargs.customindexfile is not None:
Logger().log(Logger.error,
"indexgiturl and customindexfile are mutually exclusive. So please specify either one")
exit(5)
if cmdargs.indexgiturl is not None:
indexgit = cmdargs.indexgiturl[0]
if cmdargs.indexgitbranch is not None:
indexgitbranch = cmdargs.indexgitbranch[0]
if cmdargs.customindexfile is not None:
customindexfile = cmdargs.customindexfile[0]
if cmdargs.skippass2 is not None:
skippass2 = cmdargs.skippass2
if cmdargs.datadumpdirectory is not None:
datadumpdirectory = cmdargs.datadumpdirectory[0]
if cmdargs.indexentry is not None:
indexentries = []
for item in cmdargs.indexentry:
indexentries.append(int(item[0]))
if cmdargs.testentry is not None:
testentries = cmdargs.testentry
engine = Engine(datadumpdirectory=datadumpdirectory, indexgit=indexgit, customindexfile=customindexfile,
skippass2=skippass2, specificindexentries=indexentries, testindexentries=testentries,
indexgitbranch=indexgitbranch)
status = engine.run()
if not status:
exit(1)
return
示例11: ResourceTest
class ResourceTest(unittest.TestCase):
def testAsynchLoad(self):
self.r = Resource()
self.e.addTask(self.r, synchronized = False)
self.r.load(self, "result", lambda: loader())
while not self.result:
self.e.run()
assert self.result == 0xdada
def testSynchLoad(self):
self.r = Resource()
self.e.addTask(self.r, synchronized = False)
assert self.r.load(self, "result2", loader, synch = True) == 0xdada
assert self.result2 == 0xdada
def testAsynchLoadSeries(self):
self.r = Resource()
self.e.addTask(self.r, synchronized = False)
for i in range(10):
self.r.load(self, "result%d" % i, loader)
while not self.result9:
self.e.run()
assert self.result9 == 0xdada
def testCallback(self):
self.r = Resource()
self.e.addTask(self.r, synchronized = False)
self.quux = None
def loaded(r):
self.quux = r
self.r.load(self, "fuuba", loader, onLoad = loaded).join()
while not self.fuuba:
self.e.run()
assert self.fuuba == self.quux
def setUp(self):
Config.load(Version.appName() + ".ini", setAsDefault = True)
# Resource expects game_priority to be an integer,
# Config won't know unless we define it as such.
Config.define("performance", "game_priority", int, 2)
self.e = Engine()
def tearDown(self):
self.e.quit()
示例12: main
def main():
masterTbl = MasterTbl()
engine = Engine()
projectDir = sys.argv[1]
del sys.argv[0:2]
execDir, execName = engine.split_cmdname(sys.argv[0])
return engine.execute(projectDir, execDir, execName)
示例13: ResourceTest
class ResourceTest(unittest.TestCase):
def testAsynchLoad(self):
self.r = Resource()
self.e.addTask(self.r, synchronized = False)
self.r.load(self, "result", lambda: loader())
while not self.result:
self.e.run()
assert self.result == 0xdada
def testSynchLoad(self):
self.r = Resource()
self.e.addTask(self.r, synchronized = False)
assert self.r.load(self, "result2", loader, synch = True) == 0xdada
assert self.result2 == 0xdada
def testAsynchLoadSeries(self):
self.r = Resource()
self.e.addTask(self.r, synchronized = False)
for i in range(10):
self.r.load(self, "result%d" % i, loader)
while not self.result9:
self.e.run()
assert self.result9 == 0xdada
def testCallback(self):
self.r = Resource()
self.e.addTask(self.r, synchronized = False)
self.quux = None
def loaded(r):
self.quux = r
self.r.load(self, "fuuba", loader, onLoad = loaded).join()
while not self.fuuba:
self.e.run()
assert self.fuuba == self.quux
def setUp(self):
self.e = Engine()
def tearDown(self):
self.e.quit()
示例14: __init__
def __init__(self):
Engine.__init__(self)
attributes = {
'affects' : {},
'affectComponents' : {}
}
for key in attributes.keys():
self.attributes[key] = attributes[key]
AffectEngine.instance = self
self.buildAffectList()
self.buildAffectComponentList()
示例15: main
def main(args):
# try:
debug_mode = args.debug
firmware = args.inputfile
output = args.outputfile
logger = Logger(output, debug_mode)
processor = GenericAtmel8051Proc(_logger=logger)
logger.print_success("Processor '{:s}' has been created.".format(processor.desc))
engine = Engine(processor, _logger=logger)
engine.flash_rom(firmware)
logger.print_success("Firmware loaded in ROM.")
user_input = ""
while (user_input != "quit"):
user_input = logger.get_input("").rstrip()
execute_cmd(user_input, engine, logger)
logger.print_info("Terminating program...")