Skip to content

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

155 Commits
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

Battleship in Python & Pygame

A fully functional Battleship game — human vs. computer — written in Python with Pygame.

Video series on YouTube (in Russian)


Download & Play

Pre-built binaries are available on the Releases page — no Python required.

Platform File
macOS BattleshipGame.dmg
Windows BattleshipGame-windows.zip
Linux BattleshipGame-linux.tar.gz

macOS: open the .dmg, drag the app to your Applications folder, then launch it from there.

First launch: if macOS blocks the app with "unidentified developer", run this in Terminal:

xattr -cr /Applications/BattleshipGame.app

Then launch the app normally.

Windows: unzip the archive and run BattleshipGame.exe inside the extracted folder.

Linux:

tar -xzf BattleshipGame-linux.tar.gz
chmod +x BattleshipGame/BattleshipGame
./BattleshipGame/BattleshipGame

Run from Source

Requirements: Python 3.10+

# Clone the repository
git clone https://github.com/Perun108/BattleshipGame.git
cd BattleshipGame

# Install dependencies
poetry install --no-root

# Activate the virtual environment
source venv/bin/activate        # macOS / Linux
venv\Scripts\activate           # Windows

# Run the game
cd src && python main.py

How to Play

  • At the start, choose to place your ships automatically or manually
  • Manual placement: click and drag on your grid to draw each ship (1–4 blocks)
  • Use the UNDO button to remove the last placed ship
  • Click on the computer's grid to fire — hits are marked with X, misses with a dot
  • The computer fires back automatically after each of your shots
  • First player to sink all 10 opponent ships wins

Fleet: 1×4-block, 2×3-block, 3×2-block, 4×1-block ships (10 total)


Development

# Run tests
python -m pytest

# Run linter
pylint src/

Screenshots

Place your ships

image

Drawing ships manually

image

Game in progress

image

image

image

Game over

image image

About

🚢🎯 A fully functional Battleship game in Python using PyGame, where a human plays against the computer

Topics

Resources

Stars

Watchers

Forks

Releases

Packages

Contributors

Languages