GithubHelp home page GithubHelp logo

battleship's Introduction

BattleShip Game

Battleship game is a war game played on ocean by two players. Each player own his battle area and each player will get same number of ships where each ship may have different size placed at some position in non-overlapping fashion. Note, players cannot see each others ship's location.

Current implementation can be played with more than 2 players.

Requirements

  • JAVA 1.8

Usage

  • Git clone the source code

  • Load the project in IDE and run Main.java

    OR

  • Build the project in IDE

  • Run the Main.class in out/production using

java Main

Input

  • First line of the input contains dimensions of battle area having width and height separated by space.
  • Then the next line will have number (B) of battleships each player has.
  • Then in the next line battleship type, dimensions (width and height) & positions (Y coordinate and X coordinate) for Player-1 and then for Player-2 will be given separated by space.
  • And then in the next line Player-1โ€™s sequence (separated by space) of missiles target location coordinates (Y and X) will be given and then for sequence for Player-2.

Input Constraints

  • 1 <= Width of Battle Area (M) <= 9
  • A <= Height of Battle Area (N) <= Z
  • 1 <= Number of Battleships <= M * N
  • Type of Ship = {'P', 'Q'}
  • 1 <= Width of Battleship <= M
  • A <= Height of battleship <= N
  • 1 <= X coordinate of ship <= M
  • A <= Y coordinate of ship <= N

Sample Input

5 E
2
Q 1 1 A1 B2 A5
P 2 1 D4 C3 D1
A1 B2 B2 B3
A1 B2 B3 A1 D1 E1 D4 D4 D5 D5

File Structure

- model
  |_ board
    |_ Board
      - 2D array of BoardItems
      - width
      - height
    |_ BoardItem
      - type
  |_ game
    |_ Game
      - Array of Players
  |_ player
    |_ Player
      - playerId
      - board
      - moves
      - moveNum

controller
|_ BoardController
  - createBoard
  - setupPlayerBoard
  - addShip
  - makeHit
|_ GameController
  - createGame
  - startGame
  - getWinner
|_ PlayerController
  - createPlayer
  - makeMove
  - getNextMove
  - takeHit
  - anyShipsLeft
  - firstPlayer
  - pickNextPlayer
  - anyMovesLeft

Future Scope

  • Keep Player stats (Rating, No. of games played)
  • Get random starting player
  • Keep ship types array for more types of ships

battleship's People

Contributors

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