Welcome to Lab 3 of our Connect Four project! In this session, we delve into the heart of programming design – breaking down our game into manageable parts and understanding how these parts communicate with each other. This approach not only simplifies our coding process but also makes our code more organised and easier to debug.
In our game, each function will handle a distinct aspect of the game. Often these functions will be related to the requirements you defined earlier.
For example, if we go back to our requirements and look at the top priority items we might define the first two functions of our game:
InitialiseBoard - Sets up the 7x6 grid as a 2D list with empty values. Runs at start of game.
DisplayBoard - Represents the current state of the board on the console screen as a grid. Runs at start of game and after each move.
Break off into pairs and define all of the functions that you believe the game will need. Each function should have one purpose. If you believe the function is complex, break it further down. (e.g. When checking for a win, there is quite a lot to this).
We will rejoin as a class to compare and discuss
Data flow is how information moves through the program. Because we have divided our program into distinct functions we must pass data between them. Recall that functions may receive data in the form of arguments but also return data back.
For example:
InitialiseBoard - Returns a 2D list
DisplayBoard - Receives a 2D list
In pairs, think about what inputs and outputs (arguments and return values) each of the functions you have thought up will use.
We will rejoin as a class to compare and discuss
A structure chart is a visual representation of our program's architecture. It shows how each function is connected and interacts with others.
It starts from the main function and branches downwards through all functions, with the order represented in a left to right format.
In the example below we start with our main program "Connect Four", and from left we draw a box for the first function we will call - "InitialiseBoard".
We show that this returns a gameBoard (2D list) back to the main program, which then gets passed into the next function "DisplayBoard.
The structue chart is incomplete, but shows how it might continue along, even branching a more complex function into a couple of sub-functions.
In pairs, draw a structure chart for the Connect Four game.
Include all functions you think would be necessary along with the data flowing between them.
We will rejoin as a class to compare and discuss