Module: AppController

Defined in:
lib/controllers/app_controller.rb

Class Method Summary collapse

Class Method Details

.clear_screenObject



51
52
53
# File 'lib/controllers/app_controller.rb', line 51

def clear_screen
    system('clear')
end

.exit?Boolean

Returns:

  • (Boolean)


55
56
57
58
# File 'lib/controllers/app_controller.rb', line 55

def exit?
    self.clear_screen
    ExitView.show
end

.play_gameObject



11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
# File 'lib/controllers/app_controller.rb', line 11

def play_game
    begin
        self.clear_screen
        Sound.new("lib/media/blaster-firing.wav").play
        new_round = Round.new
        request_player_input = RoundsView.input round: new_round, round_number: Round.num_rounds
        new_round.player_input = request_player_input
        new_round.player_selection = new_round.selections request_player_input
        RoundsView.display_results new_round
        new_round.save!
        RoundsView.successful_save
    end until new_round.result == 'lost'
    new_game = Game.new
    GamesView.get_player_name new_game
    new_game.score = Round.count_wins * 100 + Round.count_draws * 25
    self.clear_screen
    GamesView.thanks new_game
    new_game.save!
    GamesView.successful_save
    Round.clear_rounds
    self.play_or_menu
end

.play_or_menuObject



47
48
49
# File 'lib/controllers/app_controller.rb', line 47

def play_or_menu
    OptionsView.show == false ? nil : self.play_game
end

.show_highscoresObject



34
35
36
37
38
39
# File 'lib/controllers/app_controller.rb', line 34

def show_highscores 
    self.clear_screen
    games = Game.map { |game| [game.player_name, game.score] }
    HighscoresView.show games: games
    self.play_or_menu
end

.show_rulesObject



41
42
43
44
45
# File 'lib/controllers/app_controller.rb', line 41

def show_rules
    self.clear_screen
    RulesView.show
    self.play_or_menu
end