Main

class src.main.AcceptTradeState(player, trade_partner, player_resources, trade_partner_resources)[source]

Represents the state of the game where the player can accept or decline a trade offer.

Parameters:
  • player (Player) – The Player object representing the current player.

  • trade_partner (Player) – The Player object representing the player who initiated the trade offer.

  • player_resources (dict) – A dictionary containing the resources that the current player will give in the trade.

  • trade_partner_resources (dict) – A dictionary containing the resources that the trade partner will give in the trade.

  • current_state (None) – The current state of the game (unused in this class).

  • trade_accepted (bool) – A boolean that is True if the trade was accepted, False otherwise.

  • accept_rect (pygame.Rect) – A rectangular area where the “Accept” button will be displayed.

  • accept_text (pygame.Surface) – The text to be displayed on the “Accept” button.

  • decline_rect (pygame.Rect) – A rectangular area where the “Decline” button will be displayed.

  • decline_text (pygame.Surface) – The text to be displayed on the “Decline” button.

draw(screen)[source]

Draws the accept trade screen on the given screen.

Parameters:

screen (pygame.Surface) – The pygame screen to draw the accept trade screen on.

handle_events(events)[source]

Handles the given events for the accept trade state of the game.

Parameters:

events (list) – The list of pygame events to handle.

should_transition()[source]

Returns True if the game should transition to a new state, False otherwise.

Returns:

True if the game should transition to a new state, False otherwise.

Return type:

bool

transition()[source]

Returns the new state of the game after transitioning.

Returns:

The new state of the game after transitioning.

Return type:

None

class src.main.Build(player, is_city)[source]

Represents the state in which the player is building a settlement or a city.

Parameters:
  • player (Player) – The player that is building the settlement or city.

  • is_city (bool) – A flag indicating whether the player is building a city or a settlement.

  • node (NodeButton) – The node where the player wants to build the settlement or city.

  • current_state (GameState or None) – The current state of the game.

draw(screen)[source]

Draws the current state of the game.

Parameters:

screen (pygame.Surface) – The screen to draw on.

handle_events(events)[source]

Handles user events while the player is building a settlement or city.

Parameters:

events (List[pygame.event.Event]) – A list of events to handle.

has_enough_resources()[source]

Checks if the player has enough resources to build a settlement or city.

Returns:

True if the player has enough resources, False otherwise.

Return type:

bool

should_transition()[source]

Checks if the current state should transition to a new state.

Returns:

True if the state should transition, False otherwise.

Return type:

bool

transition()[source]

Returns the new state if the current state should transition.

Returns:

The new state if the current state should transition, None otherwise.

Return type:

GameState or None

class src.main.BuildState(is_city, player)[source]

Represents the state of the game where the player is building a settlement or a city.

Parameters:
  • is_city (bool) – A boolean that is True if the player is building a city, False if building a settlement.

  • player (Player) – The Player object representing the current player.

  • current_state (None) – The current state of the game (unused in this class).

  • settlement_cost (dict) – A dictionary containing the cost of building a settlement.

  • city_cost (dict) – A dictionary containing the cost of building a city.

  • has_enough_resources (bool) – A boolean that is True if the player has enough resources to build the settlement or city.

handle_events(events)[source]

Handles the given events for the build state of the game.

Parameters:

events (list) – The list of pygame events to handle.

has_enough_resources()[source]

Checks if the player has enough resources to build the settlement or city.

Returns:

None

Return type:

None

should_transition()[source]

Returns True if the game should transition to a new state, False otherwise.

Returns:

True if the game should transition to a new state, False otherwise

Return type:

bool

transition()[source]

Returns the new state of the game after transitioning.

Returns:

The new state of the game after transitioning.

Return type:

None

class src.main.ChooseDesiredResources(player, trade_partner, offered_resources)[source]

ChooseDesiredResources class allows the player to select the resources they want to trade with their opponent or the bank. This class has the following methods:

init(self, player, trade_partner, offered_resources): Initializes a ChooseDesiredResources instance with the given player, trade_partner, and offered_resources.

handle_events(self, events): Handles the events that occur when the player interacts with the game screen.

draw(self, screen): Draws the ChooseDesiredResources screen on the game window.

has_enough_resources(self, player_resources, offered_resources): Checks if the player has enough resources to carry out the desired trade.

class src.main.ChooseResources(player, trade_partner)[source]

This class represents a state in which a player can choose the desired resources for a trade.

Attributes: - player (Player): The player object who initiates the trade. - trade_partner (Player): The player object who is the trade partner, if any. - offered_resources (dict): The resources offered by the trade partner, if any. - current_state (State): The current game state. - submit_button (pygame.Rect): The button used to submit the desired resources. - resource_buttons (list): The resource buttons of the trade partner the player desires. - back_button (pygame.Rect): The button used to return to the main game state. - desired_resources (list): The quantities of desired resources. - plus_buttons (list): The buttons used to increment the quantity of desired resources. - minus_buttons (list): The buttons used to decrement the quantity of desired resources.

