Stack
Javascript
Webpack
Project Goals
This project is my submission for The Odin Project's
Battleship Game. The focus of this app is to practice Test Drive Developement while creating a game of Battleship. Players need to be able to choose their ship locations and take turns trying to hit/guess where their enemy's ships are. The first player to sink all 5 of their enemy's ships is the winner.
Development Stack
The front end for this project is built with Javascript and CSS. I used webpack to bundle all files/assests.
Development Process
I created classes for Players, Gameboards, and Ships. Each player has a turn boolean and a moves array. Ship classes have a size/length and a hit count. Each player has their own gameboard with X coordinates from 1-10 and Y coordinates from A-J. A player's gameboard saves the ships locations, determines if an enemy attack has hit a ship, and checks each turn if all ships have been sunk. The most challenging part of developing Battleship was randomizing enemy ship placement, as well as the functionality for a drag and drop controller for the player's ship. For enemy ships, a random direction is chosen, as well as a random starting point, and the coordinates are returned to a do...while loop that runs until a set of coordinates returned is not currently occupied.
Issues
I ran into issues using a drag and drop controller for the player ships. The player drags the ship onto the board, and each valid direction the ship can be placed on is highlighted. I wasn't thinking about how a player might interact with the board, maybe they would drop the ship on the board mulitple times until they decided on a location. I realized I wasn't clearing the saved information for the previous drops, and had introduced bugs when the player chose a direction for their ship.
Lessons Learned
This is my first project developing a more complex game, and I started by breaking down the logic step by step. Planning each interaction helped write pure, testable functions. I learned that user interactions can be unpredictable, and to keep that in mind when coding any game or application.