Giter Site home page Giter Site logo

dor-sketch / snakes_ladders Goto Github PK

View Code? Open in Web Editor NEW
0.0 1.0 0.0 4.31 MB

Enhanced with Qt6, WebAssembly-ready, and simplified CMake builds.

License: MIT License

Makefile 2.21% C++ 97.77% C 0.02%
cairo cairo-drawing cpp game-development gtk3 cmake qt6

snakes_ladders's Introduction


Snakes and Ladders Game

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.

Table of Contents

Features

  • Classic Snakes and Ladders gameplay
  • Musical notes played based on player positions
  • Graphical user interface using GTK
  • Optional MIDI file support for generating notes

Prerequisites

  • C++ compiler (e.g., g++)
  • GTK development libraries
  • CMake (optional, for building)
  • MIDI library (optional, if using MIDI files)
  • OpenCV (optional, for image processing)

Installation

Step 1: Install Dependencies

For Ubuntu:

sudo apt-get update
sudo apt-get install build-essential libgtk-3-dev cmake

For macOS:

brew install gtk+3 cmake

Step 2: Build the Project

The project can be built using the provided Makefile or CMakeLists.txt file.

Using Makefile

make <flags>

where <flags> can be:

  • USE_MIDIFILE=1: Enable MIDI file support
  • USE_OPENCV=1: Enable OpenCV support - not implemented yet

Playing the Game

  1. Rolling the Dice: Click the "Roll" button to roll the dice and move your player.
  2. Winning the Game: The first player to reach the last cell wins the game.
  3. Musical Notes: Notes are played based on the player's position on the board.

MIDI Support

This project optionally supports using MIDI files to generate the musical notes. To enable this feature:

  1. Install MIDI Library:

    • Follow the instructions in the MIDI library's documentation to install it.
  2. Define the USE_MIDIFILE Macro:

    • Add #define USE_MIDIFILE at the top of game.cpp or pass it as a compiler flag (-DUSE_MIDIFILE).
  3. Link MIDI Library:

    • Ensure that the MIDI library is linked during the build process. Modify the build commands or CMakeLists.txt accordingly.
  4. Set MIDI File Path:

    • Modify the generateNotes function in game.cpp to use the desired MIDI file path.

Example

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;
}

License

This project is licensed under the MIT License. See the LICENSE file for details.

Contributing

Contributions are welcome! Feel free to create an issue or submit a pull request if you have any improvements or bug fixes.

snakes_ladders's People

Contributors

dor-sketch avatar

Watchers

 avatar

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.