Ejemplo n.º 1
0
 def print_board(self):
     for row in self.state:
         for item in row:
             if item == 1:
                 print_red(item, '   ')
             elif item == 2:
                 print_blue(item, '   ')
             else:
                 print(item, end='   ')
         print('\n')
Ejemplo n.º 2
0
def run_game():
    signal.signal(signal.SIGINT, sigint_handler)
    player, board_size, reverse_status = game_setup()

    # Play Game with 1 or 2 players
    winner = play_game(board_size, player)
    # Results
    if (reverse_status and winner == 2) or (not reverse_status and winner == 1):
        print_red(player[0].name + ' has Won.\n', '')
    elif (reverse_status and winner == 1) or (not reverse_status and winner == 2):
        print_blue(player[1].name + ' has Won.\n', '')
    else:
        print('Game ends in Tie.\n')
Ejemplo n.º 3
0
 def players_turn(self):
     statement = "It is " + self.name + "'s turn\n"
     if self.color == 1:
         print_red(statement, '')
     else:
         print_blue(statement, '')
Ejemplo n.º 4
0
import color

if __name__ == '__main__':
    import logging
    import logging.handlers
    import io

    color.print_dark_red('dark red')
    color.print_red('red')
    color.print_dark_green('dark green')
    color.print_green('green')
    color.print_dark_skyblue('dark skyblue')
    color.print_skyblue('skyblue')
    color.print_yellow('yellow')
    color.print_purple('purple')
    color.print_blue('blue')
    color.print_white('White Char')
    color.print_dark_gray('dark gray')

    color.print_normal('normal for normal words')
    color.print_italic('italic for comment and other like italic font usage')
    color.print_bold('bold use like bold font')
    color.print_ok('ok means that exec action succeed')
    color.print_warning('warning')
    color.print_warning('print_warning is too long')
    color.print_error('error')
    color.print_err('print_error is too long')

    with color.redirect_red():
        print('redirect red')
Ejemplo n.º 5
0
def game_setup():
    # Decide if you want to play against an AI or another human
    print('Select Number of Players\nChoose 1 to play an AI, and choose 2 to play a friend.')
    while True:
        try:
            num_players = int(input('Number of Players (1 or 2): '))
        except ValueError:
            print('Invalid Input')
            continue
        if num_players is 1 or num_players is 2:
            break
        else:
            print('Invalid Number of Players')
    # Select board size
    while True:
        try:
            board_size = int(input('Select a board length from 6 to 8: '))
        except ValueError:
            print('Invalid Input')
            continue
        if 5 < board_size < 9:
            break
        else:
            print('Invalid Board Size')
    # Decide which mode of Connect4 you wish to play
    reverse_mode = False
    mayhem_mode = False
    while True:
        try:
            mode_selection = input('Type C to play normal Connect4, D to play "Dont Connect 4!", and M to play Mayhem! ')
        except ValueError:
            print('Invalid Input')
            continue
        if mode_selection == 'C' or mode_selection == 'c':
            break 
        elif mode_selection == 'D' or mode_selection == 'd':
            reverse_mode = True 
            break
        elif mode_selection == 'M' or mode_selection == 'm':
            mayhem_mode = True 
            break
        else:
            print('Invalid Input')

    if num_players == 1:
        while True:
            try:
                difficulty = int(input('Select difficulty level from 1 (Easy) to 9 (Hard): '))
            except ValueError:
                print('Invalid Input')
                continue
            if difficulty < 1 or difficulty > 9:
                print('Invalid Difficulty Level')
                continue
            else:
                difficulty += 2
                break

        player_name = input("Please enter player1's name: ")
        player1 = Player(player_name, 1, reverse=reverse_mode, mayhem=mayhem_mode)
        print_red('You are Player 1.\n', '')
        print_blue('The AI is Player 2.\n', '')
        player2 = Player("AI", 2, difficulty, reverse_mode, mayhem_mode)
    else:
        player_name = input("Please enter player1's name: ")
        player1 = Player(player_name, 1, reverse=reverse_mode, mayhem=mayhem_mode)
        player_name = input("Please enter player2's name: ")
        player2 = Player(player_name, 2, reverse=reverse_mode, mayhem=mayhem_mode)

    return [player1, player2], board_size, reverse_mode