Skip to content

ARegalado1/BattleShipJava

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

6 Commits
 
 
 
 
 
 

Repository files navigation

BattleShipJava

A simple command-line Battleship game written in Java.

This project uses a 10x10 grid where:

  • the player places 5 ships
  • the computer places 5 ships
  • both sides take turns attacking coordinates
  • the game ends when one side loses all ships

What the code demonstrates

  • 2D arrays
  • nested loops
  • user input with Scanner
  • random number generation with Random
  • conditionals and game-state tracking

How the board works

The game stores the board in a 2D integer array called map.

Board values:

  • 0 = empty water
  • 1 = player ship
  • 2 = computer ship
  • 3 = player ship that was sunk
  • 4 = computer ship that was sunk
  • 5 = player miss
  • 6 = computer miss

How to run

Compile:

javac Battleship.java

Run:

java Battleship

Current improvement ideas

  • extract repeated logic into helper methods
  • improve coordinate validation
  • separate board rendering from game logic
  • create a JavaScript version as a follow-up project

About

Simple Battleship Game in Java

Resources

Stars

Watchers

Forks

Releases

No releases published

Packages

 
 
 

Contributors

Languages