Giter Club home page Giter Club logo

-ci-pp3-battleship's Introduction

Battleship

About

Try your hand at playing against a computer! Battleship is a Python command line game where a human can relax and play against a computer. A definite embarrassment save from losing against a mate!

Table of Contents

  1. Project Goals
    1. User Goals
    2. Site Owner Goals
  2. User Experience
    1. Target Audience
    2. User Stories
    3. User Manual
  3. Technical Design
    1. Flowchart
    2. Data Models
  4. Technologies Used
    1. Languages
    2. Frameworks and Tools
  5. Features
  6. Testing
    1. Python Validation
    2. Testing user stories
  7. Bugs
  8. Deployment
  9. Credits
  10. Acknowledgements

Project Goals

  • The Battleship CLI game allows users to play against a computer
  • The winner is saved to a Google Sheets file
  • The five most recent winners can be viewed

User Goals

  • Be able to enter name to play and if wins, save to Google Sheet
  • Be able to read rules of game
  • Be able to view 5 most recent winners

Site Owner Goals

  • Create a game where users can relax and take a solitory moment
  • Create a game that is easy and clear to user
  • Create a game that gives feedback to user during gameplay

User Experience

Target Audience

  • People of all ages who enjoy games

User Stories

First-time User

  1. As a user, I want clear options from the main menu
  2. As a user, I want to see an option to read the rules for the game
  3. As a user, I want to be able to enter my name and see the personalised game messages throughout the game
  4. As a user, I want my name to be recorded if I win the game so that others would be able to see that I have won
  5. As a user, I want move feedback throughout the game so I know what is going on at all times

Site Owner

  1. As a site owner, I want the user to be able to select from the different options in the main menu
  2. As a site owner, I want the name to be saved to the Google Sheets and to be able to view them in the game
  3. As a site owner, I want data entry to be validated to show them how to correctly format the input

User Manual

Click here for instructions to use

Overview

The Battleship CLI Game is a command line version of the famous Battleship game. The user plays against the computer.

Main Menu

On the main menu, the user is presented with an ASCII art rendering of the name 'Battleship'. Beneath that, there is a greeting and there are different options as part of the main menu. Operation: Input numeric values and press enter key.

  1. Play game - enter game play
  2. Read rules - prints out rules of game
  3. View winners - prints out five most recent winners saved in Google Sheet document
  4. Quit - quits program

Play Game

With the Play Game option, the user is first instructed to enter their name. Operation: Enter anything and it will be saved as string.

A personalised message will then appear for them to take their turn. As part of their turn, they must enter suitable coordinates. Operation: Enter x,y coordinates like 2,3 for example. Hits and misses are displayed on board. Hits are shown as 'x' whereas misses are shown as '.'. Computer goes then.

When a players win, the message is shown on the screen and the name is saved to the Google Sheet. There is then a message to go back to the main menu Operation: Click any key and enter.

Read Rules

With the Read Rule option, the user is presented with the rules for Battleship. They are then given an option to go back to the main menu. Operation: Click any key and enter.

View Winners

With the View Winners option, the user is presented with the five most recent winners. They are then given an option to go back to the main menu. Operation: Click any key and enter.

Quit

With the Quit option, the user exits the program with a goodbye message.

Technical Design

Flow Chart

Please view the below flowchat, created with Lucid

Flowchart

Data Models

This project makes use of Object Oriented Programming and user the following as part of this:

  1. Classes - classes were used for the game board, shot, battleship and player. The game board and battleship were the most indepth.
  2. Lists and dictionaries - lists and dictionaries were used to create the game boards and also to use and manipulate the data sent over by the Google Sheets API.
  3. Google Sheets API - Google Sheets API was used as a database to save all the people's names who have won the game before.

Technologies Used

Languages Used

Frameworks and Tools

  • Git - Used for version control.
  • Heroku - Used for hosting the website on Heroku.
  • Lucid - Used to draw flowcharts.
  • Google Sheets - Used to store data outside of running the game.
  • Google Cloud Platform - Used to manage permissions to Google Services such as Google Sheets.

Libraries

  • gspread - Used to make it easier to work with Google Sheets API.
  • copy - Used to create two different objects in memory. This was used to create two different game board.
  • random - Used to generate computer's coordinates.
  • os - Used to clear terminal.

Features

Main Menu

On the main menu, the user is presented with an ASCII art rendering of the name 'Battleship'. Beneath that, there is a greeting and there are different options as part of the main menu.

Main Menu

