Skip to content

odilson-dev/battleship

Repository files navigation

Battleship Game

This is a project completed as part of the curriculum for The Odin Project. The goal of this project is to implement the classic game Battleship using Test Driven Development (TDD) principles.

Battleship Game

Introduction

Battleship is a classic two-player guessing game where each player attempts to sink the other player's fleet of ships by guessing the coordinates of the ships on a grid.

Assignment Overview

The assignment involved creating several classes and functionalities:

  1. Ship Class/Factory: A class or factory function to represent ships, including their length, hits, and whether they've been sunk.
  2. Gameboard Class/Factory: A class or factory function to represent the gameboard, allowing the placement of ships and tracking of hits and misses.
  3. Player: Players can take turns attacking the enemy gameboard. The game is played against the computer, which makes random plays.
  4. Main Game Loop and DOM Interaction: Implementing the main game loop and creating a module for DOM interaction to display the game boards and take user input for attacking.
  5. End Game Condition: Implementing conditions for the game to end once one player's ships have all been sunk.

Project Structure

The project consists of the following files:

  • Ship.js: Contains the Ship class or factory function.
  • Gameboard.js: Contains the Gameboard class or factory function.
  • Player.js: Contains the Player class.
  • index.js: Implements the main game loop and DOM interaction.
  • style.css: Stylesheet for the game.
  • index.html: HTML file to render the game.

How to Play

  1. Open the index.html file in your browser to start the game.
  2. Follow the on-screen instructions to place your ships and take turns attacking the opponent's gameboard.
  3. The game ends when one player's ships have all been sunk.

What I've Learned

  • Test Driven Development (TDD): Practiced writing tests before implementing functionality, ensuring that code meets requirements and remains maintainable.
  • Object-Oriented Programming (OOP): Implemented classes and factory functions to create modular and reusable code.
  • DOM Manipulation: Interacted with the DOM to render game elements and handle user input.
  • Game Design: Designed game mechanics and logic to create an interactive Battleship game.

Conclusion

This project has been an exciting journey into the world of web development and software engineering. Through implementing the Battleship game with Test Driven Development (TDD) principles, I've gained valuable experience and learned important concepts, including:

  • Applying TDD practices to ensure code quality and reliability.
  • Designing and implementing classes and factories for managing game components.
  • Utilizing JavaScript to create game logic and handle player interactions.
  • Incorporating DOM manipulation for user interface interactions.
  • Enhancing my understanding of software design principles and best practices.

I'm proud of the progress I've made and the skills I've developed throughout this project. Building a complete Battleship game from scratch has been both challenging and rewarding, and I look forward to applying what I've learned to future projects.

Thank you for joining me on this journey!

Enjoy playing Battleship!

Releases

No releases published

Packages

No packages published