Skip to content

Instantly share code, notes, and snippets.

@shamritskiy3468
Last active December 16, 2018 21:22
Show Gist options
  • Save shamritskiy3468/69b19d36cb6abdf18981b404d859b323 to your computer and use it in GitHub Desktop.
Save shamritskiy3468/69b19d36cb6abdf18981b404d859b323 to your computer and use it in GitHub Desktop.
Ruby lab HomeTask #1
#all classes in one file to fit whole code in one gist file
class Match
attr_accessor :goal_balls, :missed_balls
def initialize
@goal_balls = rand(10)
@missed_balls = rand(10)
end
def won_match?
true if goal_balls - missed_balls > 1
end
def spawn?
true if goal_balls == missed_balls
end
end
class PlaySeason
attr_accessor :games_number, :games
def initialize(games_number)
@games_number = games_number.to_i
@games = []
end
def play_mathes
games_number.times { games << Match.new }
end
end
class PrinterInfo
attr_accessor :play_season
def initialize(play_season)
@play_season = play_season
end
def print_results
play_season.games.each_with_index do |match, index|
print "#{index} match ===> "
if match.won_match?
puts "CONGRATS. WIN! (#{match.goal_balls} : #{match.missed_balls})"
elsif match.spawn?
puts "SPAWN. No Winnes (#{match.goal_balls} : #{match.missed_balls})"
else
puts "F@*#...Loose. (#{match.goal_balls} : #{match.missed_balls})"
end
end
37.times { print "*" }
puts "\n"
end
end
puts "Enter Games number:"
number_of_games = gets.chomp.to_i
play_season_2018_Belarus = PlaySeason.new(number_of_games)
play_season_2018_Belarus.play_mathes
sport_news = PrinterInfo.new(play_season_2018_Belarus)
sport_news.print_results
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment