Giter VIP home page Giter VIP logo

battleships-12's Introduction

Battleships

Welcome to my Battleships game.

Battleships is a strategy type guessing game whereby two players attempt to destroy the opposing players fleet of ships. They do this by alternating guesses of the coordinates of the concealed ships set out on a grid.

The object of this project was to build a game which could be interactive, where the player is able to play against the computer, obtain feedback on progress throughout the game and understand who has won and lost the game at the end.

This project uses the programming language of Python.

A live website can be found here

Website Preview Website Preview

Site Design Considerations

User Expectations

  • The game should be engaging for the player, providing fun and joy.
  • It should define a clear goal for the player.
  • It should clearly display a winner and a loser after each turn.
  • It should be challenging and give incentive to the player to want to return to play again.

Colour Scheme and Font

To provide an improved user experience and a point of difference I decided to implement a colour scheme to the game. I hoped that this would provide a slightly more interesting visual experience for the player and also give a better definition to the functions when there are run.

  • Player input requests and messages in Purple colour (\033[1;35;10m)
  • Win messages in Cyan colour (\033[1;36;10m)
  • Lose messages in Red colour(\033[1;31;10m)

Site Skeleton

Lucidchart was used to help create a flow chart diagram for the game. It was useful as it enabled me to clearly play out all the logic and possible scenarios to plan for the game

Lucid Chart Image

Features

Player welcome message and game instructions

Welcome Image

Player board

Player Board Image

Computer Board

Computer Board Image

Player sunk ship message

Game Play Image

Computer sunk ship message

Game Play Image

It's a draw message

Game Play Image

Player winner message

Game Play Image

Play again message

Game Play Image

Technologies Used

During the making of this game I used the following:

  • Python3

    Was the language used to create the game

  • GitHub

    For storing project code written in gitpod

  • GitPod

    For use as the code editor for the project code

  • Lucid Chart

    For creating flow chart for game planning

  • Replit

    To test code for errors or problems

  • PEP8 Validator

    For checking python code best practices and validation

  • Heroku

    To deploy project into live environment

Testing

Code was first tested using the PEP8 Online validator. This threw up some errors with the length of certain lines within the code being too long as detailed below:

Pep8 Errors

After this was corrected no further issues were found in the code as detailed in the screenshot below:

Pep8

For player name input, fields were tested using numbers, special characters and blank inputs.

Name Validation

For letter inputs, fields were tested using letters outside of the range, special characters, blank and number inputs.

Letter Validation

For number inputs, fields were tested using numbers outside of the range, special characters, blank and letter inputs.

Number Validation

For same guess inputs, fields were tested using a guess which had already been inputed.

Same Guess Validation

For yes or no play again inputs, fields were tested using letters and numbers outside of the range, blanks and special characters inputs.

Yes / No Validation

Developement

I played the game incrementally throughout development to test the features and ensure that they responded how I expected. If a feature was not responding how I expected it to then I would go back and check the code to resolve the issue.

Bugs

  • When testing the game I noticed that the computer guess was mirroring the player input guess therefore not drawing a guess randomly. This was caused by the code checking whether the computer has hit or miss having the incorrect variables passed in for the array indices. It should have been computer row guess, rather than player row guess. This was corrected and code worked as expected.

  • During coding, an issue arose with the line length on certain lines. Upon checking the PEP8 guidelines, I discovered the 80 character advisory limit. Where possible, print statement strings were split with the use of double quotation marks to denote the continuation of the line. Backslashes were not used in string statements as this resulted in spacing errors on the displayed result.

  • Upon adding colours I noticed that the background colour was displaying as a dark grey and not black as intended. This was resolved by changing the background colour from 40m to 10m.

  • When testing the game I found that the "Play Again" function was not working properly, the game would not let you exit, instead just looping back round to begin the game again. This was corrected by breaking the while loop by adding a new global variant and setting this to true. Code then worked as expected.

Deployment

To deploy my final project to the cloud I used Heroku. To do this I had to:

  1. Push the latest code to GitHub.
  2. Go to Heroku.
  3. Select new in the top right corner.
  4. Create new app.
  5. Enter the app name and select Europe as the region.
  6. Connect to GitHub.
  7. Search for repo-name.
  8. Select connect to the relevant repo you want to deploy.
  9. Select the settings tab.
  10. Go to Config Vars and add PORT 8000.
  11. Add buildpack.
  12. Select Python, then save changes.
  13. Select Nodejs, then save changes.
  14. Make sure that they are in this order, Heroku/Python is at top followed by Heroku/Nodejs.
  15. Navigate to the deploy tab.
  16. Scroll down to Automatic Deploys and select.
  17. Go to Manual Deploy and select deploy branch.

The live link can be found here - (https://battleships-saramorrin.herokuapp.com/)

Credits

  • An article on Stack Abuse helped me to understand how to implement colours into my code.

  • This article on Real Python helped my understanding of how to write Python code following best practices and guidelines.

  • I used Stack Overflow to further my knowledge of classes and functions from previous questions asked by the community.

battleships-12's People

Contributors

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