예제 #1
0
                    irc.sendMessage(chan, "Dealt")
                    for st in gameP.print():
                        irc.sendMessage(chan, st)
                        sleep(0.49)

                else:
                    irc.sendMessage(chan, "Already dealt")

            if mess[0].startswith(".e"):

                if len(mess) < 4:
                    irc.sendMessage(chan, "Insufficent paramether")

                if dealt:
                    try:
                        play.play(nick, int(mess[1]), int(mess[2]),
                                  int(mess[3]))
                        for st in gameP.print():
                            irc.sendMessage(chan, st)
                            sleep(0.49)
                    except IOError as e:
                        irc.sendMessage(chan, "You can't do that: " + str(e))

                    if play.checkForWin():
                        irc.sendMessage(chan, nick + " lost")
                        players = dict()
                        play = None
                        gameP = None
                        dealt = False
                        owner = None

                else:
예제 #2
0
from deck import Deck
from deck import Card
from game import Play

# It is a slightly different variation of the 'WAR' card game. Users can select which card to throw unless
# they are in a WAR situation, which all the cards will be from the top.

if __name__ == "__main__":

    deck = Deck()
    player_pc = []
    player_real = []
    for i in range(len(deck.get_deck())):
        if i % 2 == 0:
            player_pc.append(deck.get_deck()[i])
        else:
            player_real.append(deck.get_deck()[i])

    game = Play(player_pc, player_real)
    # game = Play([Card('S', '2', False), Card('D', '2', False), Card('H', '2', False), Card('C', '2', False)],
    #            [Card('S', 'A', False), Card('D', 'A', False), Card('H', 'A', False), Card('C', 'A', False)])
    game.play()
예제 #3
0
def play_and_status(request):
    """Play moves if game has started.
If not, check waitlist and start a new game.
"""
    # Check permission.
    if not request.session.has_key("username"):
        return HttpResponseForbidden(
            json.dumps({"error": "You are not logged in."}))

    # Check to see if game has been chosen.
    (game, requested_players) = Play.get_game(request.session["username"])
    if not game:
        return HttpResponseBadRequest(
            json.dumps({"error": "You have not chosen a game."}))

    # Check to see if game has started.
    if not game.started:
        return HttpResponse(game.last_status)

    # Check to see if the game has been won by someone.
    if "winner" in json.loads(game.last_status):
        response = HttpResponse(game.last_status + "\n"
                + game.main_grid + "\n" + game.wallh_grid + "\n"
                + game.wallv_grid + "\n" + game.wallfills_grid
                                + "\n" + json.dumps(dict()))
        Play.stop(game, requested_players,
                  request.session["username"],
                  already_stopped=True)
        return response

    if "stopped" in json.loads(game.last_status):
        response = Play.stop(game, requested_players,
                             request.session["username"],
                             already_stopped=True)
        return response

    # Check turn.
    if game.turn.username != request.session["username"]:
        return HttpResponse(game.last_status + "\n"
                + game.main_grid + "\n" + game.wallh_grid + "\n"
                + game.wallv_grid + "\n" + game.wallfills_grid
               + "\n" + Play.get_walls(game, requested_players))

    # Check to see if any move has been made.
    if request.method != "POST":
        return HttpResponse(game.last_status + "\n"
                + game.main_grid + "\n" + game.wallh_grid + "\n"
                + game.wallv_grid + "\n" + game.wallfills_grid
               + "\n" + Play.get_walls(game, requested_players))
    post = request.POST.dict()

    # Check data validity.
    if (set(post.keys()) != {"move"} 
        or not _is_move_format_valid(json.loads(post["move"]))
):
        return HttpResponseBadRequest(
            json.dumps({"error": "Your POST data is corrupted."}))

    # Play the move.
    return Play.play(game,
                     requested_players,
                     json.loads(post["move"]))