Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP
Browse files

Fixes code in lessons 8 & 9

  • Loading branch information...
commit dd97565b531acb63d662484b18bffa9543b3be3a 1 parent 034a2db
@deadprogram deadprogram authored
View
9 public/help/en/ruby4kids/lesson_8.html
@@ -22,6 +22,7 @@
loadCode("#code-8-5", "../../shared/ruby4kids/code8_5.rb");
loadCode("#code-8-6", "../../shared/ruby4kids/code8_6.rb");
loadCode("#code-8-7", "../../shared/ruby4kids/code8_7.rb");
+ loadCode("#code-8-8", "../../shared/ruby4kids/code8_8.rb");
});
</script>
</head>
@@ -96,17 +97,17 @@
<article class="lesson"><h1>Lesson 8 - Escape Key Pauses the Game</h1>
<section class="page"><h1>Read, Set, Reset!</h1>
-
+
<p>Finally, we’re going to replace those two areas where we’ve repeated:</p>
<pre id="code-8-6" class="sampleCode">Code automatically inserted here...</pre>
<p>and replace it with <code>reset!</code>. Again, those two repetitions are under <code>def initialize</code> and <code>def update</code>. Your end result should look like this:</p>
-
+
<pre id="code-8-7" class="sampleCode">Code automatically inserted here...</pre>
-
+
<p>Yet again, here is the entire program you should have written so far:</p>
- <pre id="code-8-7" class="sampleCode">Code automatically inserted here...</pre>
+ <pre id="code-8-8" class="sampleCode">Code automatically inserted here...</pre>
<p>That’s it for this lesson! You're starting to like this stuff, aren't you?! Now, let’s make the game more challenging by adding <a href="lesson_9.html">multiple balls in lesson 9</a>!</p>
View
9 public/help/en/ruby4kids/lesson_9.html
@@ -60,18 +60,21 @@
<article class="lesson"><h1>Lesson 9 - Creating Multiple Balls</h1>
<section class="page"><h1>Pluralize!</h1>
- <p>Now, let's try adding 3 more balls! So, we'll go to the <code>MyGame<.code> class and change some things under <code>def initialize</code>:</p>
+ <p>Now, let's try adding 3 more balls! So, we'll go to the <code>MyGame</code> class and change some things under <code>def initialize</code>:</p>
<pre id="code-9-3" class="sampleCode">Code automatically inserted here...</pre>
+
<p>All we did above was pluralize <code>ball</code> and then changed the code to create 3 balls, instead of one.</p>
-
<p>Next, let's update each ball, instead of just updating one of them. We'll also pluralize the <code>@ball</code>. So,under the class, <code>MyGame</code>, we'll go ahead and change the code to:</p>
<pre id="code-9-4" class="sampleCode">Code automatically inserted here...</pre>
+
<p> Next, we're going to do some more of the same stuff. So, we'll go to <code>def draw</code> to pluralize <code>@ball</code> and to change the code so that it draws each ball, instead of just one. You should end up with the following:</p>
<pre id="code-9-5" class="sampleCode">Code automatically inserted here...</pre>
+
<p>Since we're already pluralizing, why don't we go ahead and do some more! So, we'll go to the class, <code>Player</code>, and change it to the following: </p>
+
<pre id="code-9-6" class="sampleCode">Code automatically inserted here...</pre>
<p> Again, we're just adjusting the methods, so that they will work with multiple balls. For the code above, we have added the method, <code>any?</code>, which just means that being hit by any one of the balls will cause a hit. </p>
@@ -96,7 +99,7 @@
<pre id="code-9-8" class="sampleCode">Code automatically inserted here...</pre>
<p>Can it be? Is this the end? Have you really gone through the entire tutorial? The answer is, YES! CONGRATULATIONS, YOU MADE IT! You developed a program that you can play on and show off! We hope you'll continue your interest into programming, because if you've made it this far, you've got what it takes :).</p>
-
+
<a href="#prev" class="prev-lesson">&laquo; Back</a>
<a href="index.html">Back to Lessons</a>
<a href="#next" class="next-lesson">Next &raquo;</a>
View
12 public/help/shared/ruby4kids/code8_8.rb
@@ -32,7 +32,7 @@ def update
stop_game!
end
else
- #the game is currently stopped
+ # the game is currently stopped
if button_down? Gosu::Button::KbEscape
restart_game
end
@@ -51,6 +51,7 @@ def stop_game!
def restart_game
@running = true
@ball.reset!
+ end
end
class Player
@@ -74,10 +75,10 @@ def move_left
end
def move_right
- if @x > @game_window.width - 100)
+ if @x > (@game_window.width - 100)
@x = @game_window.width - 100
else
- @x = x + 10
+ @x = @x + 10
end
end
@@ -105,7 +106,7 @@ def hit_by?(ball)
class Ball
def initialize(game_window)
@game_window = game_window
- @icon = Gosu::Image.new(@game_window, "Images/ball.png", true)
+ @icon = Gosu::Image.new(@game_window, "gosu/asteroid.png", true)
reset!
end
@@ -133,8 +134,7 @@ def reset!
@y = 0
@x = rand(@game_window.width)
end
-
end
window = MyGame.new
-window.show
View
11 public/help/shared/ruby4kids/code9_8.rb
@@ -50,7 +50,8 @@ def stop_game!
def restart_game
@running = true
- @balls.each {|ball| ball.reset!}.reset!
+ @balls.each {|ball| ball.reset!}
+ end
end
class Player
@@ -74,10 +75,10 @@ def move_left
end
def move_right
- if @x > @game_window.width - 100)
+ if @x > (@game_window.width - 100)
@x = @game_window.width - 100
else
- @x = x + 10
+ @x = @x + 10
end
end
@@ -105,7 +106,7 @@ def hit_by?(balls)
class Ball
def initialize(game_window)
@game_window = game_window
- @icon = Gosu::Image.new(@game_window, "Images/ball.png", true)
+ @icon = Gosu::Image.new(@game_window, "gosu/asteroid.png", true)
reset!
end
@@ -137,4 +138,4 @@ def reset!
end
window = MyGame.new
-window.show
Please sign in to comment.
Something went wrong with that request. Please try again.