repl.it
@21Miya/

CodeJam4

Ruby

This is for the Repl.it CodeJam 2018! Some code may be messy because I did all of the games separately before putting them all together.

fork
loading
Files
  • main.rb
main.rb
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
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
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
def guessinggame
puts "What would you like to be the maximum number?"
num = gets.chomp.to_i
puts "Thinking of a number..."
int = rand(1..num)
sleep(1.5)
puts "I've got it!"
sleep(1)
puts "Can you guess what it is?"
guess = gets.chomp.to_i
until guess == int
puts "Try again!"
if guess > int
puts "Hint: Your guess was too high."
else
puts "Hint: Your guess was too low."
end
guess = gets.chomp.to_i
end
puts "You win!"
end


puts "Welcome to the CodeJam Guessing Arcade!"
puts "All of the games here are surrounding guessing, mystery, randomness, etc.!"
while 1 == 1
puts "Choose a game:"
puts "Guess My Number || Guess Your Number || Oracle || Madlibs"
puts "GMN || GYN || O || M"
game = gets.chomp.downcase
puts ""
if game == "gmn"
puts "Welcome to my Guessing Game!"
sleep(1)
puts "I'm going to think of a number between 1 and a number of your choice."
sleep(1.3)
guessinggame
elsif game == "o"
check = 1
puts "Welcome to the Oracle Program!"
sleep(1)
int = rand(9)
answers = ["Yes.","No.","Maybe.","That depends on you.","It's out of my hands.","Probably not.","Most likely, yes.","Hm...I can't answer that right now. Try asking again.","There's no certain answer to that."]
yourAnswer = answers[int]
puts "Enter a yes/no question for me to answer:" 
question = gets.chomp.downcase
if question.include? "are you real" 
puts "Of course I am."
elsif question.include? "what's your name?" || question == "do you have a name?" || question == "do you have a name?" || question == "what is your name?"
puts "I don't have a name. I'm Ruby code."
elsif question.include? "how are you" 
puts "I'm doing pretty good, thanks."
else
puts "I'm summoning your answer..."
sleep(1)
puts yourAnswer
end
elsif game == "gyn" 
def gamee
  puts "Welcome to your Guessing Game!"
  sleep(1)
  puts "Choose a number from 1 to 100."
  min = 1
  max = 100
guess = 0
count = 0
yeet = 0
prevguesses = [""]
puts "I'll give you a couple seconds to think about it."
sleep(3)
puts "I wonder what number you’re thinking of..."

#Let's make sure we don't repeat guesses.
until guess == 1000
if max < min || max == min
max = 100
min = 0
else
sleep(0.001)
end
if prevguesses == [1,2,3,4,5,6,7,8,9,10,11,12,13,14,15,16,17,18,19,20,21,22,23,24,25,26,27,28,29,30,31,32,33,34,35,36,37,38,39,40,41,42,43,44,45,46,47,48,49,50,51,52,53,54,55,56,57,58,59,60,61,62,63,64,65,66,67,68,69,70,71,72,73,74,75,76,77,78,79,80,81,82,83,84,85,86,87,88,89,90,91,92,93,94,95,96,97,98,99,100]
puts "Hold on, I've guessed every number between 1 and 100!"
else
sleep(0.001)
end


guess = rand(min..max)
until yeet == 10
if prevguesses.include? guess 
guess = rand(min..max)
else
prevguesses << guess
yeet = 10
end
end
#end

#Okay, now to ASK if our guess is correct.
puts "I'm thinking..."
sleep(2)
puts "Could it be...#{guess}?"
yeet = 0
yn = gets.chomp
if yn == "y" || yn == "Yes" || yn == "Y" || yn == "yes" || yn == "yes!" || yn == "you got it" || yn == "Yes!" || yn == "You got it"
count += 1
  if count == 1
  puts "First try, and I've won!"
  elsif count <= 3
  puts "That was a pretty quick win!"
  elsif count >= 50
  puts "I thought I would never win!"
  elsif count <=9
  puts "That wasn't too bad--I win!"
  elsif count >=10
  puts "Finally, I've won!"
  end
  sleep(1)
  guess = 1000