Methods: - init(self, player, trade_partner, offered_resources): Initializes a new instance of the ChooseDesiredResources class. - handle_events(self, events): Handles events during this state. - draw(self, screen): Renders the current state of the game on the given screen. - has_enough_resources(self, player_resources, offered_resources): Checks if the player has enough resources for the trade.

class src.main.ChooseTradePartner(player)[source]

Represents the state of the game where the player can choose who to trade with.

Parameters:
  • player (Player) – The Player object representing the current player.

  • current_state (None) – The current state of the game (unused in this class).

  • trade_partner (Player) – The Player object representing the player who the current player will trade with.

  • available_players (list) – A list of tuples containing the pygame.Rect objects and Player objects representing the available trade partners for the current player.

  • screen_width (int) – The width of the game screen.

  • screen_height (int) – The height of the game screen.

  • font (pygame.font.Font) – The font to use for displaying text on the screen.

  • back_button_text (pygame.Surface) – The text to be displayed on the “Back” button.

  • back_button_rect (pygame.Rect) – A rectangular area where the “Back” button will be displayed.

draw(screen)[source]

Draws the choose trade partner screen on the given screen.

Parameters:

screen (pygame.Surface) – The pygame screen to draw the choose trade partner screen on.

handle_events(events)[source]

Handles the given events for the choose trade partner state of the game.

Parameters:

events (list) – The list of pygame events to handle.

should_transition()[source]

Returns True if the game should transition to a new state, False otherwise.

Returns:

True if the game should transition to a new state, False otherwise.

Return type:

bool

transition()[source]

Returns the new state of the game after transitioning.

Returns:

The new state of the game after transitioning.

Return type:

None

class src.main.EndMenu(players)[source]

Represents the end menu screen that displays the final scores and the winner.

Parameters:
  • players (list) – A list of Player objects representing the players in the game.

  • current_state (None) – The current state of the game (unused in this class).

  • main_menu_button_text (pygame.Surface) – The text to be displayed on the main menu button.

  • main_menu_button_rect (pygame.Rect) – The rectangular area where the main menu button will be displayed.

draw(screen)[source]

Draws the end menu screen on the given screen.

Parameters:

screen (pygame.Surface) – The pygame screen to draw the end menu screen on.

handle_events(events)[source]

Handles the given events for the end menu screen.

Parameters:

events (list) – The list of pygame events to handle.

should_transition()[source]

Returns True if the game should transition to a new state, False otherwise.

Returns:

True if the game should transition to a new state, False otherwise.

Return type:

bool

transition()[source]

Returns the new state of the game after transitioning.

Returns:

The new state of the game after transitioning.

Return type:

None

class src.main.InventoryGameState(player)[source]

A class representing the inventory game state of a player in the game.

Attributes:

player (Player): The player whose inventory is being displayed. current_state (GameState): The current state of the game. back_button (pygame.Rect): A rectangle representing the “Back” button on the screen.

Methods:

handle_events(events): Handle the events that occur during the inventory game state. draw(screen): Draw the inventory game state on the screen. should_transition(): Check if there is a transition to another game state. transition(): Transition to the next game state.

draw(screen)[source]

Draw the inventory screen with the current state of the player’s resources.

Parameters: screen (pygame.Surface): The game screen to draw on.

Returns: None

handle_events(events)[source]

Handles events for the InventoryGameState object.

Parameters:

events (list) – A list of events to be handled.

Returns:

None

should_transition()[source]

Determine whether a state transition should occur.

Returns:

bool: True if a state transition should occur, False otherwise.

transition()[source]

Return the next state to transition to.

Returns:

object: The next state to transition to.

class src.main.MainGameState(player, robber_coords=None)[source]

This class represents the main game state of a game of Settlers of Catan.

Parameters:
  • player (Player) – the player who starts the game

  • robber_coords (Tuple[int, int] or None) – the coordinates of the robber on the board, defaults to None

  • current_turn_number (int) – the current turn number of the game

  • player_turn_index (int) – the index of the current player’s turn in the list of players

  • current_player (Player) – the current player whose turn it is

  • bank (Bank) – the bank object that holds the resources available to players

  • players (List[Player]) – the list of players in the game

  • current_state (GameState or None) – the current state of the game

  • build_road_rect (pygame.Rect) – the rectangle representing the “Build Road” button on the screen

  • build_settlement_rect (pygame.Rect) – the rectangle representing the “Build Settlement” button on the screen

  • build_city_rect (pygame.Rect) – the rectangle representing the “Build City” button on the screen

  • make_trade_rect (pygame.Rect) – the rectangle representing the “Make Trade” button on the screen

  • dev_card_rect (pygame.Rect) – the rectangle representing the “Buy Development Card” button on the screen

  • bank_inventory_rect (pygame.Rect) – the rectangle representing the “Bank Inventory” button on the screen

  • dice_rolled (List[int]) – the list containing the values of the dice rolled in the current turn

  • robber_coords – the coordinates of the robber on the board

  • invent_button_rect (pygame.Rect) – the rectangle representing the “My Inventory” button on the screen

