Example #1
0
def play_game(request, game_id, deal_number_str, params={}):

    from models.pgtile import PGTile
    from pghand import PGHand

    player_id = request.session.get('player_id', False)
    if (not player_id):
        return goto_home(request)
    player = PGPlayer.objects.get(id=player_id)

    # get the game from the db
    game = PGGame.with_id(game_id)
    if (not game):
        messages.add_message(
            request, messages.ERROR,
            "WTF?  That game has disappeared into the ether (which doesn't exist)"
        )
        return goto_home(request)
    params['game'] = game

    # get the deal number
    deal_number = int(deal_number_str)
    params['deal_number'] = deal_number

    # set the score for the other player.
    players_in_game = game.players()

    # make sure you're in the game: you can't look at other games.
    if not (player in players_in_game):
        messages.add_message(
            request, messages.ERROR,
            "I'm sorry, you are not allowed in that game, it's only for VIPs")
        return goto_home(request)

    # this sets up pig, don't get it fgirst
    params['pgsets'] = game.sets_for_player(session_player(request),
                                            deal_number)

    # set the game and score for you
    pid = game.player_in_deal(player, deal_number)
    params['score_player'] = game.score_as_of_deal_for_player(
        player, deal_number)

    # set up the opponent for the template
    opponent = session_player(request).opponent_for_deal(game, deal_number)

    # get your opponent's score
    #pido = game.player_in_deal( opponent, deal_number )
    params['score_opponent'] = game.score_as_of_deal_for_player(
        opponent, deal_number)

    # create the hands for this player (sets_for_player should be called first)
    params['pgtile_size'] = "medium"
    params['current_player_state'] = PGPlayerInDeal.state_ui(pid.state())

    return render_to_response('game_play.html',
                              request_context(request, params))
Example #2
0
def game_score( request, game_id, deal_number_str ):
  deal_number = int( deal_number_str )
  game = PGGame.with_id( game_id )
  player = session_player( request )
  if not player:
    return HttpResponseNotAllowed( "Bad Request" )
  opponent = session_opponent( request, game, deal_number )
  if not opponent:
    return HttpResponseNotAllowed( "Bad Request" )
  ret_val = str( game.score_as_of_deal_for_player( player, deal_number+1 ) ) + " - " + str( game.score_as_of_deal_for_player( opponent, deal_number+1 ) )
  if game.check_game_over():
    ret_val = "!" + ret_val
  print "Score returning: " + ret_val
  return HttpResponse( ret_val )
Example #3
0
def play_game( request, game_id, deal_number_str, params = {} ):
  
  from models.pgtile import PGTile
  from pghand import PGHand
  
  player_id = request.session.get('player_id', False) 
  if ( not player_id ):
    return goto_home( request )
  player = PGPlayer.objects.get( id = player_id )
  
  # get the game from the db
  game = PGGame.with_id( game_id )
  if ( not game ):
    messages.add_message( request, messages.ERROR, "WTF?  That game has disappeared into the ether (which doesn't exist)" )
    return goto_home( request )
  params['game'] = game

  # get the deal number
  deal_number = int( deal_number_str )
  params['deal_number'] = deal_number
  
  # set the score for the other player.
  players_in_game = game.players()
  
  # make sure you're in the game: you can't look at other games.
  if not ( player in players_in_game ):
    messages.add_message( request, messages.ERROR, "I'm sorry, you are not allowed in that game, it's only for VIPs" )
    return goto_home( request )
  
  # this sets up pig, don't get it fgirst
  params['pgsets'] = game.sets_for_player( session_player( request ), deal_number )

  # set the game and score for you
  pid = game.player_in_deal( player, deal_number )
  params['score_player'] = game.score_as_of_deal_for_player( player, deal_number )
  
  # set up the opponent for the template
  opponent = session_player( request ).opponent_for_deal( game, deal_number )
  
  # get your opponent's score
  #pido = game.player_in_deal( opponent, deal_number )
  params['score_opponent'] = game.score_as_of_deal_for_player( opponent, deal_number )
  
  # create the hands for this player (sets_for_player should be called first)
  params['pgtile_size'] = "medium"
  params['current_player_state'] = PGPlayerInDeal.state_ui( pid.state() )
  
  return render_to_response( 'game_play.html', request_context( request, params ) )
Example #4
0
def game_score(request, game_id, deal_number_str):
    deal_number = int(deal_number_str)
    game = PGGame.with_id(game_id)
    player = session_player(request)
    if not player:
        return HttpResponseNotAllowed("Bad Request")
    opponent = session_opponent(request, game, deal_number)
    if not opponent:
        return HttpResponseNotAllowed("Bad Request")
    ret_val = str(game.score_as_of_deal_for_player(
        player, deal_number + 1)) + " - " + str(
            game.score_as_of_deal_for_player(opponent, deal_number + 1))
    if game.check_game_over():
        ret_val = "!" + ret_val
    print "Score returning: " + ret_val
    return HttpResponse(ret_val)
Example #5
0
def add_game(request, params={}):

    player = session_player(request)
    if not player:
        return goto_home(request)

    # create a new game
    game = PGGame.create(request.POST['game_name'])
    game.save()  # must be done before adding player, so we have an ID

    # add ourselves and the opponent (which automatically saves)
    game.add_player(session_player(request))
    game.add_player(posted_player_from_id_field(request, 'game_opponent'))

    #messages.add_message( request, messages.INFO, "Game \"" + game.name + "\" created." )

    return redirect("/paigow/game/" + str(game.id) + "/1")
Example #6
0
def add_game( request, params = {} ):
  
  player = session_player( request )
  if not player:
    return goto_home( request )
  
  # create a new game
  game = PGGame.create( request.POST['game_name'] )
  game.save() # must be done before adding player, so we have an ID
  
  # add ourselves and the opponent (which automatically saves)
  game.add_player( session_player( request ) )
  game.add_player( posted_player_from_id_field( request, 'game_opponent' ) )
  
  #messages.add_message( request, messages.INFO, "Game \"" + game.name + "\" created." )
  
  return redirect ( "/paigow/game/" + str(game.id) + "/1" )