Giter VIP home page Giter VIP logo

damianjacob-ms3-battleship-game_marresub's Introduction

CI-MS3-battleship

Table of contents generated with markdown-toc

See live version of app: https://battleship-strategy.herokuapp.com/

The goal of this project is to create an interactive battleship game in a Python terminal that stores certain information about each game in a separate Google sheet.

How to play

In this game you will have to fight against the computer in a classical battleship game. First of all, the game will ask you to insert your name. You can then choose whether you'd like to place your ships on the board of if you'd like them to be placed on the board randomly. The board consists of a 5x5 square, with coordinates for each field: a letter from A to E for columns and a number from 1 to 5 for rows. In order to select a coordinate, the correct format is letter space number (A 1). If this format is not followed, an error message will be thrown. Once you have placed your ships, the game starts: Either you or the computer start and you have to try to guess the positions of your ships by entering the coordinates. Whoever destroys the fleet of their enemy first, wins! At the end you will be able to see some stats about the game and how you did compared to the average of all the games that have been played before.

Technologies used

I used python to create the code of the game. I imported some libraries: random for the creation of random numbers, gspread so that I could access my Google Sheet file, sys so that I could append the file path to my second python module, where I stored the class definition. I used VSCode and deployed the game on Heroku.

Features

Existing features

Player board:

Screenshot of Player board player board

Computer board:

Screenshot of Computer board computer board

Error messages:

Format error message error message screenshot
Invalid input error message error message screenshot
Same coordinate error message error message screenshot

Game stats table:

Screenshot of game stats game stats screenshot
Screenshot replay question replay question screenshot

Game messages:

Game messages game messages screenshot
Game messages game messages screenshot

Testing

I did multiple rounds of manual testing until there were no more errors or bugs. Most of the testing was done in VSCode terminal, and a few last rounds in the Heroku terminal.

PEP8

No errors were returned when passing through the official PEP8 validator

Screenshot of PEP8 validator PEP8 validation
Screenshot 2 of PEP8 validator PEP8 validation

Fixed errors

  • I fixed the line lenghts, which was the most frequent error. After fixing that, i had to reformat some of the strings that are printed to the terminal.
  • I deleted some whitespaces.
  • I fixed PEP8 Warning W503: Line break occurred before a binary operator. I moved the binary operator back and set the line break after the operator, which improved readability.

Bugs

There were many minor bugs during the creation of this project. The biggest one was the following: The file would seemingly stop running in the middle of a game, without any error message. After adding some print statements, I discovered that the reason was in the guess_player_ships method: that method used to come up with a random coordinate and then run through a loop: if that coordinate had already been hit, the loop would re-run until a non-hit coordinate would appear. I didn't think this through because obviously with every turn the likelihood of finding a coordinate that had not been hit yet decreases, so that function entered an infinite loop. I fixed the bug by simply creating a list with all the coordinates, pull a random coordinate, and then delete that coordinate from the list.

Deployment

The app was deployed to Heroku. See the live link: https://battleship-strategy.herokuapp.com/

Credit

Content

I often referred back to various lessons from Code Institute and to W3schools or MDN. Stackoverflow was a useful source of information, especially for resolving bugs.

Acknowledgements

I would like to thank my co-students who took their time to answer my questions or doubts on Slack, my mentor Mo Shami who gave me precious advice and lent me his expertise and the tutors of Code Institute who have saved me when i was stuck, in particular John who helped me out with a last-minute problem with the deployment. Thank you!

damianjacob-ms3-battleship-game_marresub's People

Contributors

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