The goal of this project is to implement the classic game Battleship using Test Driven Development (TDD) principles.
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.
The assignment involved creating several classes and functionalities:
- Ship Class/Factory: A class or factory function to represent ships, including their length, hits, and whether they've been sunk.
- Gameboard Class/Factory: A class or factory function to represent the gameboard, allowing the placement of ships and tracking of hits and misses.
- Player: Players can take turns attacking the enemy gameboard. The game is played against the computer, which makes random plays.
- 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.
- End Game Condition: Implementing conditions for the game to end once one player's ships have all been sunk.
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.
- Open the
index.html
file in your browser to start the game. - Follow the on-screen instructions to place your ships and take turns attacking the opponent's gameboard.
- The game ends when one player's ships have all been sunk.
- 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.
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!