This screen covers the following user stories:

  1. As a user, I want clear options from the main menu
  2. As a user, I want to see an option to read the rules for the game
  3. As a site owner, I want the user to be able to select from the different options in the main menu

Play Game

When playing the game, the user is first instructed to enter their name. A personalised message will then appear for them to take their turn. As part of their turn, they must enter suitable coordinates. The computer will then take its turn. When a players win, the message is shown on the screen and the name is saved to the Google Sheet. There is then a message to go back to the main menu

Play Game

This screen covers the following user stories:

  1. As a user, I want to be able to enter my name and see the personalised game messages throughout the game
  2. As a user, I want move feedback throughout the game so I know what is going on at all times
  3. As a site owner, I want data entry to be validated to show them how to correctly format the input

Read Rules

When the user selects on the read rules option, the user is presented with the rules for Battleship. They are then given an option to go back to the main menu.

Read Rules

This screen covers the following user stories:

  1. As a user, I want to see an option to read the rules for the game

View Winners

When the user clicks on view winners, they will see the five most recent winners.

View Winners

This screen covers the following user stories:

  1. As a user, I want my name to be recorded if I win the game so that others would be able to see that I have won
  2. As a site owner, I want the name to be saved to the Google Sheets and to be able to view them in the game

Validation

Python Validation

The Python code was validated using PEP8 Validation Service. The code passed with 0 errors and 0 warnings.

run.py

Testing User Stories

  1. As a user, I want clear options from the main menu
Feature Action Expected Result Actual Result
Main Menu Select any of the options User is presented with different options Works as expected
  1. As a user, I want to see an option to read the rules for the game
Feature Action Expected Result Actual Result
Read Rules Select from Main Menu User is presented with the rules Works as expected
  1. As a user, I want to be able to enter my name and see the personalised game messages throughout the game
Feature Action Expected Result Actual Result
Game Play Select from Main Menu After name entered, they will received personalised messages Works as expected
  1. As a user, I want my name to be recorded if I win the game so that others would be able to see that I have won
Feature Action Expected Result Actual Result
View Winners Select from Main Menu User is presented with different options Works as expected
  1. As a user, I want move feedback throughout the game so I know what is going on at all times
Feature Action Expected Result Actual Result
Game Play Select from Main Menu User is presented with feedback Works as expected
  1. As a site owner, I want the user to be able to select from the different options in the main menu
Feature Action Expected Result Actual Result
Main Menu Select any of the options User is presented with different options Works as expected
  1. As a site owner, I want the name to be saved to the Google Sheets and to be able to view them in the game
Feature Action Expected Result Actual Result
View Winners Select from Main Menu User is presented with five different name who are recorded winners Works as expected
  1. As a site owner, I want data entry to be validated to show them how to correctly format the input
Feature Action Expected Result Actual Result
Game Play Select from Main Menu User is made to enter coordinates correctly Works as expected

Bugs

Bug Fix
Winning name is not updating until programme termination and re-run I need to find another area for the function to be called

Deployment

Heroku

This application has been deployed from Github using Heroku. Here's how:

  1. Create an account at heroku.com
  2. Create a new app, add app name and your region
  3. Click on create app
  4. Go to "Settings"
  5. Under Config Vars, add your sensitive data (creds.json for example)
  6. For this project, I set buildpacks to heroku/python and heroku/nodejs and in that order.
  7. You must then create a Config Var called PORT. Set this to 8000.
  8. Go to "Deploy" and at "Deployment method", click on "Connect to Github"
  9. Enter your repository name and click on it when it shows below
  10. Choose the branch you want to buid your app from
  11. If desired, click on "Enable Automatic Deploys", which keeps the app up to date with your Github repository

Forking the GitHub Repository

By forking this GitHub repository you are making a copy of the original to view or make changes without affecting the original. You can do this by following these steps...

  1. Log into your GitHub account and find the repository.
  2. Click 'Fork' (last button on the top right of the repository page).
  3. You will then have a copy of the repository in your own GitHub account.

Making a Local Clone

  1. Log into your GitHub account and find the repository.
  2. Click on the 'Code' button (next to 'Add file').
  3. To clone the repository using HTTPS, under clone with HTTPS, copy the link.
  4. Then open Git Bash.
  5. Change the current working directory to where you want the cloned directory to be made.
  6. In your IDE's terminal type 'git clone' followed by the URL you copied.
  7. Press Enter.
  8. Your local clone will now be made.

Credits

Code

Acknowledgements:

  • To my mentor Mo Shami for his guidance, motivation and great resources.

-ci-pp3-battleship's People

Contributors

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