Giter Club home page Giter Club logo

portfolio-project-57's Introduction

BATTLESHIPS

Battleships is a python terminal game. It runs in the Code Institute mock terminal on Heroku.

The user can try to defeat the computer by locating all his battleships before the computer finds his.

The live link ca be found here - BATTLESHIPS

Screenshot of the app on several screen sizes

How to play


Battleships is based on a classic pen-and-paper game that some of you may remember from your childhood.

In my version, the player enters his name and 2 boards with randomly placed ships are created.

The ships are displayed with an '@' on a 5x5 board.

The player sees only his own ships, not those of the computer.

On the edges of the board are the numbers 1-5 and the letters A-E, this allows to designate each field.

Guesses are marked with a '/', hits with an 'x'.

The player is first to guess, then the computer.

The player who destroys all enemy battleships first wins.

Features


Existing Features

  • Random board generation

Ships are randomly distributed on the board of the player and the computer.

The player sees only the position of his own ships.

Screenshot of the board feature

  • Play against the computer

  • Accepts user input

Screenshot of the input feature

  • Input validation and error-checking

The coordinates must exactly match a coordinate present on the board.

You can not enter the same guess twice.

Screenshot of the input validation feature

  • Data maintained in class instances

Future Features

  • Allow player to select the board size and number of ships
  • Allow player to position ships themselves
  • Have ships larger than 1x1

Data Model


I have decided to use a board class as a data model. The game creates 2 instances of the board class, for user and computer.

The board class stores the game board, positions of the ships, positions of the hits, positions of the guesses and the player name.

The class also has methods that the game needs to work. These are the print_board method, the place_ships method, the shoot_user and shoot_computer method and the all_ships_destroyed method to determine a winner.

Imported library's


  • random

I added this library to randomly position the ships and let the computer make a random guess.

  • copy

I added this library to hide the ships of the computer when printing the boards and to create copies of variables.

Testing


I have tested this project manually as follows:

  • Passed the code through a PEP8 linter and confirmed there are no significant problems
  • Given invalid inputs: unexpected input, out of bounds inputs, same input twice
  • Tested in my local terminal and the Code Institute Heroku terminal

Bugs

Solved Bugs

  • When I changed the name of the variable used in the hit message, I had a display bug. There were 2 times computer instead of the name of the user. I fixed this by correcting the name of the variable.

Screenshot of a bug

Remaining Bugs

  • No bugs remaining

Validator Testing

  • PEP8

1 Error message (Code:501)

This error message appears because the PEP8 linter considers the print statement on line 117 to be too long. This does not cause any problems in this project and can therefore not be considered critical.

Screenshot of pep8 linter

Project logic planning


I used this flowchart to plan the logic for this project and followed it while building the project. It may be that the logic of the project at certain points deviates from the flowchart.

Flowchart

Deployment


This project was deployed using Code Institute's mock terminal for Heroku.

Steps for deployment:

  • Fork or clone this repository
  • Create a new Heroku app
  • Set the buildpacks to 'Python' and 'NodeJS' in that order
  • Link the Heroku app to the repository
  • Click on 'Deploy'

Credits


  • Code Institute for the deployment terminal

portfolio-project-57's People

Contributors

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