class TictactoeTracypholmes::TicTacToeCLI

Public Class Methods

new() click to toggle source
# File lib/tictactoe_tracypholmes.rb, line 11
def initialize; end

Public Instance Methods

call() click to toggle source
# File lib/tictactoe_tracypholmes.rb, line 26
def call
    puts 'Enter 1 to play against the computer.'
    puts 'Enter 2 to play against a human.'
    puts 'Enter 00110011 to watch the computers battle to their circuits.'
    puts "WHISPERS 'or enter wargames if you want to have a good time'"
    puts "\nYou may also enter 'q' to Quit"
    game_type = gets.chomp
    first_move = ''

    if game_type == 'q'
        puts 'Hate to see you go. Have a nice day!'.green
        abort
    elsif game_type == '2' # hum vs hum
        Game.new.play
        puts "OMG that was fun, wasn't it, Player? Would you like to play another game?"
        merry_go_round
    elsif game_type == '00110011' # comp vs comp
        Game.new(Players::Computer.new('X'), Players::Computer.new('O'), Board.new).play
        puts "OMG that was fun, wasn't it? Would you like to play another game?"
        merry_go_round
    elsif game_type == 'wargames' # comp on comp crime for 100
        counter = 0
        until counter == 100
            counter += 1
            Game.new(Players::Computer.new('X'), Players::Computer.new('O')).play
            puts "OMG that was fun, wasn't it? Would you like to play another game?"
            merry_go_round
        end
    elsif game_type == '1' # hum vs comp
        puts "So umm...who's going first?!"
        puts "\nIf you want to go first, Player, choose 'X'. Otherwise, choose 'O'"
        first_move = gets.strip.upcase
        while first_move != 'X' && first_move != 'O'
            puts 'Cmon, son! What are you doing?! Enter X or O, please.'.red
            first_move = gets.strip.upcase
        end
    end

    game = nil
    if first_move == 'X'
        Game.new(Players::Human.new('X'), Players::Computer.new('O'), Board.new).play
    else
        Game.new(Players::Computer.new('X'), Players::Human.new('O'), Board.new).play
    end
    puts "OMG that was fun, wasn't it? Would you like to play another game?"
    merry_go_round
    end
merry_go_round() click to toggle source
# File lib/tictactoe_tracypholmes.rb, line 74
  def merry_go_round
      input = gets.chomp
      while input != 'Y' || input != 'N'
          puts "Please enter 'Y' or 'N'.".red
          case input
          when 'Y'
              call
          when 'N'
              puts 'Aww man! Ok. See you later!'
              abort
          else
              merry_go_round
          end
      end
end