def __init__(self,
                 chat_id: int,
                 user_id: int,
                 lang_id: str,
                 first_name: str,
                 game_handler: object,
                 message_id: int,
                 send_message: callable,
                 multiplayer: bool = None,
                 game_id: str = None):
        # declare variables and set initial values
        self.players = []
        self.chat_id = chat_id
        self.__game_id = game_id
        self.lang_id = lang_id
        self.deck = CardDeck(lang_id)
        # TODO language of the cards & dealer cannot be changed
        # TODO especially with new multiplayer important!
        self.dealer = Dealer(translate("dealerName", lang_id), self.deck)
        self.game_running = False
        self.current_player = 0
        self.game_handler = game_handler
        self.send_message = send_message
        self.logger = logging.getLogger(__name__)

        if multiplayer:
            self.game_type = self.MULTIPLAYER_GAME
            chat_id = 0
        elif chat_id >= 0:
            self.game_type = self.PRIVATE_CHAT
        else:
            self.game_type = self.GROUP_CHAT

        one_more_button = KeyboardButton(
            translate("keyboardItemOneMore", lang_id))
        no_more_button = KeyboardButton(
            translate("keyboardItemNoMore", lang_id))
        stop_button = KeyboardButton(translate("keyboardItemStop", lang_id))
        self.keyboard_running = ReplyKeyboardMarkup(
            keyboard=[[one_more_button, no_more_button], [stop_button]],
            selective=True)

        self.add_player(user_id, first_name, message_id, silent=True)

        # Only send a "Please join the game" message, when it's a group chat
        if self.game_type == self.GROUP_CHAT:
            keyboard = [[
                InlineKeyboardButton(text=translate("join",
                                                    self.lang_id).capitalize(),
                                     callback_data="join_game")
            ]]
            reply_markup = InlineKeyboardMarkup(keyboard)
            send_message(chat_id,
                         translate("newRound", lang_id),
                         message_id=message_id,
                         reply_markup=reply_markup)
        elif self.game_type == self.MULTIPLAYER_GAME:
            pass
        else:
            self.start_game()
Beispiel #2
0
    def __init__(self):
        """"Class Constructor: will inizialite a dictionary and the num_throws to count
         the amount of times he is going to throw it"""

        self.keep_playing = True
        self.guess = True
        self.dealer = Dealer()
        self.score = 300
Beispiel #3
0
 def __init__(self):
     self.points = 0
     self.keep_playing = True
     self.user_H_L_choice = ""
     self.play_again = True
     self.get_choice = ""
     self.dealer = Dealer()
     self.highscore = Highscore()
Beispiel #4
0
 def __init__(self, num_seats: int, _id: int,
              dealer_delegate: DealerDelegate):
     self._seats: [_Seat] = [_Seat(i) for i in range(num_seats)]
     self._players: {int: Player} = self._load_players(_id)
     self._id = _id
     self.dealer = Dealer(self, dealer_delegate)
     self.button_position = 0
     self.point = None
Beispiel #5
0
 def __init__(self):
     """The class constructor.
     
     Args:
         self (Director): an instance of Director.
     """
     self.keep_playing = True
     self.score = 300
     self.dealer = Dealer()
Beispiel #6
0
    def __init__(self, chat_id, user_id, lang_id, first_name, game_handler,
                 message_id, send_message):
        # declare variables and set initial values
        self.players = []
        self.join_message_ids = []
        self.chat_id = chat_id
        self.lang_id = lang_id
        self.deck = CardDeck(
            lang_id)  # TODO language of the cards & dealer cannot be changed
        self.dealer = Dealer(translate("dealerName", lang_id), self.deck)
        self.game_running = False
        self.current_player = 0
        self.game_handler = game_handler
        self.send_message = send_message
        self.logger = logging.getLogger(__name__)

        if chat_id >= 0:
            self.game_type = self.PRIVATE_CHAT
        else:
            self.game_type = self.GROUP_CHAT

        one_more_button = KeyboardButton(
            translate("keyboardItemOneMore", lang_id))
        no_more_button = KeyboardButton(
            translate("keyboardItemNoMore", lang_id))
        stop_button = KeyboardButton(translate("keyboardItemStop", lang_id))
        self.keyboard_running = ReplyKeyboardMarkup(
            keyboard=[[one_more_button, no_more_button], [stop_button]],
            selective=True)

        self.add_player(user_id, first_name, message_id, silent=True)

        # Only send a "Please join the game" message, when it's a group chat
        if self.game_type == self.GROUP_CHAT:
            send_message(
                chat_id, translate("newRound", lang_id),
                message_id=message_id)  # keyboard=self.keyboard_not_running
        else:
            self.start_game()
