Exemplo n.º 1
0
def main():
    # Command Line Defaults:
    SETUP_PATH = u''
    BONUS_FILE = u'bonus'
    TILES_FILE = u'tiles'
    WORDS_FILE = u'words'
    FILE_EXT = u'txt'  # Default File Extension
    PLAYERS = 2
    BOARD_SIZE = 15

    try:
        command = Command(BONUS_FILE, TILES_FILE, WORDS_FILE, FILE_EXT,
                          PLAYERS, BOARD_SIZE)
        if command.Parse(sys.argv):
            verbose = command.verbose

            if command.players <= 0:
                print(u'The # of players must be greater than 0')
                return

            tileManager = FileManager(SETUP_PATH, command.file_ext, verbose)
            tileManager.load(command.tiles_file)
            tiles = Tile(tileManager.records)

            bonusManager = FileManager(SETUP_PATH, command.file_ext, verbose)
            bonusManager.load(command.bonus_file)

            #
            # Test Board
            #
            #testBoard = Board(command.size_x, command.size_y, bonusManager.records, tiles)
            #testBoard.Test()

            board = Board(command.size_x, command.size_y, bonusManager.records,
                          tiles)

            wordManager = FileManager(SETUP_PATH, command.file_ext, verbose)
            wordManager.load(command.words_file)
            player = Player(command.players, wordManager.records, board,
                            command.reverse, command.debug)
            #player.Test()

            testCommands = [
                u'play g8=c,h8=a,i8=t', u'play k8=t,l8=o,m8=n,n8=i,o8=c',
                u'play k9=u,k10=f,k11=f', u'play i9=o,j9=v,l9=m',
                u'play j8=a,j10=o,j11=i,j12=d', u'board'
            ]
            #player.perform(testCommands)

            turn_player = player.start()

    except Exception as ex:
        #type_name = type(ex).__name__
        trace = traceback.format_exc()
        print(trace)

    #[Debug]
    raw_input(u'Press Enter')
Exemplo n.º 2
0
def main():
    # Command Line Defaults:
    SETUP_PATH = u''
    ART_FILE = u'art'  # Hangman ASCII Art
    WORD_FILE = u'words'  # Word File (Hangman Dictionary)
    FILE_EXT = u'txt'  # Word File Extension
    TRIALS = 6  # Head, Body, 2 Arms, 2 Legs

    try:
        command = Command(WORD_FILE, ART_FILE, FILE_EXT, TRIALS)
        if command.Parse(sys.argv):
            verbose = command.verbose
            artManager = FileManager(SETUP_PATH, command.file_ext, verbose)
            artManager.load(command.art_file)
            figures = artManager.paragraphs()

            wordManager = FileManager(SETUP_PATH, command.file_ext, verbose)
            wordManager.load(command.word_file)

            if wordManager.length > 0:
                choice = random.randrange(0, wordManager.length)
                word = wordManager.records[choice]

                player = Player(word, figures)
                result = player.play(command.trials)
                message = u'You win!' if result else u"You're hung."
                print(message)
            else:
                print(u'There are no words.')

    except Exception as ex:
        #type_name = type(ex).__name__
        trace = traceback.format_exc()
        print(trace)

    #[Debug]
    raw_input(u'Press Enter')