Guess the Song: A PHP Music Game

SongArt

This PHP application is an engaging game where users compete to see who can name the most songs by a given musical artist. It combines user interaction with music knowledge, making it both fun and challenging.

How the game works

Starting the game

  1. User Authentication: Users log in or register to access the game.
  2. Player Selection: Once logged in, users can view a list of available players and invite them to play.
  3. Game Initiation: When the invited player accepts the invitation, the game begins.

The Gameplay

1. Artist Selection

  1. A user starts by entering the name of a musical artist.
  2. The application retrieves a list of related artists using an external API.
  3. The user selects the correct artist from this list to initiate the game.
SongArt

2. Song Guessing

  1. Players take turns guessing songs by the selected artist.
  2. The application validates the guesses against the artist's discography.
  3. Players earn points for each correct guess.
SongArt

3. Incorrect Guesses

  1. If a player guesses a song incorrectly, the opposing player is given one more guess.
  2. After this guess, a new artist is selected to continue the game.
SongArt
SongArt

Winning The Game

  1. The game continues with players alternating turns and guessing songs.
  2. The first player to reach 5 points wins the game.

Technologies used

Frameworks and Libraries

  • PHP 8, Laravel 8 and Vue 2: The core of the application is built using PHP for the backend and Vue.js for the frontend.
  • WebSockets: Utilized for real-time updates, ensuring users don't need to refresh pages between guesses.
  • APIs:The Discogs API is integrated to verify artists, check songs, and return images of the selected musicians.

Deployment and Hosting

  • Server: The application is deployed on an Ubuntu server.
  • Web Server: Nginx is used to serve the application.

Song Guess Validation

The application includes basic checks to ensure song guesses have not been previously used and are similar to the artist's actual songs. This is achieved using PHP’s similar_text function:

similar_text(strtolower($item["title"]), 
            strtolower($this->guess), 
            $perc); 

This function allows for matches to be loosely set based on a defined matching percentage.

Data Storage

  • Database: A relational SQL database is used for storing all game data, including users, games, and song guesses.
SongArt

Real-Time Communication

  • WebSockets: Laravel WebSockets package is employed to send real-time messages to the browser, allowing for seamless user experience without the need to refresh the page.

API Integration

  • Discogs API:This API is used to verify artists, check song titles, and fetch images of the selected musicians, enhancing the game's functionality and user experience.

Check It Out

  • Code Repository: The code is available on GitHub here.
  • Live Application: Try out the application here.