Beispiel #7
0
 def __init__(self):
     self.playerScore = 300
     self.current_card = 0
     self.next_card = 0
     self.dealer = Dealer()
     self.keepPlaying = True
Beispiel #8
0
# TODO: Add entry point code here
# Test comment from Bro. Lythgoe

from game.dealer import Dealer
#This imports the dealer class
dealer = Dealer()
#This initializes the dealer class
dealer.play_game()
#This calls the function in the dealer class to start playing the game
Beispiel #9
0
 def __init__(self):
     self.keep_playing = True
     self.score = 300
     self.dealer = Dealer()
     self.current_card = 0
def initialise_game(room):
    numPlayers = len(rooms[room])
    players = Players(numPlayers)
    dealer = Dealer()
    dealer.initialiseCards()
    dealer.shuffleCards()
    dealer.distributeCards(players.players)
    for ((username, p_roomid), player) in zip(rooms[room], players.players):
        player.name = username
        player.pRoomId = p_roomid
        player.roomId = room

    socketio.emit('game_data', players.json_game_data(), room=room)
    socketio.emit('player_data', player.json_player_data(), room=p_roomid)

    # for ((username, p_roomid), player) in zip(rooms[room], players.players):
    # emit('player_data', player, room=id)
    # socketio.emit('game_data',json_game_data(players,dealer), room = room)

    playerChance = 0
    player = players.players[playerChance]
    while (not player.hasWon()):
        print('+++++++++++++++++++++++++++++')
        print(f'Player - {player.id}')
        player.sendMessageToAll(f"It's {player.name}'s turn.", socketio)
        print('+++++++++++++++++++++++++++++')
        player.chance = True
        # p_roomid = rooms[room][playerChance][1]
        # socketio.emit('player_data',json_player_data(player,dealer), room = player.pRoomId)
        # print(player.handCards,player.propertyCollection, player.bankCollection)
        player.drawCards(dealer)
        player.chanceNo = 1

        socketio.emit('player_data',
                      player.json_player_data(),
                      room=player.pRoomId)
        socketio.emit('game_data', players.json_game_data(), room=room)

        print(len(dealer.drawPile), len(player.handCards))
        while player.chanceNo <= player.cardsToPlay:
            val = player.playCard(
                socketio=socketio, dealer=dealer,
                players=players)  #TODO check the value of val
            # player.clearMessage(socketio)
            if val == -1:
                break
            # player.chanceNo +=1  Will increase this in the lower functions
            socketio.emit('player_data',
                          player.json_player_data(),
                          room=player.pRoomId)
            socketio.emit('game_data', players.json_game_data(), room=room)

        if len(player.handCards) > 7:
            player.discardCards(dealer.drawPile, socketio)
            socketio.emit('player_data',
                          player.json_player_data(),
                          room=player.pRoomId)
            socketio.emit('game_data', players.json_game_data(), room=room)

        if player.hasWon():
            player.sendMessageToAll(f"{player.name} has won the game.",
                                    socketio)
            socketio.emit('new_game', room=room)
            print('***************************************')
            print(f'Player - {player.id} has won the game.')
            print('***************************************')
            break

        player.chance = False
        socketio.emit('player_data',
                      player.json_player_data(),
                      room=player.pRoomId)

        playerChance = (playerChance + 1) % numPlayers
        player = players.players[playerChance]