Giter Club home page Giter Club logo

battleships-2's Introduction

You Sunk My Battleship!!

You sunk my battleship is a python terminal game, which runs in the Code Institute mock terminal on Heroku.

Can you win against the computer? Find and sink the battleship hidden on the playing board and the glory is yours!!

Please view my live project here

Screenshot of live project below:

New game screenshot

Purpose of this project

I designed this project to be a simplified version of the game battleships. It can be enjoyed by any user who may come across my site. It is simple, fun and if you know the classic battleship game there is almost no learning curve.

Learn about the classic battleships game here

User Stories

  • As a fist time user of this game I want the experience to be fun, stress free and easy to play. I feel that I have achieved this through simple to follow prompts and full exception handling which will always bring the user back on track to secure that win against the computer.
  • As a user I want to be able to enter my name and have it displayed on screen while the game is running.
  • As a user I want to be able to guess the coordinates of where I think the battleship is and also let me know if I have missed or hit the ship.
  • As a user I want the game to alert me if I have won or lost and reveal the positoin of the ship on the playing board.
  • As a gamer I want there to be a specific amount of guesses allowed before the game is over so it is a challenge to win which will encourage me to play again.
  • As a gamer I would expect to be penalised if I make a duplicate guess, if my guess is out of the bounds of the playing board or if I enter a non numeric value. The penalty would be to lose a turn.

Features

Existing features

  • The player is greeted with a welcome message, the game board is described, the coordinates layout is explained and the player is told they only have 5 guesses to try and win.
  • The player is then asked to input their name and upon entering valid data they are wished good luck in the battle against the computer.
  • The computer generates a 5 x 5 square board.
  • A ship is randomly placed and hidden within the board
  • The user is then prompted to guess a row then a colum to try and sink the ship.
  • Once valid coordinates are entered the user is told if have missed or a hit the battleship.
  • If the user missed, the board is printed again, updated with the guessed coordinates replacing the "#" with a "@"
  • If its a hit the user is congratulated on their win and the program ends.
  • After a miss the computer will then take a turn and the board is updated accordingly also.
  • The game will continue until there is a hit form the user or the computer.
  • The game will also end if the amount or turns exceeds 5 and the user is encouraged to play again.
  • Included in the code is input validation / exception handling. User can only use integers when guessing, the guesses must be within the bounds of the playing board and the user cannot make the same guess twice. If any of these actions are executed an on screen warning explains that the user loses a turn and is asked to guess again until there is no more guesses.

Future Features

  • I would like to add two playing boards, one for the user and one for the computer.
  • I would also like to have multiple ships on each board with the possibility of user placement.

Technology

  • The only coding language used in this project was the Python programming language.
  • Heroku - This clound based platform was used to deploy the project.
  • GitHub was used to keep a history of the development process.
  • A GitPod workspace was used to write and test all code written during this project.

Testing

Code Validation

  • All Python code used in this project was passed through the PEP8 online code validator and no errors were returned.
  • Other testing was done directly in the GitPod terminal throughout the development process as well as using print statements to check the code was working along the way.

Screenshots

Computer win screenshot:

Here we see how the board is updated with the location of a battleship hit marked with an "*". In this particular case the computer won but if the user wins the boards prints out the same way but with a different message above it. Computer win screenshot

Invalid guess screenshot:

Here we see what happens when a user enters a string value instead of a number. This counts as a turn for the user and they can only do this 5 times before the program ends. Invalid guess screenshot

Miss screenshot:

Here we can see that the player has missed and the playing board has been updated with the guessed coordinates by replacing the "#" with a "@". This will continue for each guess until the turn limit is reached or there is a winner. Miss screenshot

No more guesses screenshot:

Here we see the board is updated with multiple computer and player misses. The user is told they have no more guesses and is wished luck in their next attempt. No more guesses screenshot

Out of bounds guess screenshot

Here we see what happens if the user makes a guess which is off the board. They are informed that they lose a turn and to only use numbers within the allowed range. Out of bounds guess screenshot

Fixed Bugs

I ran into a couple of bugs while writing this game.

  • I tried using a for loop to keep track of the guesses but it did not work the way I intended. My solution was to create a global variable and increment it by one every time the user made a correct guess, duplicate guess or an out of bounds guess.
  • Another bug I came across was after creating the check_row and check_col functions the if statements in the player_guess funtion returned an error as I had converted the variable values. I ammended this by wrapping the variables within the function with int() methods so they were read as integers.
  • The last bug I came across was that if the user kept guessing string values the program would never end so I added the turn counter to check_row and check_col to limit string guesses to 5.

Deployment

This project was built entirely using GitHub and GitPod.

  • First I created a repository in my GitHub account and named it appropriately.
  • Then I was able to create a GitPod workspace which included the Code Institute template where I was able to write and save all my code progress.
  • This service has been invaluable to creating all my projects and I would be lost without it.

This project was deployed using Code Institute's mock terminal for Heroku. Steps for deployment on the Heroku site are as follows:

  • Create a new app on the Heroku site
  • Add build packs ensuring Python is at the top and nodjs is below that.
  • Click on the deploy tab and choose github as the deployment method.
  • Add the project repository and then you can deploy.

Credits

  • Code Institute for deployment terminal.
  • Wikipedia for info on Battleship game and Python coding language.
  • Stack Overflow for queries on code syntax.
  • GitHub for creating project repository.
  • Gitpod for building the project in a workspace.
  • Heroku for deployinig the completed project.
  • PEP8 for validating all code within the project.

battleships-2's People

Contributors

markreddy87 avatar

Watchers

 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.