Skip to content

Instantly share code, notes, and snippets.

View pumpkincouture's full-sized avatar

Sylwia Bridges pumpkincouture

View GitHub Profile
A,B,08:00,09:00,50.00
A,B,12:00,13:00,300.00
A,C,14:00,15:30,175.00
B,C,10:00,11:00,75.00
B,Z,15:00,16:30,250.00
C,B,15:45,16:45,50.00
C,Z,16:00,19:00,100.00
def lay_over_two
@origin == "B" && @destination == "Z" || @origin != "A" && @destination != "B" && @destination != "Z"
end
def find_total_price(first_leg, second_leg, third_leg)
if second_leg == []
total_price = first_leg.get_price + third_leg.get_price
elsif second_leg == third_leg
total_price = first_leg.get_price + second_leg.get_price
else
def gather_legs(first_leg, second_leg, third_leg)
flights = []
second_leg_number = -1
third_leg_number = -1
first_leg.each {|leg| flights << [leg, second_leg[second_leg_number += 1], third_leg[third_leg_number += 1]].flatten}
flights
end
def delete_nil(flights_array)
class FlightBuilder
attr_reader :origin, :destination
attr_accessor :flight_duration
def initialize(array)
@origin = array[0].origin
@destination = array[-1].destination
end
def calculate_total_duration(array)
class Board
attr_reader :error, :cells
def initialize(user_interface)
@ui = user_interface
@cells = {"1" => "1", "2" => "2", "3" => "3", "4" => "4", "5" => "5",
"6" => "6", "7" => "7", "8" => "8", "9" => "9"}
end
def invalid_key(answer)
class SetUp
attr_reader :player, :human_player, :ui, :board
def create_instances
@human_player = HumanPlayer.new
@ui = UserInterface.new
@board = Board.new(@ui)
end
def choose_player
class UserInterface
def choice
puts "Welcome to Tic Tac Toe. Please choose your level : press e for easy and h for hard."
choice = gets.chomp
choice.upcase!
return choice if choice == "H" || choice == "E"
puts "That's not a valid choice. Please try again."
self.choice
class SetUp
attr_reader :player, :human_player, :ui, :board
def create_instances
@human_player = HumanPlayer.new
@ui = UserInterface.new
end
def choose_board
@ui.prompt_for_board
class UserInterface
def prompt_for_board
puts "Welcome to Tic Tac Toe. Please enter a number to determine board size : ex, inputting '6' would create a 6x6 board."
end
def get_board_choice
choice = gets.chomp
choice.to_i
end
class Board
include TTTConstants
attr_reader :cells
def initialize(user_interface, board_choice)
@ui = user_interface
@board_choice = board_choice
@cells = Array.new(board_choice * board_choice, [])
end