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 Game | |
attr_reader :board, :computer_player, :human_player, :ui | |
def initialize | |
@board = Board.new | |
@computer_player = ComputerPlayer.new | |
@human_player = HumanPlayer.new | |
@ui = UserInterface.new(human_player) | |
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
class FizzBuzzGame | |
def run(x,y) | |
for i in x..y | |
if i%5==0 && i%3==0 | |
puts "FizzBuzz" | |
elsif i%3==0 | |
puts "Fizz" | |
elsif i%5==0 | |
puts "Buzz" |
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 './FizzBuzzGame' | |
describe FizzBuzzGame do | |
before :each do | |
@FBGame=FizzBuzzGame.new | |
end | |
describe "#new" do |
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_relative 'spec_helper.rb' | |
describe Game do | |
before :each do | |
@new_game=Game.new | |
end | |
describe "#new" do | |
it "creates a new instance of Game" do |
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_relative 'spec_helper.rb' | |
describe Game do | |
before :each do | |
@new_game=Game.new | |
end | |
describe "#new" do | |
it "creates a new instance of Game" do |
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
describe "#decrease_space" do | |
it "should start the game with 8 spaces since computer goes first." do | |
expect(@new_game.decrease_space).to eq(8) | |
end | |
it "should decrease @@no_space by 1" do | |
expect{subject}.to change{@new_game.decrease_space}.by(-1) | |
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
#the method | |
def welcome | |
puts "Welcome to a Simpler Tic Tac Toe. The computer will go first." | |
@board.board["5"]="X" | |
puts "The computer chose space number 5." | |
@board.display_board | |
self.decrease_space | |
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
def open_spaces(board) | |
spaces=[] | |
board.cells.each do |k, v| | |
spaces << k if board.cells[k]!= "X" && board.cells[k]!="O" | |
end | |
spaces | |
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
def winner?(board) | |
winning_combos=[[1,2,3], [4,5,6], [7,8,9], | |
[1,4,7], [2,5,8], [3,6,9], | |
[1,5,9], [3,5,7]] | |
human_win=[] | |
computer_win=[] | |
board.cells.each do |k,v| | |
if board.cells[k]=="X" |
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
def game_over?(board) | |
open_spaces(@board).length <=0 || winner?(@board) | |
end |