This is a full-stack web application for the Salvo game, developed using JavaScript on the frontend and Spring Boot framework is used for the Java-based RESTful web server. The application uses H2 database.
Here's a list of tools you need to install in order to run this application:
- Java 17
- An IDE (ex. Intellij IDEA)
- Git
These instructions will get you a copy of the project up and running on your local machine for development and testing purposes.
- Clone the repository
git clone https://github.com/mericakgul/salvo-codeoftheweb.git
- Open the project
- Open the cloned project in the IDE that you installed.
- Start the application
- Run the following command in the directory of where build.gradle is in the terminal.
./gradlew bootRun
or
- You can use the IntelliJ gradle bootRun configuration on right top corner.
or
- You can open the Gradle tab on the right side of IntelliJ, click on 'Execute Gradle Task' button and click on 'gradle bootrun' option.
The application will be accessible at localhost:8080
. Go to http://localhost:8080/web/games.html
to play the game.
- This game can be played by only two players.
- You can see the list of the games and the scoreboard on
/web/games.html
page even if you are not logged in. - You have to log in / sign up to be able to view, join or create games on
/web/games.html
page. You might see an empty game list and scoreboard if there is no created games yet. - You can create your own game by clicking on 'Create New Game' button and wait for you opponent.
- If there are some created games listed, then you can join one of the games that have only one player by clicking 'Join' button next to the game. This one player cannot be you, you cannot play against yourself.
- You can also view the games that you are one of the players by clicking on 'View' button. Therefore, you can play more than one game at the same time.
- When you create, join or view a game, you will be directed to
/web/game.html?gp=
page. - If you are the only player in the game, then you have to wait for your opponent to play. You can place and save your ships meanwhile though.
- Select a ship and a direction on the left menu and place it on the 'Ship Grid' map. The ships placed on the map will be shown in the list of 'Placed Ship' on the left bottom side.
- You can either save(sending the ship data to database so no change can be done after saving) or remove the ship by using checkboxes and 'Remove' and 'Save' buttons. Removing will remove the checked ships from the map, so you can replace them.
- After you and your opponent save all the ships, you can start making salvo.
- The creator player can make the first salvo of each turn. If you joined to a game created by anyone else, then you have to wait for your opponent's salvo.
- You can select at most 5 locations on the 'Salvo Grid' map at the beginning. You can select as many locations as the number of your ships that are not sunk.
- You can send the salvo by clicking 'Fire Salvo' button on the left side.
- If you hit any of your opponent's ships then the hit locations will be shown in purple on the 'Salvo Grid' map. Also, same for your ships on 'Ship Grid' map.
- You can make salvo only once for each turn. When both players make their salvo, then the next turn can start. Again, the creator can fire first salvo of the next turn.
- You can see the game history at the bottom of the page after each salvo (yours or opponent's).
- The game can end with three possible results: Win, Lose and Tie. And the game can end if all the players played same amount of turns.
- If you sink all of your opponent's ship, and you still have floating ship at the end of a turn, then you win. If other way around, then you lose. If both players' ships are sunk at the end of a turn, then it is tie.
- The winner gets 1 point, the loser gets 0 point. If it is tie, both players get 0.5 point. The points are added to the scoreboard on page
/web/games.html
.
There is a Postman collection under the Resources folder to be able to test API end points. You can use it to test the API.
Any recommendation is welcome. Please contact me if you have any idea, improvement or suggestion.
Meriç Akgül