https://github.com/mgmerino/battleship-game
Classic game implemented in Ruby
https://github.com/mgmerino/battleship-game
battleship-game game ruby
Last synced: about 1 year ago
JSON representation
Classic game implemented in Ruby
- Host: GitHub
- URL: https://github.com/mgmerino/battleship-game
- Owner: mgmerino
- License: mit
- Created: 2024-10-15T20:46:53.000Z (almost 2 years ago)
- Default Branch: main
- Last Pushed: 2024-10-20T21:36:07.000Z (almost 2 years ago)
- Last Synced: 2025-04-05T18:52:26.690Z (over 1 year ago)
- Topics: battleship-game, game, ruby
- Language: Ruby
- Homepage:
- Size: 38.1 KB
- Stars: 1
- Watchers: 2
- Forks: 0
- Open Issues: 0
-
Metadata Files:
- Readme: README.md
- Changelog: CHANGELOG.md
- License: LICENSE.txt
Awesome Lists containing this project
README
# Battleship
This is a simple implementation of the Battleship game in Ruby. It is a two-player game where each player has a board with ships on it. The players take turns to guess the location of the ships on the opponent's board. The first player to sink all the ships of the opponent wins the game.
## Usage
You can install the gem by running:
```bash
gem install battleship
```
After installing the gem, you can start the game by running:
```bash
battleship
```
## Technical Details
The game is implemented using the following classes:
- `Cell`: Represents a cell on the board. It has a state that can be either `:empty`, `:ship`, `:hit`, or `:miss`.
- `Grid`: Represents the board. It is responsible for placing the ships, and sending the attack to the cells.
- `Ship`: Represents a ship on the grid. It has a size and a direction and health points determined by its size.
- `Player`: Represents a player in the game. It has a grid and can make an attack on the opponent's grid.
- `Engine`: The main game engine that controls the flow of the game. It spawns the ships, switch turns and manages the attack.
The game is played in the terminal. The players can see their own board and the opponent's board. The players take turns to make an attack by entering the coordinates of the cell they want to attack. The game displays the result of the attack and the state of the opponent's board.
The terminal client is implemented the following classes:
- `Interface`: The main interface that displays the game state and takes input from the players.
- `Presenter`: The presenter that formats the game state for display in the terminal.
- `InputHandler`: The input handler that validates the input from the players.
## Development
After checking out the repo, run `bin/setup` to install dependencies. Then, run `rake spec` to run the tests. You can also run `bin/console` for an interactive prompt that will allow you to experiment.
To install this gem onto your local machine, run `bundle exec rake install`. To release a new version, update the version number in `version.rb`, and then run `bundle exec rake release`, which will create a git tag for the version, push git commits and the created tag, and push the `.gem` file to [rubygems.org](https://rubygems.org).
## Contributing
Bug reports and pull requests are welcome on GitHub at https://github.com/[USERNAME]/battleship.
## License
The gem is available as open source under the terms of the [MIT License](https://opensource.org/licenses/MIT).