Skip to content

giankpetrov/python-battleship

Repository files navigation

Battleship: Guadalcanal 1942

Welcome to Battleship: Guadalcanal 1942.

Battleship also known as Battleships or Sea Battle, is a strategy type guessing game for two players. It is played on ruled grids on which each player's fleet of warships are marked. The locations of the fleets are concealed from the other player.

On this project you will be able to play not only the multiplayer version (2 players) but also a History Mode (Player vs Computer) based on historical data with personalised dialogue.

Live link to website

Tech Stack

VS Code Gitpod Python Git

UX & Design

User Stories

  • As a player, I want to be able to see my opponent's board during the game so that I can make educated guesses about where their ships are located.

  • As a player, I want to be able to make my moves by selecting the Row and Column on the game board so that I can play the game intuitively.

  • As a player, I want to be notified when one of my ships is hit so that I can keep track of the game's progress.

  • As a player, I want to be able to see which of my opponent's ships have been hit and which ones are still a mystery so that I can adjust my strategy accordingly.

  • As a player, I want to be able to play against the computer or another player so that I can enjoy the game in different ways.

  • As a player, I want to be able to see the results of the game, including which ships were sunk and which player won, so that I can review the game and improve my strategy for future games.

  • As a player, I want to be able to play with different types of ships with varying sizes so that I can have a unique gameplay experience.

  • As a player, I want to be able to play the game in different modes, such as a limited number of moves, so that I can add more challenge and variety to the gameplay.

Flowchart

A flowchart is a graphical representation of a process or system that shows the steps or stages involved and the relationships between them. I created a flowchart to provide a visual representation of the steps that a user need to follow in order to achieve a particular goal, such as navigating through the application.

Flowchart

Modules

  • The os module was used to create the clear_screen function to enhance user experience and reduce clutter on screen.

  • The random module was used place the ships randomly across the board game.

  • The time module was used for sleep() to create timers to get a smooth transition.

  • The sys module was used to create a typing effect when presenting the information on the console.

Features

  • Introduction screen

    • When the app loads the user is presented with a menu that allows a better and easy navigation

    • The menu options are 2 play modes, information about the person who develop the app and exit option from the app

Introduction Screen

  • Introduction History Mode

    • When the user selects the "History Mode" is presented with an introduction to the game in this mode. The text is presented with a typing effect to simulate a message is being receive in the console.
    • In the introduction it makes clear the details of the computer ships

Introduction History Mode

  • Instructions History Mode

    • The instructions are provided to the user to understand the rules of the game

Instructions History Mode

  • Board Preparation

    • Before the game start a message is displayed to the user following the history behind an historical fact followed by a description of the enemy fleet in this game mode against the computer

Board preparation History Mode

  • Board Game

    • An initial board game is created with enemy ships hidden
    • User can visualize the grid, amount of shells (turns) left.
    • User is invited to guess coordinates

Board Game History Mode

  • Target Miss

    • When the user miss a shot a dash "-" populate the grid to indicate a failed shot

Target Miss

  • Target Hit

    • When the user hit a ship an asterisk "*" populate the grid to indicate a successful shot

Target Hit

  • Input Validation

    • When the user does not follow the instructions on how to select a ROW and a COLUMN to make a shot, a message is displayed to warn the user to select valid a valid option.

Input Validation

  • History Mode defeat

    • If the user lose the game a message is displayed together with all ships that were hidden during the game.

Defeat history mode

  • Multiplayer Instructions

    • As in History mode, here is displayed the instructions to the players

Multiplayer Instructions

  • Multiplayer Board Preparation

    • In this section a message is displayed showing with details the ships places on each other player's board.

Multiplayer board preparation

  • Multiplayer First Turn

    • In this section a message display the current player turn, remaining amunition and the grid from the opponent.

Multiplayer first turn

  • Multiplayer Hit

    • If a player hit a ship an asterisk "*" populate the coordate where it was shot.
    • A message is displayed to continue shooting.

Multiplayer Hit.

  • Multiplayer Miss

    • If a player miss the shot a dash "-" populate the coordate where it was shot.

Multiplayer Miss

  • Multiplayer Second Turn

    • When the second player start to play a message display the change of turn, with its respective remaining amunition and enemy board.

Multiplayer Second Turn

Code Validation

  • One of the valitadors used was CI Python Linter

Code Institute Validator

Deployment

Code Institute has provided a template to display the terminal view of this backend application in a modern web browser. This is to improve the accessibility of the project to others.

The live deployed application can be found at Battleship: Guadalcanal 1942.

Local Deployment

Gitpod IDE was used to write the code for this project.

To make a local copy of this repository, you can clone the project by typing the follow into your IDE terminal:

  • git clone https://github.com/giankpetrov/python-battleship.git

Alternatively, if using Gitpod, you can click below to create your own workspace using this repository.

Open in Gitpod

Heroku Deployment

This project uses Heroku, a platform as a service (PaaS) that enables developers to build, run, and operate applications entirely in the cloud.

Deployment steps are as follows, after account setup:

  • Select New in the top-right corner of your Heroku Dashboard, and select Create new app from the dropdown menu.

  • Your app name must be unique, and then choose a region closest to you (EU or USA), and finally, select Create App.

  • From the new app Settings, click Reveal Config Vars, and set the value of KEY to PORT, and the value to 8000 then select add.

  • Further down, to support dependencies, select Add Buildpack.

  • The order of the buildpacks is important, select Python first, then Node.js second. (if they are not in this order, you can drag them to rearrange them) For Heroku deployment, follow these steps to connect your GitHub repository to the newly created app:

  • In the Terminal/CLI, connect to Heroku using this command: heroku login -i

  • Set the remote for Heroku: heroku git:remote -a <app_name> (replace app_name with your app, without the angle-brackets)

  • After performing the standard Git add, commit, and push to GitHub, you can now type: git push heroku main

The frontend terminal should now be connected and deployed to Heroku.

Credits

Concept

  • Concept for History Mode is based on historical data better explained here.

Code

Design

Acknowledgement

Harry Dhillon for being my mentor on this project and provide excellent feedback from real work experience.

Namaste ☸

About

No description, website, or topics provided.

Resources

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published