Class: ScreenMessage

Inherits:
Object
  • Object
show all
Defined in:
lib/screen_message.rb

Constant Summary collapse

SPACING =

Constant variable for display formatting space

30

Instance Method Summary collapse

Constructor Details

#initializeScreenMessage

Returns a new instance of ScreenMessage.



10
11
# File 'lib/screen_message.rb', line 10

def initialize
end

Instance Method Details

#display_game_overObject



140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
# File 'lib/screen_message.rb', line 140

def display_game_over
  # Create instance of Artii
  artii = Artii::Base.new
  title = "   GAME OVER   "
  msg = artii.asciify('GAME OVER') + "\n\n"
  msg += "Oh no! Everyone is leaving because you didn't stack the right burgers!" + "\n\n"
  msg += "Owning a burger shop, especially a Ruby one, is tough.\n"
  msg += "You need to practice hard (or just use the handicap ARGV in command line, read the instruction in the installation/usage guide in README.md).\n\nDon't give up! You can always try again next time!" + "\n\n"
  msg += "You are lucky this is just a game..."
  msg += "\n\n\n~ END ~"
  height = 30

  # Format output using frame
  msg_frame(title, msg, height)
end

#display_h_moneyObject



13
14
15
# File 'lib/screen_message.rb', line 13

def display_h_money
  msg = "Change TARGET_MONEY.\n\t\t\t\t\tThe lower the value, the easier to WIN.\n\t\t\t\t\tDefault is 50. Enter number 10 to 99.\n\t\t\t\t\tUsage example: -m 10"
end

#display_h_reputationObject



17
18
19
# File 'lib/screen_message.rb', line 17

def display_h_reputation
  msg = "Change MAX_REPUTATION.\n\t\t\t\t\tThe lower the value, the easier to GAME OVER.\n\t\t\t\t\tDefault is 10. Enter number 1 to 10.\n\t\t\t\t\tUsage example: -r 2"
end

#display_instructionsObject



83
84
85
86
87
88
89
90
91
92
93
94
# File 'lib/screen_message.rb', line 83

def display_instructions
  title = "   HOW TO PLAY   "
  msg = "Instructions:\n\n1. When shop's Menu is displayed, memorise \"burger names\", \"ingredients\" and \"quantity\" needed, and ingredients \"stack order\"." + "\n\n"
  msg += "2. Customer's request will consists of the \"name of the burger\", and custom \"preferences\", such as 'no sauce' or 'extra 1 patty'." + "\n\n"
  msg += "3. Select ingredient and quantity needed in order, from \"bottom\" of the stack \"to the top\". Enter \"0\" for requests that ask to leave some ingredients out because we need to keep the correct order of the stack." + "\n\n"
  msg += "4. When you build the burger perfectly as per customer request, the happy customer will increase your reputation by 1 point and pay $10 for the burger. Otherwise, if you miss a thing or two, but still acceptable, the pay would be halved but no reputation points given. If you fail to make a decent burger for the customer, the angry customer will not pay and they will take 1 point off your reputation." + "\n\n"
  msg += "5. Keep enough customers happy and earn money to meet the target (You Win). Be careful not to make too many customers angry and let your reputation get to 0 (Game Over)."
  height = 32

  # Format output using frame
  msg_frame(title, msg, height)
end

#display_invalid(input = "") ⇒ Object



21
22
23
# File 'lib/screen_message.rb', line 21

def display_invalid(input = "")
  msg = "You have entered an invalid value #{input}\nPlease enter the value in a valid format. Use -h or --help to view Help menu.\n"
end

#display_prologueObject



96
97
98
99
100
101
102
103
104
105
106
107
108
109
# File 'lib/screen_message.rb', line 96

def display_prologue
  title = "   PROLOGUE   "
  msg = "Ruby Burger is dedicated in fulfilling the ever growing customers' demand of customised and personalised burgers.\n"
  msg += "Our job is to build a burger following our shop's Menu recipes, while adjusting into different customers' preferences.\n"
  msg += "In the next scene, we will memorise our Menu and recipes." + "\n\n"
  msg += "Hint:\n"
  msg += "Memorise \"burger names\", \"ingredients\" and \"quantity\" needed, and ingredients \"stack order\".\n"
  msg += "Build burger from \"bottom up\". Select ingredients from the bottom of the stack to the top as seen in the recipes.\n"
  msg += "Enter \"0\" for requests that ask to leave some ingredients to keep the correct order of the stack."
  height = 22

  # Format output using frame
  msg_frame(title, msg, height)
end

#display_welcomeObject



68
69
70
71
72
73
74
75
76
77
78
79
80
81
# File 'lib/screen_message.rb', line 68

def display_welcome
  # Create instance of Artii
  artii = Artii::Base.new
  title = "   WELCOME   "
  msg = "Hello there... Welcome to" + "\n\n"
  msg += artii.asciify('Burger Game') + "\n\n"
  msg += "We are going to build burgers for customers." + "\n"
  msg += "Clear your mind, put on your best smile..." + "\n"
  msg += "And... we're ready to stack 'em burgers!"
  height = 24

  # Format output using frame
  msg_frame(title, msg, height)
end

#display_winObject



111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
# File 'lib/screen_message.rb', line 111

def display_win
  title = "   YOU WIN   "
  msg = "Ruby Burger has reached its goal!\n\nAll thanks to you and your brilliant burger stacking skill.\nNow is the time to celebrate and give yourself a reward..." + "\n\n"
  msg += "A burger... and chips!" + "\n\n"

  msg += "                            |\\ /| /|_/|" + "\n"
  msg += "                          |\\||-|\\||-/|/|" + "\n"
  msg += "                           \\\\|\\|//||///" + "\n"
  msg += "          _..----.._       |\\/\\||//||||" + "\n"
  msg += "        .'     o    '.     |||\\\\|/\\\\ ||" + "\n"
  msg += "       /   o       o  \\    | './\\_/.' |" + "\n"
  msg += "      |o        o     o|   |          |" + "\n"
  msg += "      /'-.._o     __.-'\\   |          |" + "\n"
  msg += "      \\      `````     /   |          |" + "\n"
  msg += "     |``--........--'`|    '.______.'" + "\n"
  msg += "\\              /          " + "\n"
  msg += "jgs  `'----------'`              " + "\n\n\n"

  msg += "-- all ASCII artwork copyrighted ©1996-01 --" + "\n"
  msg += "Joan G. Stark" + "\n"
  msg += "-- All Rights Reserved --" + "\n\n"
  msg += "\n~ END ~"

  height = 35

  # Format output using frame
  msg_frame(title, msg, height)
end

#go_to_nextObject



156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
# File 'lib/screen_message.rb', line 156

def go_to_next
  # Create instance of TTY Prompt
  prompt = TTY::Prompt.new

  input = prompt.select("Do you want to continue?") do |menu|
    menu.choice "Next"
    menu.choice "Exit"
  end

  if input == "Exit"
    exit
  else
    input
  end
end

#msg_frame(title, msg, height = 10) ⇒ Object

Method for displaying message frame



26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
# File 'lib/screen_message.rb', line 26

def msg_frame(title, msg, height = 10)
  msg_box = TTY::Box.frame({
    enable_color: true, # force to always color output
    width: 80,
    height: height,
    align: :center,
    padding: 3,
    style: {
      border: {
        fg: :white
      }
    },
    border: :thick,
    title: {
      top_left: title
    }
  }) do
    msg
  end

  msg_box
end

#recipe_frame(recipe) ⇒ Object

Method for displaying recipe frame



50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
# File 'lib/screen_message.rb', line 50

def recipe_frame(recipe)
  recipe_box = TTY::Box.frame({
    enable_color: true, # force to always color output
    width: SPACING + 10,
    align: :center,
    padding: 3,
    style: {
      border: {
        fg: :white
      }
    }
  }) do
    recipe
  end

  recipe_box
end