0% found this document useful (0 votes)
5 views4 pages

Coding Process Explanation

The document outlines the coding process for a Memory Match Game, detailing steps from planning to finalization. It includes setting up the project, creating utility functions, and the main program flow, which involves player interaction and game logic. The project emphasizes the use of C++ features such as 2D vectors, modular functions, and input validation.
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
5 views4 pages

Coding Process Explanation

The document outlines the coding process for a Memory Match Game, detailing steps from planning to finalization. It includes setting up the project, creating utility functions, and the main program flow, which involves player interaction and game logic. The project emphasizes the use of C++ features such as 2D vectors, modular functions, and input validation.
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
You are on page 1/ 4

Memory Match Game – Coding Process

Explanation
Step-by-Step Coding Process
1. Planning the Program

Before writing code, I:

●​ Understood the game rules (matching pairs on a 4x4 grid).


●​ Broke the logic into small tasks (initialize board, shuffle, check match, scoring).
●​ Sketched the algorithm (see algorithm document).
●​ Planned out the functions needed.

2. Setting Up the Project

●​ Created a new .cpp file for the project.


●​ Included necessary libraries:
○​ <iostream>: Input/output
○​ <vector>: 2D board storage
○​ <iomanip>: Output formatting
○​ <cstdlib> and <ctime>: Randomization
○​ <string>: Player name processing
○​ <cctype>: Input validation

3. Creating Utility Functions

3.1. getName():

●​ Prompts for the user's name.


●​ Validates the input (only letters and spaces).
●​ Capitalizes first letters (title case).

3.2. initialize():

●​ Fills a 4x4 grid with two of each number 1–8.


●​ Shuffles the numbers.
●​ Assigns the shuffled numbers to the board.
3.3. displayBoard():

●​ Displays the board to the user.


●​ Shows matched numbers, hides unmatched ones as *.

3.4. match():

●​ Accepts two coordinates.


●​ Validates input.
●​ Compares values at the coordinates.
●​ Updates matched board and adjusts points.

3.5. displayFullBoard():

●​ Shows all card values, used when giving up or ending.

3.6. toUpper():

●​ Converts a string to uppercase (used in some messages).

4. Main Program Flow

4.1. Greeting the Player

●​ Show a header with student name and game name.


●​ Ask for the player's name using getName().

4.2. Board Setup

●​ Call initialize() to set up the cards and shuffle.


●​ Initialize a parallel matched board (all false).
●​ Set points to 50.

4.3. Main Game Loop

●​ Display a menu with 4 options:


○​ Match
○​ Display
○​ Give Up
○​ Exit
●​ Use a loop and switch-case to process player choices.
●​ Keep running until the user chooses to give up or exit.

4.4. Matching Logic


●​ Allow player to enter 2 card coordinates.
●​ Check for a match.
●​ Award or deduct points accordingly.
●​ Update matched positions if successful.

4.5. Display Option

●​ Shows the current state of the board.


●​ Costs 10 points to use.
●​ Only allowed if the user has at least 10 points.

4.6. Give Up Option

●​ Shows the full solution board.


●​ Offers a chance to restart or quit.

5. Finalization

●​ When the game ends, display the final score.


●​ Return 0 to exit successfully.

Functions Used
Function Name Purpose

getName() Validates and formats player name

initialize() Randomizes and fills the game


board

displayBoard() Shows matched cards or * for


hidden

match() Handles matching logic, scoring

displayFullBoa Reveals all cards


rd()

toUpper() Converts string to uppercase

Testing the Program


●​ Manual test inputs were used (see hand-calculations).
●​ Validated inputs and outputs for:
○​ Matching cards.
○​ Using Display option.
○​ Giving up and restarting.
○​ Edge cases like selecting the same card twice.

Summary
This project reinforced:

●​ Working with 2D vectors in C++.


●​ Creating modular, reusable functions.
●​ Validating user input.
●​ Using randomization and logic flow.
●​ Building a turn-based console game with scoring.

You might also like