|
Coding!
Sept 10, 2011 23:59:00 GMT -5
Post by ♫Moonbane♫ on Sept 10, 2011 23:59:00 GMT -5
Yes, another thread in the General board! And yes, it's on coding I just downloaded a program called ruby www.ruby-lang.orgAnd yes, here it is! 1. puts 'What\'s your first name?' 2. name1 = gets.chomp 3. puts 'Alright then. What is your middle name?' 4. name2 = gets.chomp 5. puts 'I see, I see... Now, tell me. What\'s your last name?' 6. name3 = gets.chomp 7. name = name1 + name2 + name3 8. puts 'Did you know there are ' + name.length.to_s + ' characters in your name, ' + name1 + ' ' + name2 + ' ' + name3 + '?' All typed into Notepad++
|
|
|
Coding!
Sept 11, 2011 18:20:26 GMT -5
Post by IcelandicEel on Sept 11, 2011 18:20:26 GMT -5
Yay! Me too! Ruby is awesome, isn't it?
Try this one (it's a HTTYD game in ruby): Your goal is basically to get through the "Forbidden Friendship" scene alive.
---------- class NightFury def initialize() puts "While out walking in the woods, you find a resting Night Fury. You try to slowly back away, but the dragon wakes up. You decide to name it..." @name = gets.chomp @trust = 0 @hunger = 1 @happiness = 0 @done = false end def feed @hunger += 1 @trust += 1 case rand 8 when 0..2 string = 'You pull a whole Icelandic cod out of your vest and offer it to ' + @name + ', who swallows it in one gulp.' when 3 string = 'You sneak back to Berk for food. When you get there, you see a nice, juicy sheep carcass hanging on a wall. You drag that back and decide to offer it to ' + @name + '. ' + @name + ' grins and gobbles it up.' @hunger += 1 when 4 string = 'You are out of food, but cannot resist ' + @name + "'s cute expression, so you offer up your own hand. " if @hunger <= @trust # I love this line... string += @name + " takes a bite and purrs. You are delicious! ...And also writhing on the ground in agony." else string += @name + ' declines. After all, you are friends now.' @hunger -= 1 end when 5..7 string = 'You pull out of your vest a yellow-and-black striped eel. ' + @name + ' backs off, growling. What were you thinking, trying to feed an eel to a dragon?' @hunger -= 1 @trust -= 2 @happiness -= 1 end puts string self.kill? end def play case rand 7 when 0..3 puts 'You find a stick and sit down to draw in the dirt. ' + @name + ' is fascinated and begins to draw too... but with a giant branch.' when 4 puts 'Good thing you brought a sheep-hide frisbee! You toss it to ' + @name + ', who chases after it. You find out that retrieving it is a thing to be done carefully, but you both have a good time.' when 5..6 puts 'You and ' + @name + ' sit down to fish. You decide to grab a stick (fishing with your mouth like ' + @name + ' sounded less fun). You even catch a couple and share them with each other!' @hunger += 2 end @hunger -= 1 @happiness += 1 @trust += 1 self.kill? end def pet if @trust > 4 puts 'You reach out toward the dragon. ' + @name + ' snarls and you quickly retract your hand. But you are unfazed. You close your eyes, look away, and reach out again. The seconds pass like hours until... You feel warm scales press against your fingers -- the feeling makes you shudder. When you look up, you are staring right into ' + @name + "'s eyes. Your forbidden friendship has begun!" @done = true else puts @name + ' backs away, growling menacingly.' @trust -= 2 @happiness -= 1 self.kill? end end def kill case rand 3 when 0..1 string = 'You take out your dagger to try to kill ' + @name + ', but you are not quick enough. ' + @name + ' pins you down, but instead of killing you, roars into your ear and takes off, flying away clumsily.' @done = true else string = 'You take out your dagger and close your eyes. Trying not to think, you plunge the dagger into something soft. You hear the dragon cry out and feel something warm pooling at your feet, but you keep your eyes closed. You feel tears rolling down your face. You are a Viking now.' @done = true end puts string end def kill? string = "" if @trust < 0 string = 'You have frightened ' + @name + ' and the dragon charges at you. You run as fast as you can...' elsif @hunger < 0 string = 'However, ' + @name + ' is too hungry, and cannot resist the delicious Viking in front of him. He pins you down and you black out...' elsif @happiness < 0 string = 'But ' + @name + ' is incredibly unhappy and thinks it would be fun to claw at your face.' end if string != "" puts string + "\nYou wake up in your bed, covered in bandages and bruises. Your father is standing over you, looking down at you sorrowfully.\n\nYou are scarred for life. Please try again." @done = true end end def done @done end end puts dragon = NightFury.new while dragon.done == false puts puts "What do you want to do? Enter one: (feed | play | pet | kill)" input = gets.chomp puts case input when 'feed' dragon.feed when 'play' dragon.play when 'pet' dragon.pet when 'kill' dragon.kill else puts 'The dragon kills you. Follow the instructions next time and you might live.' break end end puts puts
|
|
|
Coding!
Sept 11, 2011 18:45:02 GMT -5
Post by toothless11 on Sept 11, 2011 18:45:02 GMT -5
Oh wow the part where you actually kill Toothless sounds sad and cruel . You should use that coding for a game! XD
|
|
|
Coding!
Sept 11, 2011 18:52:32 GMT -5
Post by ♫Moonbane♫ on Sept 11, 2011 18:52:32 GMT -5
hehe :3 I beat it.
|
|
|
Coding!
Sept 11, 2011 18:58:01 GMT -5
Post by toothless11 on Sept 11, 2011 18:58:01 GMT -5
It's confusing .
|
|
|
Coding!
Sept 11, 2011 19:21:32 GMT -5
Post by IcelandicEel on Sept 11, 2011 19:21:32 GMT -5
|
|
|
Coding!
Sept 11, 2011 19:28:11 GMT -5
Post by toothless11 on Sept 11, 2011 19:28:11 GMT -5
Lol like a java game or something . Wait, how did Scylla win? I don't get it. Can you play it just by reading the words? XD
|
|
|
Coding!
Sept 11, 2011 19:37:21 GMT -5
Post by IcelandicEel on Sept 11, 2011 19:37:21 GMT -5
If you know how to program in Ruby, then you could play it just by reading it. But you could also install Ruby on your computer and run the code (which would probably be better).
|
|
|
Coding!
Sept 11, 2011 19:41:37 GMT -5
Post by toothless11 on Sept 11, 2011 19:41:37 GMT -5
What happens if I run the code? IDK how to play in Ruby . I'll try it tomorrow when I get back from school.
|
|
|
Coding!
Sept 11, 2011 20:34:28 GMT -5
Post by IcelandicEel on Sept 11, 2011 20:34:28 GMT -5
You have to install Ruby first ( ruby-lang.org). That will let you run Ruby programs.
|
|
|
Coding!
Sept 11, 2011 20:36:53 GMT -5
Post by toothless11 on Sept 11, 2011 20:36:53 GMT -5
I'll do that tomorrow then ^^. Though idk how to play the game afterwards.
|
|
|
Coding!
Sept 12, 2011 16:24:13 GMT -5
Post by ♫Moonbane♫ on Sept 12, 2011 16:24:13 GMT -5
yes, without dying once Well, I have one question. If you've seen the movie WarGames, I'm trying to make a mini-Joshua. Just a few lines. Basic. But I got stuck. puts 'PLEASE INPUT STARTUP CODE' gets.chomp if CPE 1704 TKS puts 'Hello, Professor Falken.' puts 'Would you like to play a game? (YES | NO)' end gets if = 'NO' puts 'Oh, well, too bad then. Shutting down...' if = 'YES' end end puts 'Alright, then. Truth, or dare?' gets if = 'Truth' puts 'WHY WAS I CREATED?' gets puts 'THAT IS AN INVALID RESPONSE' if = 'Dare' puts 'I DARE YOU TO KILL YOURSELF.' end
|
|
|
Coding!
Sept 12, 2011 17:36:46 GMT -5
Post by IcelandicEel on Sept 12, 2011 17:36:46 GMT -5
Cool! That's lucky, I actually have seen WarGames! (I really don't see movies much) The code basically looks good. But you need to remember that when you use an "if" statement, there has to be something to compare the answer to. This: gets.chomp if = 'NO' ... Will not work, but this: if gets.chomp == 'NO' ... should work fine. Also remember to use a == instead of a = when comparing. Hopefully this makes sense (I've never been a good explainer). If not, I fixed this in the code, so this should work: puts 'PLEASE INPUT STARTUP CODE'
if gets.chomp == 'CPE 1704 TKS' puts 'Hello, Professor Falken.' puts 'Would you like to play a game? (YES | NO)' if gets.chomp == 'NO' puts 'Oh, well, too bad then. Shutting down...' else # if it is not 'NO'... puts 'Alright, then. Truth, or dare?' if gets.chomp == 'Truth' puts 'WHY WAS I CREATED?' # user input doesn't matter here -- it's always wrong :D gets else # meaning dare... puts 'I DARE YOU TO KILL YOURSELF.' end end end
Alternatively, you can use a "case" statement like I did in my game. This lets you compare user input options more easily. So: puts 'Truth or dare?'
case gets.chomp when 'Truth' puts 'WHY WAS I CREATED' when 'Dare' puts 'I DARE YOU TO KILL YOURSELF' when 'Toothless' puts 'WRONG MOVIE' end
Hope this helps!
|
|
|
Coding!
Sept 13, 2011 14:54:07 GMT -5
Post by ♫Moonbane♫ on Sept 13, 2011 14:54:07 GMT -5
awesome, thanks I get what you mean now ^^
|
|
|
Coding!
Sept 13, 2011 14:56:28 GMT -5
Post by toothless11 on Sept 13, 2011 14:56:28 GMT -5
I still don't get it at all .
|
|