コード例 #1
0
def init_game(name):
    """
    Initialize the game

    :param game: the game you want to play
    :type game: str
    :returns: the games setup
    :rtype: dict
    """
    game={}
    game['name']=name
    list_coin=None
    if name =='othello':
        list_coin=['black','white']
    elif name =='tic_tac_toe':
        list_coin=['X','O']
    game['player1']=register_player(list_coin)
    player2= two_players()
    game['IA_level']= None
    if player2:
        game['player2']=register_player(list_coin)
    else:
        if list_coin==None:
            game['player2']=Player.create('minMAX',None)
        else:
            game['player2']=Player.create('minMAX',list_coin[0])
        if name == 'othello':
            game['IA_level']=set_difficulty()
        else:
            game['IA_level']=None
    # allow the player to choose wether he play on terminal on with graphical board
    return game
コード例 #2
0
def create():
    global img
    win = tk.Tk()
    win.title ('tictactoe')
    sit = tictactoe.initSituation({})
    playerone = Player.create('meryem','O')
    playertwo = Player.create('farah','X')
    global current
    current = playerone
    iconpath = os.path.join(os.path.dirname(os.path.abspath(__file__)),"icons")
    img = [
        tk.PhotoImage(file=os.path.join(iconpath,"c.gif")),
        tk.PhotoImage(file=os.path.join(iconpath,"x.gif")),
        tk.PhotoImage(file=os.path.join(iconpath,"o.gif"))
        ]
    b = []
    for i in range(3):
        b.insert(i,[])
        for j in range(3):
            if sit[i][j] == 'X':
                ig = img[1]
            if sit [i][j] == 'O':
                ig = img[2]
            if sit[i][j] == ' ':
                ig = img[0]
            button = tk.Button(win,padx=0,pady=0, width=120, height=120, image=img[0])
            button.grid(column = i, row = j)
            b[i].insert(j,button)
            button.bind("<Button-1>",partial(onClick, button.grid_info()['row'], button.grid_info()['column'], b, sit, playerone, playertwo))
    win.mainloop()
コード例 #3
0
ファイル: twoplayergame.py プロジェクト: Zimoune/projet-s3
def ask_players_names(color):
    """
    Ask players's names

    :param color: colors
    :type color: color list
    :return:
    """
    try:
        mod.set_player1(Player.create(input("name player 1: "), color[0]))
        mod.set_player2(Player.create(input("name player 2: "), color[1]))

    except KeyboardInterrupt:
        raise KeyboardInterrupt

    except:
        ask_players_names(color)
コード例 #4
0
    def NewUser(self, connection, name, password):
        # verify
        if name in self._players:
            raise CommandError, 'Username already exists'

        # create
        p = player.create(name, password, self)

        # store
        self.add_player(p)

        # push info to all players.
        self.broadcast('NEW_PLAYER', p.id, p.name)

        return 'OK'
コード例 #5
0
ファイル: __init__.py プロジェクト: p-blomberg/yamosg
    def NewUser(self, connection, name, password):
        # verify
        if name in self._players:
            raise CommandError, "Username already exists"

            # create
        p = player.create(name, password, self)

        # store
        self.add_player(p)

        # push info to all players.
        self.broadcast("NEW_PLAYER", p.id, p.name)

        return "OK"
コード例 #6
0
def register_player(list_coin):
    """
    register a human player
    :param list_coin: the list of allowed coins
    :type list_coin: list
    :returns: a new player
    :rtype: player
    """
    name= choose_name()
    if list_coin == None:
        coins = None
    elif len(list_coin)==1:
        coins=list_coin[0]
    else:
        coins=choose_coins(list_coin)
    return Player.create(name,coins)