draw(screen)[source]

Draws the game board, including the tiles, numbers, settlements, cities, roads, dice, scoreboard, and buttons on the given screen.

Parameters:

screen – The pygame screen to draw on.

Ptype:

draw_buttons()[source]

Draws the buttons on the game board.

draw_dice(roll_1, roll_2)[source]

Draws the dice with the given rolls.

Parameters:
  • roll_1 (int) – the roll value of the first dice

  • roll_2 (int) – the roll value of the second dice

draw_lines()[source]

Draws the lines connecting the nodes of the tiles on the game board.

draw_roads()[source]

Draws all built roads on the game screen.

This method iterates through the built_roads list and draws a line for each road using Pygame’s draw.line method. The color of the line is set to the color of the player who built the road. The line thickness is set to 5 pixels.

Returns:

None

Return type:

None

draw_scoreboard(player_turn)[source]

Draws the scoreboard on the screen.

Parameters:

player_turn (Player) – The current player whose turn it is.

Returns:

None

Return type:

None

handle_events(events)[source]

Handles the events of the game, updating the current game state based on player interactions with the screen.

Parameters:

events (list) – list of pygame events

Returns:

none

Return type:

none

should_transition()[source]

Determines whether a transition to a new game state should occur.

Returns:

True if a transition should occur, False otherwise

Return type:

bool

transition()[source]

Returns the new game state to transition to.

Returns:

the new game state to transition to

Return type:

GameState

class src.main.NotEnoughResources(player)[source]

Represents the screen that displays a message when the player doesn’t have enough resources to perform an action.

Parameters:
  • player (Player) – The Player object representing the current player.

  • current_state (None) – The current state of the game (unused in this class).

  • font (pygame.font.Font) – The font to be used for the message text.

  • message_text (pygame.Surface) – The text to be displayed on the screen.

  • message_rect (pygame.Rect) – The rectangular area where the message will be displayed.

draw(screen)[source]

Draws the not enough resources screen on the given screen.

Parameters:

screen (pygame.Surface) – The pygame screen to draw the not enough resources screen on.

handle_events(events)[source]

Handles the given events for the not enough resources screen.

Parameters:

events (list) – The list of pygame events to handle.

should_transition()[source]

Returns True if the game should transition to a new state, False otherwise.

Returns:

True if the game should transition to a new state, False otherwise.

Return type:

bool

transition()[source]

Returns the new state of the game after transitioning.

Returns:

The new state of the game after transitioning.

Return type:

None

class src.main.PlaceRobberState(player)[source]

A class representing the state of the game where the player is placing the robber.

Parameters:

player (Player) – The player whose turn it is.

draw(screen)[source]

Draw the PlaceRobberState on the given screen.

Parameters:

screen (pygame.Surface) – The screen to draw on.

handle_events(events)[source]

Handle events for the PlaceRobberState.

Parameters:

events (List[pygame.event.Event]) – The events to handle.

should_transition()[source]

Check if the PlaceRobberState should transition to a new state.

Returns:

True if the current state is not None, False otherwise.

Return type:

bool

transition()[source]

Transition to the next state.

Returns:

The next state.

Return type:

GameState

class src.main.RoadBuildState(player)[source]

Represents the state in which the player is building a road.

Parameters:

player (Player) – The player that is building the road.

draw(screen)[source]

Draws the choose trade partner screen on the given screen.

Parameters:

screen (pygame.Surface) – The pygame screen to draw the choose trade partner screen on.

handle_events(events)[source]

Handles user events while the player is building a road.

Parameters:

events (List[pygame.event.Event]) – A list of events to handle.

has_enough_resources()[source]

Checks if the player has enough resources to build a road.

Returns:

True if the player has enough resources, False otherwise.

Return type:

bool

is_adjacent(node1, node2)[source]

Checks if two nodes are adjacent to each other.

Parameters:
  • node1 (NodeButton) – The first node to check.

  • node2 (NodeButton) – The second node to check.

Returns:

True if the two nodes are adjacent, False otherwise.

Return type:

bool

should_transition()[source]

Returns True if the game should transition to a new state, False otherwise.

Returns:

True if the game should transition to a new state, False otherwise.

Return type:

bool

transition()[source]

Returns the new state of the game after transitioning.

Returns:

The new state of the game after transitioning.

Return type:

None

class src.main.SpecialRoundGameState(player)[source]

