Git Product home page Git Product logo

battleships's Introduction

Battleship game in Python

I created this battleship game in Python, it runs in a custom mock terminal designed by Code Institute.

The game is hosted on Heroku

Here is the live version of my project

Screenshot of the landing page on different devices

How to play

I designed my battleship game on the classic version, I brushed up on the rules on Wikipedia.

In my version the computer board is randomly generated and the user of the website gets to place their own ships on the battlefield. The ship locations are marked by an @ sign, guesses/misses are marked with a O and hits are marked with a X. The player and the computer take it in turn to guess locations of the ships until either side has hit all of the opponents ships.

Features

Battleship load screen

  • Shows to user when game has loaded.

Screenshot of loading screen

Rules screen

  • Rules are typed out to user of the website
  • Pauses before clearing to give user time to read the rules.

Screenshot of the rules screen

Name screen

  • Asks the user for their Name.
  • Store the name in memory and uses it to reply to the user.
  • Personalises the game to the user.
  • Asks the user if they want to play.
  • If user says yes then onto placing ships.
  • If user replies no then onto a goodbye screen.

Screenshot of the name screen Screenshot of the goodbye screen

Place ships screen

  • Asks the user to place their ships.
  • If incorrect input then the user is alerted and asked to re-input the selection.
  • Ships marked with an @ sign.

Screenshot of ships being placed Screenshot of placed ships Screenshot of ship overlap Screenshot of axis select

Aiming at enemy ships

  • The user gets to pick where to aim their shots.
  • Misses marked with O.
  • Hits marked with X.
  • Feedback given if shots hits or missed.

Screenshot of shot selection Screenshot of shot selection Screenshot of succesful hit Screenshot of player miss hit Screenshot of player been hit Screenshot of computer missed shot Screenshot of hits and misses

Game over screens

  • When all ships are sunk a win or lose screen appears.
  • User will be asked if they want to play again.

Screenshot of win screen Screenshot of lose screen

Flow plan

To assist me with what I wanted to achieve with my battleship game I created a flow chart using Lucid . This helped me to visualize what I wanted my game to encompass before I started to write code.

Flow chart of battleship game in python

Testing

I tested my code throughout this project by:

  • Testing individual functions to ensure they worked.
  • Using Pep8 within my gitpod workspace.
  • Playing through my game and entering incorrect inputs.
  • Tested within my local terminal and the Code Institute Heroku terminal on Heroku platform.

Bugs

Solved bugs

  • When I was writing the code I was getting errors on my place_ship function. I fixed this by correcting the if/else statement within the while loop.
  • I kept my functions to as as small as possible so any errors could be fixed quickly.

Remaining bugs

  • To the best of my knowledge and through extensive testing no bugs are remainig.

Validator testing

  • PEP8 within the gitpod terminal shows no errors remaining.
  • CI Python linter shows no errors as well.

Screenshor of no errors on main code Screenshot of letters to numbers no errors Screenshot of colour module no errors Screenshot of battle boards no errors

Deployment

  • Steps for deployment
    • Fork or clone this repository
    • Create a new Heroku app
    • Set the build packs to Python and NodeJs in that order
    • Link the Heroku app to the repository
    • Click on Deploy

Credits

  • Code Institute for the deployment terminal
  • Wikipedia for details on the battleships game
  • When runnign into problems I used
    • The Code Institute slack channel
    • Stack Overflow
    • I also googled for solutions as well
  • I used Text2art to write the large text within my battleship game.

Acknowledgements

I would like to thank my mentor Victor Miclovich who has given me great advice and is very clear in explaining processes. I would also like to thank the Code Institute Slack community who are always ready to help if needed. Also the code institute slack community who are great and there is always someone ready to help if you are stuck or just to pick you up if you're feeling under the pressure.

battleships's People

Contributors

carl2087 avatar

Stargazers

Graham Williamson avatar  avatar

Watchers

 avatar Graham Williamson 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.