Skip to content

Instantly share code, notes, and snippets.

@paegun
Created July 14, 2014 20:25
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save paegun/8d5950f7c0c523669c8b to your computer and use it in GitHub Desktop.
Save paegun/8d5950f7c0c523669c8b to your computer and use it in GitHub Desktop.
Naughty Beginnings
class Viewport
def initialize(opts = {})
@elements = {}
end
def add(element)
element.send(:viewport=, self)
elements[element.id] = element
end
def remove(element)
elements.delete(element.id)
end
private
attr_accessor :elements
end
class ViewportElement
attr_reader :viewport, :id
attr_accessor :type, :x, :y, :z, :height, :width, :depth
def initialize(opts = {})
@type = opts[:type]
@id = "#{type}#{next_id}"
@x = opts[:x]
@y = opts[:y]
@z = opts[:z]
@height = opts[:height]
@width = opts[:width]
end
private
attr_writer :id, :viewport
def next_id
@@ids ||= {}
type_ids = @@ids[type]
type_ids = 0 if type_ids.nil?
type_ids += 1
end
end
class HumanObserver
def display(viewport)
# TODO: implement display for a command-line interface (CLI) form of the
# game "naughts and crosses" aka tic-tac-toe.
# if you are more familiar or comfortable with HTML + CSS, feel free
# to render HTML + CSS.
end
end
class HumanPlayer
end
class ComputerPlayer
end
class Lobby
end
class Match
end
class LeaderBoard
end
class PlayerMatchHistory
end
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment