Created
February 20, 2013 01:55
-
-
Save zeitan/4992054 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
class Humano < Jugador | |
attr_accessor :puntaje | |
def initialize(id) | |
@tipo = TipoJugador::HUMANO | |
@puntaje = 0 | |
@id = id | |
end | |
#Chequea que la jugada realizada por el humano este dentro del tablero o sea en una columna que no este llena. | |
#Luego llama a el jugada de la super clase de donde hereda y hace el movimiento. | |
#Si la jugada a realizar genera puntos de alguna forma(horizontal,vertical, cruzado) actualiza el atributo puntaje de la clase. | |
def jugada(tablero,col) | |
if tablero.posicion_valida?(col) | |
@puntaje += tablero.puntaje_jugada(col, ficha) | |
super | |
else | |
raise Exceptions::PosicionInvalida.new("Imposible jugar la ficha en la columna pedida") | |
end | |
end | |
end |
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
require './tipo_jugador.rb' | |
require './exceptions.rb' | |
class Jugador | |
@tipo = nil | |
@id = nil | |
@puntaje = 0 | |
#Constructores no implementados para que sea heredada la clase | |
def initialize | |
raise NotImplementedError.new("Para heredar no para instanciar") | |
end | |
def initialize(id) | |
raise NotImplementedError.new("Para heredar no para instanciar") | |
end | |
#Superclase que marca en el tablero la jugada del concursante sin importar si es humano o computador | |
def jugada(tablero,col) | |
p "Por que 2 impesiones? #{ficha}" | |
tablero.jugar!(col,ficha) | |
end | |
def ficha | |
"#{@tipo.to_tipo}#{@id.to_s}" | |
end | |
end |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment