Guess the Song: A PHP Music Game
![SongArt](https://mttspear.com/img/song.jpg)
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
- User Authentication: Users log in or register to access the game.
- Player Selection: Once logged in, users can view a list of available players and invite them to play.
- Game Initiation: When the invited player accepts the invitation, the game begins.
The Gameplay
1. Artist Selection
- A user starts by entering the name of a musical artist.
- The application retrieves a list of related artists using an external API.
- The user selects the correct artist from this list to initiate the game.
![SongArt](https://mttspear.com/img/FirstArtistPick.png)
2. Song Guessing
- Players take turns guessing songs by the selected artist.
- The application validates the guesses against the artist's discography.
- Players earn points for each correct guess.
![SongArt](https://mttspear.com/img/GuessTheSong.png)
3. Incorrect Guesses
- If a player guesses a song incorrectly, the opposing player is given one more guess.
- After this guess, a new artist is selected to continue the game.
![SongArt](https://mttspear.com/img/PickArtist.png)
![SongArt](https://mttspear.com/img/GuessSongNew.png)
Winning The Game
- The game continues with players alternating turns and guessing songs.
- 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](https://mttspear.com/img/DatabaseStructure.png)
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.