This is a console-based implementation of the classic Connect 4 game, featuring color-coded pieces, customizable board dimensions, save/load functionality, a high scores leaderboard, and a simple AI opponent.
ke.1.mp4
- Customizable Board Dimensions:
- The game reads and validates board dimensions from an XML file (
readXML.xml
). - If there is any issue with reading the XML file, default values are applied (height = 7 and width = 6).
- The game reads and validates board dimensions from an XML file (
- Save/Load Game:
- Players can save their current game state to a binary file (
savedgames.bin
) and load it later to continue from where they left off. - The game efficiently handles file storage, and if the save file is removed or an error occurs, a new file is created automatically.
- Players can save their current game state to a binary file (
- High Scores Leaderboard:
- The game maintains a leaderboard of high scores, stored in a binary file (
highscores.bin
).
- The game maintains a leaderboard of high scores, stored in a binary file (
- AI Opponent:
- The game includes a basic AI opponent that simulates a simple algorithm to play against the human player.
- Unique Win Evaluation:
- The game evaluates the winner based on how many sets of 4-in-a-rows are achieved in rows, columns, and diagonals.
- Redo/Undo Functionality:
- The game features redo/undo options available in both the in-game and main menus.
- Modular Code Structure:
- The code is divided into six files for better organization and maintainability:
Rxml.h
connect 4 project.c
function.h
highscores.bin
readXML.xml
savedgames.bin
- The code is divided into six files for better organization and maintainability:
Rxml.h
:- Header file for reading and validating XML data related to the board dimensions.
connect 4 project.c
:- The main source file containing the game logic, user interface, and flow control.
function.h
:- Header file containing function declarations used across the project.
highscores.bin
:- Binary file for storing the high scores leaderboard.
readXML.xml
:- XML file used for reading the board dimensions.
savedgames.bin
:- Binary file used for saving and loading game states.
-
Clone the Repository:
bash Copy code git clone https://github.com/yourusername/connect4.git cd connect4
-
Compile the Code:
arduino Copy code gcc -o connect4 connect\ 4\ project.c -lm
-
Run the Game:
bash Copy code ./connect4
- Starting the Game:
- Run the executable and follow the on-screen instructions to start a new game or load a saved game.
- Gameplay:
- Players take turns dropping colored pieces into the columns of the board.
- The goal is to connect as many sets of four of your pieces vertically, horizontally, or diagonally before your opponent does.
- Saving and Loading:
- You can save the current game state at any time and load it later to continue playing.
- AI Opponent:
- If you choose to play against the AI, the game will automatically simulate the AI's moves based on a simple algorithm.
- In-Game Menu Options:
- During the game, you can access the in-game menu for additional options:
- c: Continue the game.
- u: Undo the last move.
- r: Redo the last undone move.
- s: Save the current game state.
- e: Exit the game.
- You can access the main menu for options such as starting a new game, loading a game, viewing top players, and quitting the game.
- During the game, you can access the in-game menu for additional options: