Game Modules

shell

Takes input from user/s.

Control the game through parse the input and call the equivalent method to operate the work.

class app.shell.Shell[source]

Bases: cmd.Cmd

Shell class.

default(line)[source]

Print out message when invalid input.

do_cheat(_)[source]

Return the upcoming value of the dice.

do_end(_)[source]

End currnet game.

do_exit(_)[source]

Exit CMD-terminal the game.

do_help(_)[source]

Print orders’ format.

do_level(level)[source]

Change the game’s level.

do_name(new_name)[source]

Change player name.

do_pass(_)[source]

Hold turn.

do_q(arg)[source]

Exit CMD-terminal the game.

do_roll(_)[source]

Roll the dice.

do_score(_)[source]

Read from highscore file.

do_start(player_num)[source]

Game starting.

intro = 'Enter help or ? to get the words that can be used.\n'
prompt = '(game): '

game

Process operations according to input taken in shell.py.

The instance of game class is created within shell.py. After analyzing the input, game object reach the equivalent method for processing

class app.game.Game[source]

Bases: object

Game Class.

change_name(name)[source]

Change player name.

cheat()[source]

Return the rolled dice to reach cheating feture.

check_levels(level)[source]

Check if the entered level is valid.

computer_turn()[source]

Take orders from Intelligence class to control the decison.

console(player)[source]

Synchronize between players’s scores and rolled dice.

create_player(player_amount)[source]

Create Players according to passed parameter.

Get info from shell.py, fit equivalent players with names. Turn computer_controller on/off.

end_game(player)[source]

Call other methods to process game ending.

get_computer_controler()[source]

Getter for a boolen variable.

Help to switching turns.

get_face()[source]

Return dice face before automatic rolling.

Method used for testing purpose.

get_game_status()[source]

Check the game status.

get_playing_now()[source]

Return currently player.

highscore()[source]

Call method sprint out from highscore file.

static print_out_dice(player, number)[source]

Print out rolled dice.

static print_score(player)[source]

Print out player score and name.

roll()[source]

Reached by human players.

Call other methods to make operations depends on die rollments.

set_computer_controler(controller)[source]

Setter for a boolen variable.

Help in switching turns.

set_face(num)[source]

Set value in variable to hold dice face before automatic rolling.

This method used for testing purpose.

set_game_status(bool)[source]

Set game status.

set_playing_now(player)[source]

Change object’s holder to help exchanging players.

still_going = False
switcher()[source]

Switch between players.

Considering if the game has computer controller or not, based on that it calls a method to switch between players

win_pig = 50

dice

Present dice object used in the game.

class app.dice.Dice[source]

Bases: object

Dice Class.

get_dice()[source]

Return the rolled dice face.

roll_dice()[source]

Roll the dice and initialize random value.

highscore

The class accepts instances of players.

To be able to save scores at the end of the game. Player has ability to read score file when script runs

class app.highscore.Highscore(player1, player2)[source]

Bases: object

Highscore Class.

get_path()[source]

Return file’s path (testing purpose).

static read_file()[source]

Read highscore file.

write_file()[source]

Initialize players’ name and score to write them in txt file.

histogram

Recive players lists and organize printable style.

Considering players list score, each printed row equable the face that player got when he rolled dice.

class app.histogram.Histogram[source]

Bases: object

Histogram Class.

static print_asterisk(player_list)[source]

Print the equavelent asterisks in player list.

print_histogram(player1, player2)[source]

Process histogram feature.

Print Histogram and sending players lists to another method to organize asterisks style.

intelligence

Controls the intelligence computer player.

According to chosen level the class make decision for next movement.

class app.intelligence.Intelligence(level)[source]

Bases: object

Intelligence Class.

act_easy()[source]

Return decision as an easy level.

act_hard(value)[source]

Notice that the computer has ability to cheat.

act_normal(player)[source]

Control decision when level is Normal.

cheat_decison()[source]

Create computer decision about cheating.

Use same boolean tuple to init decision.

get_inti_decision(player, dice_value)[source]

Return a method using currying approach to set level.

orders = (True, False, True)

player

Player Class to control player objects create in game.

class app.player.Player(name, decision)[source]

Bases: object

Player Class.

change_score(score)[source]

Change player score according to dice dance.

get_name()[source]

Return player name.

get_score()[source]

Return player score.

get_score_list()[source]

Return score list.

reaction = <app.intelligence.Intelligence object>
set_level(level)[source]

Set computer’s level.

set_name(name)[source]

Change plyer name.

set_score_list(num)[source]

Set score list.

Test Modules

test_game

Test game module.

class test.test_game.TestGameClass(methodName='runTest')[source]

Bases: unittest.case.TestCase

Test Game Class.

setUp()[source]

Run at the beginning of the test.

test_change_name()[source]

Test changing name feature.

test_cheat()[source]

Tests cheat feature.

Cheating is made by showing the upcoming die-rollment.

test_check_levels()[source]

Test check_levels.

test_computer_turn_calls_switcher(mock_calls_switcher)[source]

Tests switcher callable by comuter-turn method.

test_console(mock_calls_dice_printer)[source]

Tests console method calls print_out_dice.

test_console1(mock_calls_change_score)[source]

Tests console method calls change-score.

test_console2(mock_calls_end_game)[source]

Tests player wins and game ends.

test_console_returns_false()[source]

Tests that console returns false when dice is 1 or 6.

test_create_player(mock)[source]

Test create_player.

test_create_player1(mock)[source]

Test create_player.

test_create_player2(mock)[source]

Test create_player.

test_end_game()[source]

Test end_game.

test_get_computer_controler()[source]

Test get_computer_controler.

test_get_game_status()[source]

Test get_game_status.

test_get_playing_now()[source]

Test set And get_playing_now.

test_print_out_dice()[source]

Test print_out_dice.

test_print_score()[source]

Test print_score.

test_roll(mock_calls_switcher)[source]

Tests that roll-method calls switcher when dice-face is 1.

test_set_cmputer_controler()[source]

Test set_computer_controler.

test_set_face()[source]

Test set_face.

test_switch_between_humans()[source]

Tests switching turns between player1 and player2.

test_switch_human_calling(mock_calls_swit_humans)[source]

Test-switching between humans’ players.

test_switch_with_computer(mock_set_computer)[source]

Tests switching turns between player1 and computer_player.

When switching between player1 and computer-player, _switch_with_computer method returns computer-turn method which in turns set_game_player to be the computer.

test_switch_with_computer_calling(mock_calls_swit_com)[source]

Test switching between player-1 and computer player.

test_dice

Test dice file.

class test.test_dice.TestDiceClass(methodName='runTest')[source]

Bases: unittest.case.TestCase

Dice class Test.

setUp()[source]

Run at the beginning of the test.

test_get_dice()[source]

Tests the returned value after rolling a die.

test_init()[source]

Test the created instance.

test_roll_dice()[source]

Test that the rolled value is in the list above.

test_highscore

Test highscore module.

class test.test_highscore.TestHigscore(methodName='runTest')[source]

Bases: unittest.case.TestCase

Test Higscore Class.

setUp()[source]

Run at the beginning of the test.

test_get_path()[source]

Test get_path.

test_write_file()[source]

Test write_file.

test_histogram

Test Histogram module.

class test.test_histogram.TestHistogram(methodName='runTest')[source]

Bases: unittest.case.TestCase

Test Histogram Class.

test_print_asterisk()[source]

Test print_asterisk method.

test_print_histogram()[source]

Test print_histogram by catching output and comparing it.

test_intelligence

Test intelligence module.

class test.test_intelligence.TestIntelligenceClass(methodName='runTest')[source]

Bases: unittest.case.TestCase

Test Histogram Class.

setUp()[source]

Run at the beginning of the test.

test_act_easy()[source]

Test act_easy.

test_act_hard()[source]

act-hard method where it returns true when computer dicide to cheat.

The method returns True when dice-face between 2-5.

test_act_hard_calls_easy(mock_calls_act_easy)[source]

Tests act-hard calls easy when cheat_decison = False.

test_act_normal(mock_calls_act_easy)[source]

Tests act-normal returns True/False.

When computer-player score is less than 10, another test to assert it calls act-easy if the score higher that 10.

test_cheat_decision()[source]

Test cheat-decision.

test_get_inti_decision_hard(mock_calls_act_hard)[source]

Tests get_inti_decision method calls act-hard.

test_get_inti_decision_normal(mock_calls_act_normal)[source]

Tests get_inti_decision method calls act-normal.

test_player

Test player module.

class test.test_player.TestPlayer(methodName='runTest')[source]

Bases: unittest.case.TestCase

Test Histogram Class.

setUp()[source]

Create instances at the beginning of tests cases.

test_chane_score()[source]

Test change_score method.

test_get_score_list()[source]

Test Player Class.

test_set_name()[source]

Test set/change player name.

test_set_score_list()[source]

Test set_score_list.