Last active
December 20, 2022 22:37
-
-
Save dbreunig/25d82fce61d28c35470545b01828e3e7 to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
module Battleship | |
class Game | |
attr_accessor :player_1, :player_2 | |
def initialize(player_1, player_2) | |
@player_1 = player_1 | |
@player_2 = player_2 | |
@player_1.game = self | |
@player_2.game = self | |
end | |
def start_game | |
check_players | |
# do stuff | |
end | |
def check_players | |
unless @player_1 && @player_2 | |
# Throw error saying the game needs two players | |
end | |
end | |
end | |
class Player | |
attr_accessor :name, :game | |
def initialize(name) | |
@name = name | |
end | |
end | |
class ComputerPlayer < Player | |
# Robot logic | |
end | |
end | |
# Main | |
p1 = Battleship::Player.new("Human Player") | |
p2 = Battleship::ComputerPlayer.new("Robot") | |
game = Battleship::Game.new(p1, p2) | |
p game |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment