Enhanced with Qt6, WebAssembly-ready, and simplified CMake builds
This project is an implementation of the classic Snakes and Ladders game with a twist - it incorporates musical notes that are played as the players move across the board. The game uses GTK for the GUI and optionally supports MIDI files to generate the notes.
- Classic Snakes and Ladders gameplay
- Musical notes played based on player positions
- Graphical user interface using GTK
- Optional MIDI file support for generating notes
- C++ compiler (e.g., g++)
- GTK development libraries
- CMake (optional, for building)
- MIDI library (optional, if using MIDI files)
- OpenCV (optional, for image processing)
For Ubuntu:
sudo apt-get update
sudo apt-get install build-essential libgtk-3-dev cmake
For macOS:
brew install gtk+3 cmake
The project can be built using the provided Makefile
or CMakeLists.txt
file.
make <flags>
where <flags>
can be:
USE_MIDIFILE=1
: Enable MIDI file supportUSE_OPENCV=1
: Enable OpenCV support - not implemented yet
- Rolling the Dice: Click the "Roll" button to roll the dice and move your player.
- Winning the Game: The first player to reach the last cell wins the game.
- Musical Notes: Notes are played based on the player's position on the board.
This project optionally supports using MIDI files to generate the musical notes. To enable this feature:
-
Install MIDI Library:
- Follow the instructions in the MIDI library's documentation to install it.
-
Define the
USE_MIDIFILE
Macro:- Add
#define USE_MIDIFILE
at the top ofgame.cpp
or pass it as a compiler flag (-DUSE_MIDIFILE
).
- Add
-
Link MIDI Library:
- Ensure that the MIDI library is linked during the build process. Modify the build commands or
CMakeLists.txt
accordingly.
- Ensure that the MIDI library is linked during the build process. Modify the build commands or
-
Set MIDI File Path:
- Modify the
generateNotes
function ingame.cpp
to use the desired MIDI file path.
- Modify the
Here is an example of how to modify game.cpp
to use a MIDI file:
#define USE_MIDIFILE
#include "midifile/include/MidiFile.h"
// Modify generateNotes function
std::vector<std::vector<int>> Game::generateNotes(const std::string &midi_file_path) {
std::cout << "MIDI file path: " << midi_file_path << std::endl;
if (midi_file_path.empty()) {
std::cerr << "MIDI file path is empty" << std::endl;
return generateNotes(10);
}
// Open the MIDI file
smf::MidiFile midi_file;
if (!midi_file.read(midi_file_path)) {
std::cerr << "Failed to open MIDI file" << std::endl;
return generateNotes(10);
}
// Create a 2D vector to hold the notes
std::vector<std::vector<int>> notes;
// Read the MIDI messages
for (int track = 0; track < midi_file.getTrackCount(); ++track) {
for (int event = 0; event < midi_file[track].getEventCount(); ++event) {
if (midi_file[track][event].isNoteOn()) {
int note = midi_file[track][event][1];
notes.push_back({note});
}
}
}
return notes;
}
This project is licensed under the MIT License. See the LICENSE file for details.
Contributions are welcome! Feel free to create an issue or submit a pull request if you have any improvements or bug fixes.