bug fixes on tic tac toe, inheritance modeling, mastermind
This commit is contained in:
13
common/BoardBase.rb
Normal file
13
common/BoardBase.rb
Normal file
@@ -0,0 +1,13 @@
|
||||
class BoardBase
|
||||
attr_accessor :turn
|
||||
|
||||
def initialize(turn = 1)
|
||||
@turn = turn
|
||||
end
|
||||
|
||||
def to_s
|
||||
print "
|
||||
Current turn: #{@turn}\n
|
||||
"
|
||||
end
|
||||
end
|
||||
27
common/GameBase.rb
Normal file
27
common/GameBase.rb
Normal file
@@ -0,0 +1,27 @@
|
||||
class GameBase
|
||||
def initialize
|
||||
puts "Welcome to Tic Tac Toe!"
|
||||
puts "Player 1, what is your name?"
|
||||
@player_one_name = gets.chomp
|
||||
|
||||
puts "Player 2, what is your name?"
|
||||
@player_two_name = gets.chomp
|
||||
|
||||
@playerOne = Player.new(@player_one_name)
|
||||
@playerTwo = Player.new(@player_two_name)
|
||||
@statusMessage = ""
|
||||
@board = Board.new()
|
||||
@winner = nil
|
||||
@turn = 1
|
||||
end
|
||||
|
||||
def to_s
|
||||
print "
|
||||
Player one: #{@playerOne.name}\n
|
||||
Player two: #{@playerTwo.name}\n
|
||||
Current turn: #{@turn}\n
|
||||
#{@statusMessage}
|
||||
#{@board.to_s}
|
||||
"
|
||||
end
|
||||
end
|
||||
10
common/Player.rb
Normal file
10
common/Player.rb
Normal file
@@ -0,0 +1,10 @@
|
||||
class Player
|
||||
attr_accessor :turn_active
|
||||
attr_reader :name, :symbol, :turn_active
|
||||
|
||||
def initialize(name, symbol = nil)
|
||||
@name = name
|
||||
@symbol = symbol
|
||||
@turn_active = false
|
||||
end
|
||||
end
|
||||
Reference in New Issue
Block a user