Skip to content

Instantly share code, notes, and snippets.

@dbreunig
Last active December 20, 2022 22:37
Show Gist options
  • Save dbreunig/25d82fce61d28c35470545b01828e3e7 to your computer and use it in GitHub Desktop.
Save dbreunig/25d82fce61d28c35470545b01828e3e7 to your computer and use it in GitHub Desktop.
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