game_page module¶
A module with a computer game class page and an online game class page.
- class game_page.FriendGame(master)¶
Bases:
tkinter.FrameThe online game class page.
- Parameters
master (class: tictactoe.App) – An instance of the main class of the game application
- __init__(master) None¶
Make constructor method.
- _bind_return_btn() None¶
Change a “Reset game” button to a “Return to online game page” button.
- _change_status() None¶
Change the text of the label with the status of the game to “Waiting for the opponent turn”.
- _check_win() Optional[Tuple[int, int, int]]¶
Check whether the game ended with a victory for player, otherwise causes a check for a draw.
- Returns
A tuple with a player’s winning position or None
- Return type
class: tuple[int, int, int] or None
- _click(square: int) None¶
Set action for a button that is an element of the game field.
- Parameters
square (class int) – The position chosen by the player
- _create_field(frame: tkinter.Frame) List[tkinter.Button]¶
Draw the playing field from buttons.
- Parameters
frame (class tkinter.Frame) – Frame for drawing the playing field from buttons
- Returns
Game field
- Return type
class list[tkinter.Button]
- _create_return_btn() None¶
Render “Reset game” button.
- _create_widgets() None¶
Render widgets of the online game page.
- _draw_sign(square: int) None¶
Draw a player sign at the position he has chosen.
- Parameters
square (class int) – The position chosen by the player
- static _end_game_color() Tuple[str, str, str]¶
Set the color of the field illumination after the end of the game.
- Returns
Tuple of three same color strings of the field illumination after the end of the game
- Return type
class tuple[str, str, str]
- _if_drawn_game() None¶
Check whether the game ended in a draw and performs the appropriate actions.
- _if_end_game(result: Optional[Tuple], square: int) None¶
Make some actions if the game is over.
Perform the actions to be performed if the game is over. Send a message to the server_dir that the game is finished.
- Parameters
result (class: tuple or None) – A tuple with a player’s winning position
square (class: int) – The position that the player went to and which led to the end of the game
- _player_sign_lbl() None¶
Draw label with the names of players and their signs.
- _set_end_game(pos_a: int, pos_b: int, pos_c: int) None¶
Set the end of the game, tells which player won and repaints the field in the appropriate color.
- Parameters
pos_a (class: int) – The first of three positions from which a win is obtained
pos_b (class: int) – The second of the three positions from which a win is obtained
pos_c (class: int) – The third of the three positions from which a win is obtained
- _status_lbl() None¶
Draw a label with the game status.
- _switch_frame() None¶
Set action for the “Return to online game page” button.
- _update_statistic(flag: int) None¶
Update statistics and sends them to the server_dir.
- Parameters
flag (class: int) – Flag signaling the outcome of the game; 0 - drawn, 1 - win, 2 - defeat
- change_language(lang: str) None¶
Set action for the language change button.
- Parameters
lang (class: str) – A string with the localization language of the application, “en” or “ru”
- on_info(data: Dict[str, str]) None¶
Take information about the game from the server_dir and saves it.
- Parameters
data (class: dict[str, str]) – Dictionary with the information about the game from the server_dir
- on_opponent_reset() None¶
Perform actions if the opponent has left the game.
- on_start_game() None¶
Make actions for start the game.
Receive a message from the server_dir about the start of the game. Prepare the field and status messages so that you can start the game.
- on_update_board(data: Dict[str, int]) None¶
Perform actions to update the field and status messages after the opponent’s move.
- Parameters
data (class: dict[str, int]) – Dictionary with the information about the opponent turn from the server_dir
- on_update_game_over(data: Dict[str, Union[str, int, bool]]) None¶
Perform actions to end the game if the opponent wins.
- Parameters
data (class dict[str, str | int | bool]) – Dictionary with data about the end of the game
- reset_game() None¶
Set action for the “Reset game” button.
- class game_page.PcGame(master)¶
Bases:
tkinter.FrameThe computer game class page.
- Parameters
master (class: tictactoe.App) – An instance of the main class of the game application
- __init__(master) None¶
Make constructor method.
- _begin_cur_sign() Optional[Tuple[str, str]]¶
Select the sign and player name of the player who moves first.
- Returns
The sign and player name of the player who moves first or None
- Return type
class tuple[str, str] or None
- _bind_return_btn() None¶
Change the label and action for the “Start” button.
- _change_sign_and_status() None¶
Change the sign and name of the current player.
- _check_win() None¶
Check the win on each turn.
Check whether the game ended with a victory for the computer or the player, otherwise causes a check for a draw.
- _click(square: int) None¶
Set action for a button that is an element of the game field.
Set action for a button that is an element of the game field. Pass the move to the computer, if the game is not over.
- Parameters
square (class int) – The position chosen by the player
- _click_1(square: int) None¶
Perform actions corresponding to the player’s turn.
- Parameters
square (class int) – The position chosen by the player
- _computer_turn() None¶
Select a position for the computer’s move and executes a move to that position.
- _create_field(frame: tkinter.Frame) List[tkinter.Button]¶
Draw the playing field from buttons.
- Parameters
frame (class tkinter.Frame) – Frame for drawing the playing field from buttons
- Returns
Game field
- Return type
class list[tkinter.Button]
- _create_return_btn() None¶
Render “Start” button for starting the game.
- _create_widgets() None¶
Render widgets of the computer game page.
- _cur_sign_change() Tuple[str, str]¶
Change the name and badge of the current player to another.
- Returns
Current player name and current player sign
- Return type
class: tuple[str, str]
- _default_choice() Optional[int]¶
Select randomly a position for the computer’s move if the best move has not been found.
- Returns
Random position of the computer turn or None
- Return type
class int or None
- _draw_sign(square: int) None¶
Draw a player’s sign at the position he has chosen.
- Parameters
square (class int) – The position chosen by the player
- _end_game_color() Tuple[str, str, str]¶
Set the color of the field illumination after the end of the game.
- Returns
Tuple of three same color strings of the field illumination after the end of the game
- Return type
class tuple[str, str, str]
- _find_best_turn(sign: str) Optional[int]¶
Find position of the best turn for computer.
- Parameters
sign (class str) – Sign of player or computer
- Returns
Position of the best turn or None
- Return type
class int or None
- _if_drawn_game() None¶
Check whether the game ended in a draw and performs the appropriate actions.
- _if_end_game() None¶
Perform the actions to be performed if the game is over.
- _is_win(sign: str, field: List[str]) bool¶
Check whether there is a winning position on field for a given sign.
- Parameters
sign (class: str) – Sign of player or computer
field (class list[str]) – List of signs on specific positions
- Returns
Flag of whether there is a winning position
- Return type
class: bool
- static _player_name() Tuple[str, str]¶
Return a tuple of the strings “Player” and “Computer”.
- Returns
The tuple of the strings “Player” and “Computer”
- Return type
class: tuple[str, str]
- _player_sign_lbl() None¶
Draw label with the names of players and their signs.
- _precondition() None¶
Make the playing field active and informs that the game has started.
- _set_end_game(pos_a: int, pos_b: int, pos_c: int) None¶
Set the end of the game, tells which player won and repaints the field in the appropriate color.
- Parameters
pos_a (class: int) – The first of three positions from which a win is obtained
pos_b (class: int) – The second of the three positions from which a win is obtained
pos_c (class: int) – The third of the three positions from which a win is obtained
- _set_end_game_music() None¶
Set the music of the end of the game depending on the outcome of the game.
- _sign_choose() Optional[Tuple[str, str]]¶
Set signs for players.
- Returns
Signs for players or None
- Return type
class tuple[str, str] or None
- _start_game() None¶
Set action for the “Start” button.
- _start_game_1() None¶
Perform actions to start the game.
- _status_lbl() None¶
Draw a label with the game status.
- _switch_frame() None¶
Send statistics to the server_dir and changes the page to the settings page of the game with the computer.
- _turn(square: int) None¶
Perform actions corresponding to the computer’s turn.
- Parameters
square (class int) – The position chosen by the computer
- _update_statistic(flag: bool) None¶
Update player statistics.
- Parameters
flag (class bool) – Flag indicating whether the game ended in a draw
- change_language(lang: str) None¶
Set action for the language change button.
- Parameters
lang (class: str) – A string with the localization language of the application, “en” or “ru”