本文整理汇总了Python中models.Game.put方法的典型用法代码示例。如果您正苦于以下问题:Python Game.put方法的具体用法?Python Game.put怎么用?Python Game.put使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类models.Game
的用法示例。
在下文中一共展示了Game.put方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: post
# 需要导入模块: from models import Game [as 别名]
# 或者: from models.Game import put [as 别名]
def post(self):
"""
CREATE a new Game entity
"""
self.record_usage()
namespace_manager.set_namespace(users.get_current_user().user_id())
param_map = {}
param_map['player_faction'] = self.request.get('player_faction')
param_map['player_warcaster'] = self.request.get('player_warcaster')
param_map['opponent_name'] = self.request.get('opponent_name', '')
param_map['opponent_faction'] = self.request.get('opponent_faction')
param_map['opponent_warcaster'] = self.request.get('opponent_warcaster')
param_map['result'] = self.request.get('result')
param_map['size'] = int(self.request.get('size', 0))
param_map['won'] = self.request.get('won') == 'true'
param_map['draw'] = self.request.get('draw') == 'true'
param_map['teaching'] = self.request.get('teaching') == 'true'
param_map['location'] = self.request.get('location', '')
param_map['game_type'] = self.request.get('game_type', '')
date = self.request.get('date')
try:
real_date = datetime.datetime.strptime(date,'%m/%d/%Y')
except (ValueError):
real_date = datetime.datetime.strptime(date,'%Y-%m-%d')
param_map['date'] = real_date
param_map['created_at'] = datetime.datetime.now()
logging.error(param_map)
game = Game(**param_map)
game.put()
self.response.out.write(game.key.urlsafe())
示例2: post
# 需要导入模块: from models import Game [as 别名]
# 或者: from models.Game import put [as 别名]
def post(self):
user = users.get_current_user()
if not user:
self.redirect(users.create_login_url("/"))
return
game_name = self.request.get("game_name")
if not game_name:
self.response.write("No game name specified")
return
game_key = db.Key.from_path("Game", game_name)
game = db.get(game_key)
if not game:
game = Game(key_name=game_name)
game.put()
logging.info("Game: {0}".format(game))
player = Player(user=user, parent=game)
player.put()
token = channel.create_channel("{0}:{1}".format(game_name, user.user_id()))
logging.info("/game?gamename={0}&token={1}".format(game.key().id_or_name(), token))
self.redirect("/game?gamename={0}&token={1}".format(game.key().id_or_name(), token))
示例3: get
# 需要导入模块: from models import Game [as 别名]
# 或者: from models.Game import put [as 别名]
def get( self ):
alias = self.request.get( 'alias' )
name = self.request.get( 'name' )
platforms = self.request.get( 'platforms' ).split( ',' )
category = self.request.get( 'category' )
download_link_linux = self.request.get( 'download_link_linux' )
download_link_osx = self.request.get( 'download_link_osx' )
download_link_windows = self.request.get( 'download_link_windows' )
download_link_java = self.request.get( 'download_link_java' )
store_link_chrome = self.request.get( 'store_link_chrome' )
store_link_android = self.request.get( 'store_link_android' )
store_link_ios = self.request.get( 'store_link_ios' )
model = Game()
model.alias = alias
model.name = name
model.platforms = platforms
model.category = category
model.download_link_linux = download_link_linux
model.download_link_osx = download_link_osx
model.download_link_windows = download_link_windows
model.download_link_java = download_link_java
model.store_link_chrome = store_link_chrome
model.store_link_android = store_link_android
model.store_link_ios = store_link_ios
model.put()
self.send_json_response( True )
示例4: get
# 需要导入模块: from models import Game [as 别名]
# 或者: from models.Game import put [as 别名]
def get(self, name):
if not users.get_current_user():
self.redirect(users.create_login_url(self.request.uri))
logging.info('Iniciando busca')
results = search_metacritic(name, 'game')
logging.info('Fetch concluido')
output = []
for result in results:
query = Img.all()
query.filter('url =', result[1])
img = query.fetch(1)[0]
query = Game.all()
query.filter('cover =', img)
if not query.count():
platform = str(result[1])[:str(result[1]).rfind('/')].replace('/game/','')
game = Game(name=str(result[0]),cover=img,platform=platform,score=str(result[2]))
game.put()
else:
game = query.fetch(1)[0]
output.append([img.key().id(), result[0], game.key().id()])
template_values = {'results': output}
path = os.path.join(os.path.dirname(__file__), 'search.html')
self.response.out.write(template.render(path, template_values))
示例5: create_new_game
# 需要导入模块: from models import Game [as 别名]
# 或者: from models.Game import put [as 别名]
def create_new_game(players, name):
import uuid
from models import Game
from constants import default_counter
from constants import win_types
game = Game()
game.game_name = name
game.game_id = str(uuid.uuid1())
game.players = players
game.current_player = random.randint(0, len(players) - 1)
game.data = json.dumps(create_world_data())
game.move_counter = default_counter
game.major_arcana = []
arcana = get_major_arcana()
for i in range(len(players)):
num = random.randint(0, len(arcana) - 1)
game.major_arcana.append(arcana[num])
del arcana[num]
goals = get_goals()
game.goals = []
for i in game.major_arcana:
for goal in win_types[i]:
num = random.randint(0, len(goals[goal]) - 1)
game.goals.append(goals[goal][num])
del goals[goal][num]
game.put()
示例6: new_game
# 需要导入模块: from models import Game [as 别名]
# 或者: from models.Game import put [as 别名]
def new_game(self, request):
"""Start a new game"""
#Check if players have registered
player1 = User.query(User.name == request.player1).get()
if not player1:
raise endpoints.ConflictException('Player 1 must register')
player2 = User.query(User.name == request.player2).get()
if not player2:
raise endpoints.ConflictException('Player 2 must register')
if player1 == player2:
raise endpoints.ConflictException('Cannot play against oneself')
#Create new game and put in datastore
game = Game(player1=player1.key,
player2=player2.key,
playerTurn=player1.key,
game_over=False
)
game.put()
#Create initial game board and set as ancestor of game
boardId = Board.allocate_ids(size=1, parent=game.key)[0]
boardKey = ndb.Key(Board, boardId, parent=game.key)
board = Board(key=boardKey)
board.put()
game.state = boardKey
game.put()
return StringMessage(message="Game between {0} and {1} created! {2}".format(player1.name, player2.name, game.key))
示例7: post
# 需要导入模块: from models import Game [as 别名]
# 或者: from models.Game import put [as 别名]
def post(self):
gameName = self.request.get("gameTitle")
creator = self.request.get("user")
newGame = Game(parent = PARENT_KEY,
gameName = gameName,
goals = [],
gameCreator = creator)
newGame.put()
self.redirect(self.request.referer)
示例8: create_new_game
# 需要导入模块: from models import Game [as 别名]
# 或者: from models.Game import put [as 别名]
def create_new_game():
if Game.all().filter('title =', request.json['title']).count() == 0:
name_of_player_to_join = list(set(request.json['players'])) # Makes sure each player is registered only once
shuffle(name_of_player_to_join)
players_to_join = [Player.all().filter('username =', name).get() for name in name_of_player_to_join]
new_game = Game(title=request.json['title'], num_player=len(players_to_join))
new_game.put()
for i in range(-1, len(players_to_join)-1):
killer = players_to_join[i]
GamePlayer(game=new_game, player=killer).put()
target = players_to_join[i+1]
GameHistory(killer=killer, target=target, game=new_game, is_complete=False, confirm_msg=msg_generator()).put()
return jsonify({"success": True})
else:
return jsonify({"success": False})
示例9: game_new_game
# 需要导入模块: from models import Game [as 别名]
# 或者: from models.Game import put [as 别名]
def game_new_game(self, game):
""" Add or update a game """
creator_key = player_utils.get_player_from_email(endpoints.get_current_user().email()).key
if game.invitee_email:
invitee_key = player_utils.get_player_from_email(game.invitee_email).key
else:
invitee_key = None
game_with_parent = Game(parent = creator_key,
creator_key = creator_key,
invitee_key = invitee_key,
is_solo = not invitee_key
)
game_with_parent.put()
return game_with_parent
示例10: create_game
# 需要导入模块: from models import Game [as 别名]
# 或者: from models.Game import put [as 别名]
def create_game(self, request) :
"""Create new conference."""
#get the user ID first and make sure they're authorised
user = endpoints.get_current_user()
if not user:
raise endpoints.UnauthorizedException('Authorization required')
user_id = getUserId(user)
#now create the game entity and insert it
game = Game(owner=user_id,
player1=GameMiniForm.get('player1'),
player2=GameMiniForm.get('player2'),
name=GameMiniForm.get('name'))
playerTurn = 1
#set the player turn randomly
if bool(random.getrandbits(1)) :
playerTurn = 1
else :
playerTurn = 2
game.playerTurn = playerTurn
game_key = game.put()
url_key = game_key.urlsafe()
#return all of the game details, including a game key
return GameForm(id=url_key, owner=user_id,
player1=game.player1,
player2=game.player2,
name=game.name)
示例11: startGame
# 需要导入模块: from models import Game [as 别名]
# 或者: from models.Game import put [as 别名]
def startGame(self, request):
""" Initializes all 9 posible moves using provided game_id """
game_id = request.game_id
player1 = request.player1
player2 = request.player2
if request.game_id == None:
return StringMessage(message = "Failed, Empty game_id. Please enter a valid unique game_id")
if request.player1 == None or request.player2 == None:
return StringMessage(message = "Failed, Missing Players. Make sure both player ids are present")
if request.player1 == request.player2:
return StringMessage(message = "Failed, Player Ids must be different")
game_exists = len(Move.query(Move.game_id == game_id).fetch()) > 0
if game_exists:
return StringMessage(message = "Game Creation Failed, Game ID already exists: {0}".format( game_id ) )
# Creating Game
game = Game(game_id = game_id, player1 = request.player1, player2 = request.player2)
game.put()
print("New Game Created: {0}".format(game))
mv1 = Move(x = 0, y = 0, game_id = game_id, available = True, description = "[0,0]")
mv2 = Move(x = 0, y = 1, game_id = game_id, available = True, description = "[0,1]")
mv3 = Move(x = 0, y = 2, game_id = game_id, available = True, description = "[0,2]")
mv4 = Move(x = 1, y = 0, game_id = game_id, available = True, description = "[1,0]")
mv5 = Move(x = 1, y = 1, game_id = game_id, available = True, description = "[1,1]")
mv6 = Move(x = 1, y = 2, game_id = game_id, available = True, description = "[1,2]")
mv7 = Move(x = 2, y = 0, game_id = game_id, available = True, description = "[2,0]")
mv8 = Move(x = 2, y = 1, game_id = game_id, available = True, description = "[2,1]")
mv9 = Move(x = 2, y = 2, game_id = game_id, available = True, description = "[2,2]")
# ndb.put_multi([ mv1, mv2, mv3, mv4, mv5, mv6, mv7, mv8, mv9])
for m in [ mv1, mv2, mv3, mv4, mv5, mv6, mv7, mv8, mv9]:
print(" saving: {0}".format(m) )
m.put()
return StringMessage(message = "New Game Created, ID: {0} | Player 1: {1} | Player 2: {2}".format( game_id, player1, player2 ) )
示例12: add_game
# 需要导入模块: from models import Game [as 别名]
# 或者: from models.Game import put [as 别名]
def add_game():
if not session.get('logged_in'): # session is a like a conference, the browser remembers data
abort(401)
# db = get_db()
# # use ? to specify query parameters
# db.execute('insert into game (title, num_player) values (?, ?)',
# [request.form['title'], request.form['num_player']])
# db.commit()
title = request.form['title'] #takes what user put into show_games form
num_player = request.form['num_player']
g = Game(title=title, num_player=int(num_player))
g.put() # save in the database
flash('New game was successfully posted') #displays message
return redirect(url_for('show_games')) #takes you back to show games page, with the newly added game displayed
示例13: _new_game
# 需要导入模块: from models import Game [as 别名]
# 或者: from models.Game import put [as 别名]
def _new_game(self, user, game_name):
# retrieve key from user_name
user_key = ndb.Key(User, user.user_name)
# generate game_id
game_id = Game.allocate_ids(size=1, parent=user_key)[0]
# create key using generated game_id and user as its ancestor
game_key = ndb.Key(Game, game_id, parent=user_key)
# generate random word for this game
rw = RandomWords()
word = rw.random_word()
guessed_chars_of_word = []
# make this impl more 'pythonic' way
for c in word:
guessed_chars_of_word.append('*')
game = Game(key=game_key,
game_id=game_id,
game_name=game_name,
word=word,
guessed_chars_of_word=guessed_chars_of_word)
# save game
game.put()
# score id
score_id = Score.allocate_ids(size=1, parent=user_key)[0]
# score key using generated score_id and user as its ancestor
score_key = ndb.Key(Score, score_id, parent=user_key)
# score entity for this game
score = Score(key=score_key,
score_id=score_id,
game_key=game_key)
# save score
score.put()
# capture game snapshot
self._capture_game_snapshot(game, '')
return game
示例14: _create_and_save_game
# 需要导入模块: from models import Game [as 别名]
# 或者: from models.Game import put [as 别名]
def _create_and_save_game(team_a, team_b, map, winner, round):
team_a_team = _create_or_get_team(team_a)
team_b_team = _create_or_get_team(team_b)
team_a_elo = team_a_team.elo
team_b_elo = team_b_team.elo
team_a_team.elo = calculate_new_elo(team_a_elo, team_b_elo, winner == team_a)
team_b_team.elo = calculate_new_elo(team_b_elo, team_a_elo, winner == team_b)
game = Game(
team_a=team_a,
team_b=team_b,
winner=winner,
round=round,
map=map
)
logging.info('about to put {}, {} and {}'.format(game, team_a_team, team_b_team))
game.put()
team_a_team.put()
team_b_team.put()
示例15: ResultTests
# 需要导入模块: from models import Game [as 别名]
# 或者: from models.Game import put [as 别名]
class ResultTests(gae.GAETestCase):
def setUp(self):
super(ResultTests, self).setUp()
self.user = MainUser(name='vovo', email='[email protected]')
self.user.put()
self.game = Game(tit='teste', map='brasil')
self.game.put()
def test_create_new_result(self):
result = Result.change_result_attrs(points=1, won_medal=True,
game_title=self.game.tit, game=self.game,
user_key=self.user.key, duration=0.20)
result.put()
self.assertEquals(result.last_points, 1)
self.assertEquals(result.game_title, self.game.tit)
self.assertEquals(result.won_medal, True)
self.assertEquals(result.game, self.game.key)
self.assertEquals(result.last_duration, 0.20)
self.assertEquals(result.best_duration, 0.20)
def test_update_result(self):
result = Result.change_result_attrs(points=1, won_medal=True,
game_title=self.game.tit, game=self.game,
user_key=self.user.key, duration=0.20)
result.put()
self.assertEquals(result.best_points, 1)
self.assertEquals(result.best_duration, 0.20)
self.assertEquals(result.best_date, date.today())
self.assertEquals(result.frequency, 1)
result = Result.change_result_attrs(points=2, duration=0.10, won_medal=True,
game_title=self.game.tit, game=self.game,
user_key=self.user.key)
self.assertEquals(result.best_points, 2)
self.assertEquals(result.best_duration, 0.10)
self.assertEquals(result.best_date, date.today())
self.assertEquals(result.frequency, 2)