Battleships

This project is a console-based recreation of the classic Battleship strategy game, developed in C++ using object-oriented programming principles. It features a complete turn-based gameplay loop, AI opponent with multiple difficulty levels, and a text based UI built from ASCII art.

The program was developed in Visual Studio using C++

Project Overview

The game simulates the Battleships experience through modular class structure separating UI, game logic, and AI components. The UI manages all menus and input handling, the GameLogic class governs the turn flow and win conditions, and the AI adapts its attack strategy based on difficulty. A grid system stores ship data and hit detection using pointer-based access for efficiency.

Displaying The Game Grid

The Grid::displayGrid function renders the player and AI grids to the console, iterating through a pointer-based 2D array of cells to visually represent ships, hits, and misses. It combines procedural console drawing with encapsulated data handling, showcasing how object states can be translated into an interactive visual interface through cursor control and colour formatting.

Creating Player Ships

The GameLogic::createPlayerShips method dynamically allocates memory for each of the players ships using pointers, creating individual Ship objects with their respective names and sizes. It then calls placeShip for each ship, which handles the player’s manual placement on the grid. Once all ships are placed, the game is ready to proceed to the battle phase where the player can begin taking turns against the opponent.