Class: RubyChess

Inherits:
Object
  • Object
show all
Defined in:
lib/ruby_chess.rb,
lib/ruby_chess/version.rb

Constant Summary collapse

VERSION =
"0.1.2"

Instance Method Summary collapse

Instance Method Details

#choose_playersObject



19
20
21
22
23
24
25
26
27
28
# File 'lib/ruby_chess.rb', line 19

def choose_players
  puts "Welcome to RubyChess by Joe Daly"
  puts
  puts "Who will play white? (Human or Computer)"
  white_choice = gets.chomp
  puts "Who will play black? (Human or Computer)"
  black_choice = gets.chomp

  set_players(white_choice, black_choice)
end

#clear_screenObject



30
31
32
# File 'lib/ruby_chess.rb', line 30

def clear_screen
  system('clear')
end

#resetObject



34
35
36
37
# File 'lib/ruby_chess.rb', line 34

def reset
  puts "Would you like to play again? (y/n)"
  gets.chomp
end

#runObject



8
9
10
11
12
13
14
15
16
17
# File 'lib/ruby_chess.rb', line 8

def run
  clear_screen
  choose_players
  game = Game.new(@white_player, @black_player)
  game.play
  gets
  clear_screen
  choice = reset
  run if choice == 'y' || choice =='Y' || choice == 'yes' || choice == 'Yes'
end

#set_players(white_choice, black_choice) ⇒ Object



39
40
41
42
43
44
45
46
47
48
49
50
# File 'lib/ruby_chess.rb', line 39

def set_players(white_choice, black_choice)
  if white_choice == 'Human' || white_choice == 'human'
    @white_player = HumanPlayer.new(:white)
  else
    @white_player = ComputerPlayer.new(:white)
  end
  if black_choice == 'Human' || black_choice == 'human'
    @black_player = HumanPlayer.new(:black)
  else
    @black_player = ComputerPlayer.new(:black)
  end
end