本文整理汇总了Python中tp.server.model.Model类的典型用法代码示例。如果您正苦于以下问题:Python Model类的具体用法?Python Model怎么用?Python Model使用的例子?那么恭喜您, 这里精选的类代码示例或许可以为您提供帮助。
在下文中一共展示了Model类的20个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于我们的系统推荐出更棒的Python代码示例。
示例1: setUp
def setUp( self ):
Universe, StarSystem, Planet, Fleet = self.model.use( 'Universe', 'StarSystem', 'Planet', 'Fleet' )
universe = Universe(
name = "The Universe",
size = 10**8,
age = 0 )
system = StarSystem(
name = "The Star System",
parent = universe,
position = Vector3D( 0, 0, 0 ),
size = 10**4)
planet = Planet(
name = "The Planet",
parent = system,
position = Vector3D( system.position.x + 5,
system.position.y + 7 ),
size = 10**2,
owner = self.players[0] )
fleet = Fleet(
parent = planet,
size = 3,
name = "The Fleet",
ships = [],
damage = 0,
position = planet.position,
owner = self.players[0])
self.objects = [ universe, system, planet, fleet ]
Model.add( self.objects )
开发者ID:cahirwpz,项目名称:tpserver-py,代码行数:34,代码来源:objects.py
示例2: initModel
def initModel(self):
Ruleset.initModel(self)
universe = self.generator.createUniverse(name="The Universe")
ships = self.generator.createShipClasses()
Model.add(universe, ships)
开发者ID:cahirwpz,项目名称:tpserver-py,代码行数:7,代码来源:__init__.py
示例3: addPlayer
def addPlayer(self, username, password, email="N/A", comment=""):
"""
Create a player for this game.
The default function creates a new user, a board for the user and adds a
welcome message. It returns the newly created user object.
"""
Player, Board, Message = self.model.use("Player", "Board", "Message")
player = Player(username=username, password=password, email=email, comment=comment)
board = Board(
owner=player,
name="Private message board for %s" % username,
description="This board is used so that stuff you own (such as fleets and planets) can inform you of what is happening in the universe.",
)
board.messages.append(
Message(
subject="Welcome to the Universe!",
body="Welcome, %s, to the python Thousand Parsec server. Hope you have fun!"
"This game is currently playing version %s of %s." % (username, self.version, self.name),
turn=self.game.turn,
)
)
Model.add(player, board)
return player
开发者ID:cahirwpz,项目名称:tpserver-py,代码行数:29,代码来源:Ruleset.py
示例4: __call__
def __call__( self, request ):
Object = self.model.use( self.__object__ )
response = []
for id in request.ids:
obj = self.fetch( Object, id )
# WARNING: This is only for testing purposes!
Model.refresh( obj )
if obj:
if self.authorize( obj ):
response.append( self.process( request, obj ) )
else:
debug( "No permission for %s with id %s.", Object.__origname__, id )
response.append( self.Fail( request, "PermissionDenied", "You cannot access %s with id = %d." % ( Object.__origname__, id ) ) )
else:
debug( "No such %s with id %s.", Object.__origname__, id )
response.append( self.Fail( request, "NoSuchThing", "No %s with id = %d." % ( Object.__origname__, id ) ) )
if len( response ) > 1:
response.insert( 0, self.Sequence( request, len( response ) ) )
if not len( response ):
response.append( self.Fail( request, "Protocol", "List of IDs must be nonempty!" ) )
return response
开发者ID:cahirwpz,项目名称:tpserver-py,代码行数:28,代码来源:Common.py
示例5: tearDown
def tearDown( self ):
Category = self.model.use( 'Category' )
if Category.ById( self.cat.id ):
Model.remove( self.cat )
super( RemovePublicCategory, self ).tearDown()
开发者ID:cahirwpz,项目名称:tpserver-py,代码行数:7,代码来源:category.py
示例6: setUp
def setUp( self ):
Board = self.model.use( 'Board' )
board1 = Board(
owner = self.players[0],
name = "First message board for %s" % self.players[0].username,
description = "Board for testing purposes." )
board2 = Board(
owner = self.players[0],
name = "Second message board for %s" % self.players[0].username,
description = "Board for testing purposes." )
board3 = Board(
owner = self.players[1],
name = "Message board for %s" % self.players[1].username,
description = "Board for testing purposes." )
board4 = Board(
owner = None,
name = "Public message board.",
description = "Board for testing purposes." )
self.boards = [ board1, board2, board3, board4 ]
Model.add( self.boards )
开发者ID:cahirwpz,项目名称:tpserver-py,代码行数:26,代码来源:board.py
示例7: __call__
def __call__( self, request ):
Container = self.model.use( 'Board' )
container = Container.ById( request.id )
if container:
if self.authorize( container ):
slot = request.slot if request.slot < len( container.messages ) else -1
message = self.fromPacket( request )
if slot == -1:
container.messages.append( message )
else:
container.messages.insert( slot, message )
Model.add( container )
if slot == -1:
slot = len( container.messages )
response = self.Okay( request, "Message posted on %s with id = %d in slot %d." % ( Container.__origname__, request.id, slot ) )
else:
debug( "No permission for %s with id %s.", Container.__origname__, request.id )
response = self.Fail( request, "PermissionDenied", "You cannot access %s with id = %d." % ( Container.__origname__, request.id ) )
else:
debug( "No such %s with id %s.", Container.__origname__, request.id )
response = self.Fail( request, "NoSuchThing", "No %s with id = %d." % ( Container.__origname__, request.id ) )
return response
开发者ID:cahirwpz,项目名称:tpserver-py,代码行数:30,代码来源:Message.py
示例8: setUp
def setUp( self ):
Board, Message = self.model.use( 'Board', 'Message' )
board = Board(
owner = self.players[0],
name = "First message board for %s" % self.players[0].username,
description = "Board for testing purposes." )
board.messages.append(
Message(
subject = "First",
body = "Test message generated in first turn",
turn = 1 ))
board.messages.append(
Message(
subject = "Second",
body = "Test message generated in second turn",
turn = 2 ))
board.messages.append(
Message(
subject = "Third",
body = "Test message generated in third turn",
turn = 3 ))
self.board = board
Model.add( board )
开发者ID:cahirwpz,项目名称:tpserver-py,代码行数:29,代码来源:message.py
示例9: setUp
def setUp( self ):
Category = self.model.use( 'Category' )
self.cat = Category(
name = "Public",
description = "Public category for testing purposes." )
Model.add( self.cat )
开发者ID:cahirwpz,项目名称:tpserver-py,代码行数:8,代码来源:category.py
示例10: initModelConstants
def initModelConstants(self):
"""
This method initialises all data which is considered to be constant for
a ruleset lifetime.
"""
Model.create(self.model)
for loader in self.modelLoaders:
loader.initModelConstants()
开发者ID:cahirwpz,项目名称:tpserver-py,代码行数:9,代码来源:Ruleset.py
示例11: initialise
def initialise( self ):
Model.add( self.__game )
self.ruleset.loadModelConstants()
self.ruleset.initModelConstants()
self.ruleset.loadModel()
self.ruleset.initModel()
info( "Game '%s' initialised successfully.", self.name )
开发者ID:cahirwpz,项目名称:tpserver-py,代码行数:9,代码来源:gamemanager.py
示例12: __init__
def __init__( self ):
Model.init()
self.__game = {}
for gamedesc in GameDesc.query().all():
game = Game( gamedesc )
game.load()
self.__game[ game.name ] = game
开发者ID:cahirwpz,项目名称:tpserver-py,代码行数:10,代码来源:gamemanager.py
示例13: addResourcesToPlanet
def addResourcesToPlanet( self, planet ):
ResourceType = self.model.use( 'ResourceType' )
NaturalResourceTypes = [ ResourceType.ByName( name ) for name in [ 'Fruit Tree', 'Weird Artifact', 'Rock', 'Water' ] ]
# Add a random smattering of resources to planets...
for Type in self.random.sample( NaturalResourceTypes, self.randint(0, 4) ):
planet.resources[ Type ] = {
'accessible' : self.randint( 0, 10 ),
'extractable' : self.randint( 0, 100 ),
'inaccessible' : self.randint( 0, 1000 ) }
Model.update( planet )
开发者ID:cahirwpz,项目名称:tpserver-py,代码行数:13,代码来源:__init__.py
示例14: addPlayer
def addPlayer( self, username, password, email = 'Unknown', comment = 'A Minisec Player' ):
"""
Create a Solar System, Planet, and initial Fleet for the player, positioned randomly within the Universe.
"""
user, system, planet, fleet = MinisecRuleset.addPlayer( self, username, password, email, comment )
ResourceType = self.model.use( 'ResourceType' )
# Get the player's planet object and add the empire capital
planet.resources = {
ResourceType.ByName('House') : { 'accessible' : 1 },
ResourceType.ByName('Empire Capital') : { 'accessible' : 1 } }
Model.update( planet )
开发者ID:cahirwpz,项目名称:tpserver-py,代码行数:14,代码来源:__init__.py
示例15: initModel
def initModel(self):
"""
Initialise the database with anything needed for this game.
The ruleset should do things like,
- Create any components in the databases
- Create any resources in the databases
- etc
This should not add anything to the players universe. Use the populate
command for that.
This command takes no arguments, so it should not do anything which
needs information from the user.
"""
Model.create(self.model)
开发者ID:cahirwpz,项目名称:tpserver-py,代码行数:16,代码来源:Ruleset.py
示例16: __call__
def __call__( self, request ):
"""
Request: AddCategory :: Category
Response: Category | Fail
"""
category = self.fromPacket( request )
Category = self.model.use( 'Category' )
if Category.query().filter( and_( Category.name == category.name,
or_( Category.owner_id == self.player.id, Category.owner_id == None ))).count():
return self.Fail( request, "PermissionDenied",
"Category named %s already exists!" % category.name )
Model.add( category )
return self.toPacket( request, category )
开发者ID:cahirwpz,项目名称:tpserver-py,代码行数:17,代码来源:Category.py
示例17: populate
def populate(self, *args, **kwargs):
"""
Populate a universe with a number of systems and planets.
"""
Ruleset.populate(self, *args, **kwargs)
self.generator.initialise(*args)
Object = self.model.use("Object")
universe = Object.ByType("Universe")[0]
systems = self.generator.generateStarSystems(parent=universe)
for system in systems:
self.generator.generatePlanets(parent=system)
Model.update(universe)
开发者ID:cahirwpz,项目名称:tpserver-py,代码行数:18,代码来源:__init__.py
示例18: setUp
def setUp( self ):
ResourceType = self.model.use( 'ResourceType' )
hq = ResourceType(
id = 9,
name_singular = "Headquarters",
description = "The famous headquarters for a big trading conglomerate." )
credit = ResourceType(
id = 3,
name_singular = "Credit",
name_plural = "Credits",
description = "The root of all evil, money." )
uranium = ResourceType(
id = 7,
name_singular = "Uranium",
name_plural = "Uranium",
unit_singular = "kt",
unit_plural = "kt",
description = "A heavy metal used in weapons.",
weight = 1,
size = 1 )
weapon = ResourceType(
id = 4,
name_singular = "Weapon",
name_plural = "Weapons",
unit_singular = "part",
unit_plural = "parts",
description = "A ship component for destroying other ships.",
weight = 1,
size = 1 )
self.resources = [ hq, credit, uranium, weapon ]
Model.add( self.resources )
开发者ID:cahirwpz,项目名称:tpserver-py,代码行数:37,代码来源:resource.py
示例19: setUp
def setUp( self ):
if 'test_minisecplus' not in GameManager():
GameManager().addGame( 'test_minisecplus', 'Test Game (minisecplus)',
'minisecplus', '[email protected]', 'Test game used for testing purposes')
self.game = GameManager()[ 'test_minisecplus' ]
Player = self.model.use( 'Player' )
player1 = Player(
username = 'player1',
password = 'passwd1',
email = '[email protected]',
comment = 'Player used for testing purposes.' )
player2 = Player(
username = 'player2',
password = 'passwd2',
email = '[email protected]',
comment = 'Player used for testing purposes.' )
self.players = [ player1, player2 ]
Model.add( self.players )
开发者ID:cahirwpz,项目名称:tpserver-py,代码行数:24,代码来源:testenv.py
示例20: setUp
def setUp( self ):
Component, ComponentProperty = self.model.use( 'Component', 'ComponentProperty' )
Category, Property = self.model.use( 'Category', 'Property' )
misc = Category(
name = "Misc",
description = "Things which dont fit into any other category." )
ship = Category(
name = "Ship",
description = "Things which deal with ship's equipment." )
combat = Category(
name = "Combat",
description = "Things which deal with combat between ships." )
protection = Category(
name = "Protection",
description = "Things which deal with ship's protection." )
self.categories = [ misc, ship, combat, protection ]
speed = Property(
categories = [ ship ],
name = "speed",
display_name = "Speed",
description = "The maximum number of parsecs the ship can move each turn.",
calculate = """(lambda (design) 1.0)""" )
hp = Property(
categories = [ combat ],
name = "hp",
display_name = "Hit Points",
description = "The amount of damage the ship can take.",
calculate = """(lambda (design) 1.0)""" )
damage = Property(
categories = [ combat ],
name = "damage",
display_name = "Damage",
description = "The amount of damage that the ship will do when using its weapon.",
calculate = """(lambda (design) 1.0)""" )
escape = Property(
categories = [ ship ],
name = "escape",
display_name = "Escape Chance",
description = "The chance the ship has of escaping from battle.",
calculate = """(lambda (design) 1.0)""" )
self.properties = [ speed, hp, damage, escape ]
missile = Component(
id = 9,
name = "Missile",
description = "Missile which does 1HP of damage.",
categories = [ combat ],
properties = {
damage : """(lambda (design) 1.0)""",
speed : """(lambda (design) 1.0)""" })
laser = Component(
id = 1,
name = "Laser",
description = "Lasers which do 1HP of damage.",
categories = [ combat ],
properties = { damage : """(lambda (design) 1.0)""" })
armor_plate = Component(
id = 4,
name = "Armor Plate",
description = "Armor Plate which absorbes 1HP of damage.",
categories = [ ship, protection ] )
primary_engine = Component(
id = 7,
name = "Primary Engine",
description = "A part which allows a ship to move through space.",
categories = [ ship ],
properties = { speed : """(lambda (design) 1.0)""" })
self.components = [ missile, laser, armor_plate, primary_engine ]
Model.add( self.categories, self.properties, self.components )
开发者ID:cahirwpz,项目名称:tpserver-py,代码行数:84,代码来源:component.py
注:本文中的tp.server.model.Model类示例由纯净天空整理自Github/MSDocs等源码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。 |
请发表评论