Coder Social home page Coder Social logo

sea-battle's Introduction

Sea Battle

Sea Battle is a two-player strategy game where each player tries to sink the enemy's ships by bombing their grid. The game is implemented in Java, JavaFX, and Hibernate ORM, using sockets for network communication. It was a project for the Advanced Programming course with Java at Sharif University of Technology. the code may have bugs and some features may have not been implemented completely.

main gameplay

Game Logic

The game is played on two 10x10 grids, one for each player. Each player has a fleet of ships of different sizes and shapes: one battleship (4x1), two cruisers (3x1), three destroyers (2x1), and four frigates (1x1). The ships are placed randomly on the grid by the server, with no adjacent ships. Each player can request a new placement up to three times. Each player has 30 seconds to check their placement and request a new one if needed. There is also a button to declare readiness for the game. The game starts when both players are ready.

waiting

The game is turn-based. Each player has 25 seconds to bomb a cell on the enemy's grid that has not been bombed before. If the bomb hits a ship, the player gets another turn. A ship is sunk when all its cells are bombed. In that case, all the adjacent cells are also bombed. The player who sinks all the enemy's ships first wins the game.

main gameplay

Game Structure

The game has a client-server architecture. The server manages the network connections and the user accounts. The client connects to the server automatically and provides a user interface for creating or logging into an account. The account information includes the username, password, number of wins, number of losses, and score. The score is the difference between the number of wins and losses.

server logs

The game menu has options for starting a new game, watching other games, viewing the score table, and viewing the user information. The server matches the players who request a new game and assigns them randomly as the first or second player. The server also notifies the players of their turn and the game result. The game screen shows the grids of both players (without revealing the enemy's ships) and the current turn.

The game supports multiple concurrent games. The players can watch other games in progress and see some details of the game, such as the number of moves, the number of sunk or remaining ships, and the number of bombs that hit the ships. The score table shows the online or offline status and the score of each user in descending order. The user information shows the username, number of wins, number of losses, and score of the current user.

both gameplay

Data Persistence

The server saves the information of each account in a database using Hibernate ORM. The information is preserved after the user logs out and can be retrieved when the user logs in again(config your Postgresql info in hibernate.xml file on the server resources folder).

login

Error Handling

The game handles errors in different situations. If a player disconnects during a game, the server gives them one minute to reconnect and resume the game. The other player is informed of the disconnection and the waiting time. If the disconnected player does not reconnect within one minute, the other player is declared the winner. The client also shows an appropriate message when disconnected from the server and tries to reconnect. If the client is closed completely, the user has to log in again to resume the game. The game also handles errors related to creating or logging into an account, such as duplicate usernames or wrong passwords, and shows an appropriate error message.

Assets

Most of the graphical assets of this game are borrowed from the original game, SeaBattle2 and All rights reserved to Byril.

sea-battle's People

Contributors

ammahmoudi 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.