Created
August 29, 2016 21:29
-
-
Save fee1good/2bdf4d36744ccb5e5ffbe1ad98659b58 to your computer and use it in GitHub Desktop.
This file contains 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 Station | |
attr_accessor :name | |
trains = [] | |
def initialize(name) | |
@name = name | |
end | |
def add_train (train_obj) | |
trains << train_obj | |
end | |
def show_trains | |
puts trains | |
end | |
def delete_train(train_obj) | |
trains.delete(train_obj) | |
end | |
end | |
class Route | |
attr_accessor :station_x | |
attr_accessor :station_y | |
attr_accessor :full_route | |
def initialize(station_x, station_y) | |
@full_route = [station_x, station_y] | |
end | |
def add_point (station_name) | |
@full_route << station_name | |
end | |
def delete_point(station_name) | |
@full_route.delete(station_name) | |
end | |
def show_route | |
puts @full_route | |
end | |
end | |
class Train | |
attr_accessor :number | |
attr_accessor :type | |
attr_accessor :wagon_number | |
attr_accessor :speed | |
train_type = ["passanger", "cargo"] | |
def initialize(number, type, wagon_number) | |
if train_type.include?(type) | |
@number = number | |
@type = type | |
@wagon_number = wagon_number | |
else | |
puts "Тип поезда должен быть: cargo или passanger." | |
end | |
end | |
def increase_speed(km) | |
self.speed += km | |
end | |
def show_current_speed | |
puts self.speed | |
end | |
def stop | |
self.speed = 0 | |
end | |
def show_wagon_number | |
puts @wagon_number | |
end | |
def add_wagon(number) | |
if @speed > 0 | |
puts "Необходимо остановить поезд, чтобы прицепть вагон" | |
else | |
@wagon_number += number | |
end | |
end | |
def use_route(route_obj) | |
current_route = route_obj | |
end | |
end | |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment