Ejemplo n.º 1
0
    def test_local_run_counting(self):
        new_game = bw.Bowling('X4/34')

        new_game.game_state(self.local_game())
        new_game._game_state.run()

        self.assertEqual(new_game.total_result, 42)
Ejemplo n.º 2
0
    def test_tournament_run_counting(self):
        new_game = bw.Bowling('X4/34', local_rules=False)

        new_game.game_state(self.tournament_game())
        new_game._game_state.run()

        self.assertEqual(new_game.total_result, 40)
Ejemplo n.º 3
0
 def setUp(self):
     self.game = bw.Bowling('1/X3-5/X8154-57/X')
     self.first_state = bw.FirstState
     self.second_state = bw.SecondState
     self.local_game = bw.LocalGame
     self.tournament_game = bw.ChampGame
     self.new_first_state = bw.NewRulesFirst
     self.new_second_state = bw.NewRulesSecond
def testFinalScore(testName, rolls, expectedScore):
    aGame = bowling.Bowling(testName)
    for roll in rolls:
        aGame.addRoll(roll)
    if aGame.finalScore() == expectedScore:
        print('PASS: '******'FAIL: ' + testName + ' expected ' + str(expectedScore) +
              ' but got ' + str(aGame.finalScore()))
Ejemplo n.º 5
0
 def _analyze_input_line(self, line):
     """ Going through each line in file"""
     line = line.rstrip()
     if line:
         line = line.split()
         self.player_name = line[0]
         self.player_result = line[1]
         bwl = bw.Bowling(self.player_result, local_rules=self.local_rules)
         bwl.check_result()
         self.player_result_count = bwl.total_result
         self.tournament_results[self.player_name] = []
         self.tournament_results[self.player_name].append(self.player_result)
         self.tournament_results[self.player_name].append(self.player_result_count)
         self._tour_result()
Ejemplo n.º 6
0
 def setUp(self):
     self.sut = bowling.Bowling()
Ejemplo n.º 7
0
import bowling

def displayGame(bowlingGame):
    print('')
    print('Player: ' + bowlingGame.playerName)
    print('')
    print('Frame1 | Frame2 | Frame3 | Frame4 | Frame5 | Frame6 | Frame7 | Frame8 | Frame9 | Frame10')
    frames = ''
    for frame in bowlingGame.frames:
        if len(frame.rolls) == 1:
            frames += '  ' + str(frame.rolls[0]) + '   | '
        elif len(frame.rolls) == 2:
            frames += ' ' + str(frame.rolls[0]) + ', ' + str(frame.rolls[1]) + '  | '
        elif len(frame.rolls) == 3:
            frames += str(frame.rolls[0]) + ', ' + str(frame.rolls[1]) + ', ' + str(frame.rolls[2])
    print(frames)
    print('Final Score: ' + str(bowlingGame.finalScore()))


playerName = input("Please enter the player's name: ")
game = bowling.Bowling(playerName)

while not game.gameOver:
    pins = input('Frame: ' + str(game.currentFrame().frameNumber) + ' Roll: ' + str(game.currentFrame().rollNumber) + ' How many pins? ')
    if not game.addRoll(int(pins)):
        print('Invalid number of pins. Try Again.')

displayGame(game)
Ejemplo n.º 8
0
    elif string.lower() in ('no', 'false', 'f', 'n', '0'):
        return False
    else:
        raise argparse.ArgumentTypeError('Boolean value expected.')


bowling_parser = argparse.ArgumentParser(
    'Input your bowling game result. It should consist of 10 frames with '
    'correct game rules. Example - 3271-/44X--2/X43-8')

bowling_parser.add_argument('-r',
                            '--result',
                            required=True,
                            help='Game result in 1 string without spaces.'
                            'Example - 9-4/529/8/XX-6311/')
bowling_parser.add_argument('-l',
                            '--local_rules',
                            type=str_to_bool,
                            help='Choose rules for counting game result:'
                            'pick True if you want to use local,'
                            'pick False for tournament rules')

bowling_result = vars(bowling_parser.parse_args())
game_checker = bw.Bowling(**bowling_result)
game_checker.check_result()
game_checker.print_result()

# input example
# python3 single_game_console_access.py -r 1/X3-5/X8154-57/X -l true
# python3 single_game_console_access.py -r 1/X3-5/X8154-57/X -l false