-
Notifications
You must be signed in to change notification settings - Fork 1
Vidhi Written Create Task
Video: https://youtu.be/Xy_F5jf8m5w
| Row Description | CB Requirements | How our program meets this requirement |
|---|---|---|
| Program Purpose and Function | Input, Output, Program Functionality | Purpose: The purpose of our project is to make a modified Tic Tac Toe game with various levels in order to entertain users. Functionality: The program will display a gameboard with both rows and columns. The user is first prompted for their name and the program greets the user. The player places an "O" character and the computer places an "X" character by clicking somewhere on the gameboard. The player can play in an easy level (3 x 3 board) or a hard level (5 x 5 board). The scores are recorded for the player in the top left of the screen. If a three in a row is found, the user is told if they have won or lost. If the user wins, a message and gameboard with a blue background appear. If the user loses, a message and gameboard with an orange background appear. If there is a tie, a message and gameboard with a purple background appear. Inputs and Outputs: The user inputs their name at the start of the game and the user is greeted as an output. The user can click on a grid square to input the "O" character and the gameboard with this character showing is the output. The user clicks on a hard or easy level button (as an input) and the changed gameboard size displayed to the user is the output. |
Data Abstraction: Program code segments that show data in a list and how the data is being used to fulfill the program's purpose
The WinCombos list/array is used to determine which combinations on the board are winning combinations. The data these lists stores are the indexes of the boxes that represent winning combinations. The WinCombos lists help manage program complexity and assist the program's carrying out of its function.
The WinCombos list/array fulfills the program purpose because of how it is used as an argument in the function pictured above. The array is used to find which player has won by finding which character (if any has three in a row) by comparing the indexes entered by the user and computer to that of WinCombos. If the indexes match that of WinCombos, the program uses a ternary operator to decide whether a blue or orange background should be displayed for both the message and the gameboard. These lists also help manage complexity because if they were not there, it would be much harder to compare winning indexes.
Managing Complexity: Program code segment that shows a list being used to manage complexity and explains how this list manages complexity
The WinCombos lists manage complexity because it allows the program to compare winning indexes and make a judgment whether the player has won, lost, or tied. Without this list, we would not be able to assess which combinations on the board are winning combinations. The program code would also not be able to be written without this list because without it, the program will not know which message to display, which color to change the background, and which player has won.
Procedural Abstraction: Procedure with a parameter and show where the program is being called
One of the procedures we wrote was the CheckTie procedure. The procedure's goal is to check whether there has been a tie between the two players. The procedure starts by checking if there are any empty squares. If there are no empty squares, this means there has been a tie between both players. If there are no empty squares, the program iterates through each box on the gameboard (i) which is also the parameter. It turns each of these boxes purple (the color for a tie game). It also makes it so that the user can no longer click on the board by making turnclick false, as the game has ended.
The CheckTie procedure is called in the turnClick function. In this function, the procedure is called when there is no tie, as shown from the ! before the procedure has been called. If there is no tie, it means that it is the computer's turn to play. This means that the computer looks for empty spaces and places the "X" where there is the best spot. The parameter for this function is the square parameter.
Algorithm Implementation: Sequencing, Selection, and Iteration
This procedure shows iteration because if there are no empty squares detected by the program, the program turns each of the game board squares purple and stops the user from being able to click on the squares. When it is turning the squares purple, it uses a for loop to turn each square purple until the number of squares equals i. If it does not, the loop will keep looping through the code until this condition is met.
This procedure shows selection because there are two possibilities for the outcome of the function. If there are no squares detected by the program, the program turns each of the game board squares purple and stops the user from being able to click on the squares. If there are empty squares detected by the program, these steps are not taken.
This procedure shows sequencing because multiple steps are taken during the procedure, all are taken step by step. The first step that is taken is checking whether or not there are any empty squares. The next step is looping through each of the squares until all squares are purple. The last step is looping through each of the squares until none of them can be clicked on.
Testing: two calls to the procedure in 3C and different arguments, conditions, and results
The first call checks whether the game has been won, which is the argument. It uses this result to stop the game. The second call compares the entries of the user's characters to the winning combinations. The index and win are the arguments.
The results of the first call: the function checks the indexes of the winCombos list/array and compares it to the indexes that the user has inputted for their character. If the indexes match, and a character has won, the program uses a ternary operator to display a blue grid/message if the user has won and an orange grid/message if the computer has won.
The results of the second call is for the ending of the game. We start by getting the indexes with the win combinations from the WinCombos lists mentioned in 3C. We then check the places that the players have put their characters and compare every spot there is a character with the winning combinations, which it proceeds to loop through. The procedure then identifies which combinations led the user to win and the player that has won (user or computer). It uses a ternary operator to display the winning combo and the player that has won. It returns the gameWon function (displays message and changes background).