Class: Gato
- Inherits:
-
Object
- Object
- Gato
- Defined in:
- lib/mygem_tictactoe.rb
Defined Under Namespace
Modules: Patrones
Instance Method Summary collapse
-
#initialize ⇒ Gato
constructor
A new instance of Gato.
- #jugar ⇒ Object
Constructor Details
#initialize ⇒ Gato
Returns a new instance of Gato.
43 44 45 46 47 |
# File 'lib/mygem_tictactoe.rb', line 43 def initialize @mapa = [].fill(0, 9) { " " } @jugadores = { :X => 'X', :O => 'O' } @turno = :X end |
Instance Method Details
#jugar ⇒ Object
50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 |
# File 'lib/mygem_tictactoe.rb', line 50 def jugar banderaGanadora = false 9.times do if @turno === :X mostrar movimientoJugador else movimientoCPU end ganador = posibleGanador unless ganador.nil? mostrar print "\n#{ganador} es el ganador!\n" banderaGanadora = true break end @turno = (@turno === :X) ? :O : :X end if (!banderaGanadora) mostrar print "\nJuego empate.\n" end end |