else
#If it isn't, we need to make sure the computer guesses again.
  puts "No? Well, was my guess too high or too low?"
  puts "1. Too high"
  puts "2. Too low"
  hl = gets.chomp
  if max < min 
  max = 100
  min = 0
  elsif hl == "1" || hl == "too high" || hl == "Too high"
max = guess
elsif hl == "2" || hl == "too low" || hl == "Too low"
min = guess
  end
  count += 1
  end
end
end
gamee
elsif game == "m"
puts "Welcome to Madlibs!"
puts "We have 3 different templates. Picking a random one..."
sleep(1.5)
temp = rand(1..3)
if temp == 1
puts "You got template 1!"
puts "Input a singer's name (ex: Alessia Cara, Tyler Joseph, Famous Dex):"
name = gets.chomp
puts "Input a number, any number (ex: 1, 1000, 100000):"
number = gets.chomp
puts "Input an item (ex: chair, plate, book):"
item1 = gets.chomp
puts "Input a food (ex: spaghetti, ramen, poutine):"
food = gets.chomp
puts "Input another item (ex: computer, bag, pencil):"
item = gets.chomp
puts "Loading up your final madlibs..."
sleep(1.5)
puts "My friend and I were going to see a concert for our favorite singer: " + name + "! We had even bought the special VIP tickets on a sale price for only " + number + " dollars! But when we got to the meet-and-greet, we couldn't believe our eyes. " + name + " was sitting on a " + item1 + ", choking on " + food + "! We immediately tried to help, but " + name + " thought we were attacking and called security on us. When security came, they dragged us out of the venue and stole my " + item + " which I cherished more than anything. I'm never forgiving " + name + "!"
elsif temp == 2
puts "You got template 2!"
puts "Input a name (ex: Lily, Optimus Prime, Alyssa):"
name = gets.chomp
puts "Input a vacation spot (ex: Hawaii, the beach, Canada):"
place = gets.chomp
puts "Input a brand or store (ex: Gucci, Apple, Walmart):"
brand = gets.chomp
puts "Input a number, any number (ex: 1, 1000, 10000000):"
number = gets.chomp
puts "Input a song (ex: Hallelujah, Africa, the theme song of iCarly):"
song = gets.chomp
puts "Loading up your final madlib..."
sleep(1.5)
puts name + " and I were going on an exciting vacation to " + place + " in our private jet, which we had bought from " + brand + " for about " + number + " dollars USD. As the beautiful " + place + " came into view from our windows, we could not contain our joy! " + name + " started belting " + song + " and the whole cabin crew thought we were crazy!"
elsif temp == 3
puts "You got template 3!"
puts "Input a holiday (ex: Valentine's Day, Christmas, the Fourth of July):"
holiday = gets.chomp
puts "Input a place name (ex: Philadelphia, Idaho, RavenTown):"
place = gets.chomp
puts "Input an adjective (ex: dark, brilliant, glowing):"
adjective = gets.chomp
puts "Input a name (ex: Alex, Lil Pump, Taylor Swift):"
name = gets.chomp
puts "Input an emotion (ex: scared, excited, sad):"
emotion = gets.chomp
puts "Input an animal (ex: cougar, poodle, weasel):"
animal = gets.chomp
puts "Loading up your final madlib..."
sleep(1.5)
puts "It was the night before " + holiday + " in " + place + ". Everything was dark and quiet. Dare I say, it was " + adjective + "! " + name + " walked quietly along the sidewalk, feeling extremely " + emotion + ". Suddenly, a huge " + animal + " popped out of nowhere and attacked! " + name + " ran and was never seen again! To this day, the people of " + place + " still hear the cries of " + name + " on the eve of " + holiday + "..."
end
else
puts "That input was invalid."
end
puts ""
puts "Let's play another game!"
end
ruby 2.5.5p157 (2019-03-15 revision 67260) [x86_64-linux]
?