Skip to main content

A Battleship game using Python and Flask

Project description

BATTLESHIP GAME

Table of contents

Introduction

This is a Python implementation of the Battleship game, with a Flask UI.

Description

Players can place their ships on a board, and can play against an AI opponent (or multiplayer in a future iteration!), taking turns to sink eachothers ships until one or the other sinka all ships, declaring one side the winner!

There are 3 different versions of the game. One is a simple version, where you can attack ships on a predetermined board, giving coordinates in the terminal. The second is with an AI opponent, which can attack your board and you aim to destroy all the opponents ships before it destroys yours, which is also in the terminal. The third is the main game which can be played on the browser against the AI opponent.

Prerequisites

To install Battleship, you will need to have python installed. Download python here

  • Python 3.7 or higher

Installation

Flask is an external python library and so needs to be installed using pip.

  1. Type cd followed by a space in the command prompt window
  2. Drag and drop the battleship folder into the window and press Enter
  3. Type in pip install -U Flask to download flask

For more information check out the official flask documentation:

Getting started

To play the Battleship game, follow these steps:

  1. Type cd followed by a space in the command prompt window
  2. Drag and drop the battleship folder into the window and press Enter

Windows:

$ cd C:\Users\user\Downloads\battleship

MacOS:

$ cd /Users/username/Downloads/battleship
  1. Run the main application:
$ flask --app main run
  1. Open your web browser and navigate to http://127.0.0.1:5000/placement
  2. Click to place your battleships, with 'r' or 'R' to rotate the ships and start the game.

Testing

All tests are present in a tests folder where each file contains the keyword "test".

Pytest is an external python library and so needs to be installed using pip.

$ pip install pytest

You will also need to install these plugins:

$ pip install pytest-depends

$ pip install pytest-cov

To run the tests, use the following command:

Windows:

$ python -m pytest 

MacOS:

$ pytest

Details

Project details


Download files

Download the file for your platform. If you're not sure which to choose, learn more about installing packages.

Source Distribution

Battleship_yousufaa-0.0.1.tar.gz (9.6 kB view hashes)

Uploaded Source

Built Distribution

Battleship_yousufaa-0.0.1-py3-none-any.whl (8.7 kB view hashes)

Uploaded Python 3

Supported by

AWS AWS Cloud computing and Security Sponsor Datadog Datadog Monitoring Fastly Fastly CDN Google Google Download Analytics Microsoft Microsoft PSF Sponsor Pingdom Pingdom Monitoring Sentry Sentry Error logging StatusPage StatusPage Status page