Represents the game state for the first 2 turns of the game, during which players can build 1 road and settlement for free.

Args:

player (Player): The player whose turn it is.

Attributes:

current_player (Player): The player whose turn it is. players (list): A list of all players in the game. current_turn_number (int): The number of turns that have been played so far. player_turn_index (int): The index of the player whose turn it currently is. current_state (GameState): The current game state. node_buttons (list): A list of all the node buttons on the board. settlement_node1 (ButtonHex): The first node where the player has built a settlement. settlement_node2 (ButtonHex): The second node where the player has built a settlement. road_1 (list): The first road built by the player, represented as a list of two ButtonHex objects. road_2 (list): The second road built by the player, represented as a list of two ButtonHex objects. settlement_img (pygame.Surface): The image of a settlement.

Methods:

handle_events(events): Handles events in the game. draw(screen): Draws the game state on the screen.

draw(screen)[source]

Draws the game state on the screen.

Args: - screen (pygame.Surface): The surface on which to draw the game state.

draw_lines()[source]

Draws the lines between the nodes on the game board.

This method iterates over all tiles on the board and draws the six lines that connect the nodes of each tile. The lines are drawn in white with a thickness of 5 pixels.

handle_events(events)[source]

Handles user input events.

Args: - events (List): A list of pygame events.

is_adjacent(node1, node2)[source]

Determines whether two nodes are adjacent.

Args: - node1 (ButtonHex): The first node. - node2 (ButtonHex): The second node.

Returns: - bool: True if the nodes are adjacent, False otherwise.

should_transition()[source]

Checks whether the current state is not None.

Returns:

bool: True if the current state is not None, False otherwise.

transition()[source]

Returns the current state of the game.

Returns:

The current state of the game.

Return type:

CurrentGameState

class src.main.StartMenu[source]

Represents the start menu of the game.

:param start_button_rect : the rectangle of the ‘Start Game’ button. :type start_button_rect : pygame.Rect :param start_button_text: The rendered text of the ‘Start Game’ button. :type start_button_text: pygame.Surface :param rule_book_button_rect: The rendered text of the ‘Rules’ button. :type rule_book_button_rect: pygame.Rect :param rule_book_button_text: The rectangle of the input box for player names. :type rule_book_button_text : pygame.Surface :param input_box: The current state of the game. :type input_box: pygame.Rect :param current_state: The text entered in the input box. :type current_state : game_state :param text : The text entered in the input box. :type text : str :type type_active : bool :param checkbox_rect : The rectangle of the checkbox for AI player. :type checkbox_rect : pygame.Rect :param checked : A flag indicating if the checkbox is checked. :type checked : bool

text (str): type_active (bool): A flag indicating if the input box is currently active. checkbox_rect (pygame.Rect): The rectangle of the checkbox for AI player. checked (bool): A flag indicating if the checkbox is checked.

Methods:

handle_events(events): Handles the events generated by user interaction with the start menu. draw(screen): Draws the start menu on the screen. should_transition(): Checks if a transition to a new game state is necessary. transition(): Returns the new game state.

draw(screen)[source]

Draws the StartMenu screen onto the given screen.

vbnet

Args:

screen: The screen to draw the StartMenu onto.

Returns:

None

handle_events(events)[source]

Handle events in the game loop.

Args:

events (List[pygame.event.Event]): A list of pygame events.

returns: none rtype: none

should_transition()[source]

Check whether the current state should transition to a new state.

Returns:

A boolean indicating whether the current state should transition to a new state.

transition()[source]

Transition to a new state.

Returns:

The new state.

Return type:

GameState

src.main.create_adjacent_nodes(nodes_dict, adjacent_nodes)[source]

Create a list of adjacent node pairs based on the given nodes_dict.

Parameters:
  • nodes_dict (dict) – A dictionary of nodes, where the keys are node IDs and the values are tuples of (x, y) positions.

  • adjacent_nodes (list) – The list to append the adjacent node pairs to.

Returns:

None

Return type:

None

src.main.is_adjacent(node1, node2)[source]

Determine if two nodes are adjacent to each other on a game board.

Parameters:
  • node1 (str) – The ID of the first node.

  • node2 (str) – The ID of the second node.

Returns:

True if the two nodes are adjacent to each other, False otherwise.

Return type:

bool

src.main.main_game_loop(**kwargs)[source]

The main game loop that runs the game until the user quits.

Parameters:

kwargs (dict) – Additional keyword arguments (unused).

Returns:

None

Return type:

None

src.main.setup()[source]

Sets up the initial catan board positions and the ids for each tile

Returns:

boardList of tile objects

Return type:

list

Returns:

tile_sprites list of images for each tile

Return type:

list

Returns:

board_mapping: dictionary that maps the tile object to an id and nodes to respective coordinates.

Return type:

dictionary