![]() * key and a sound file, which is played when the key is pressed. * This method makes the below keys when compile is hit or the program opens.ĪddObject (new Key ("g", "3a.wav"), i*63 + 54, 140) * A piano that can be played with the computer keyboard. Import greenfoot.* // (World, Actor, GreenfootImage, and Greenfoot) Here is the code example from the piano class: I am confused in general how the program knows that the keys are set from left to right in the first place. The remaining keys should be next to each other, with no space between them." Rewrite it (in this document only-not in your working Greenfoot program) to create the keys from right to left, instead of left to right, and force the rightmost key to be flush against the right side of the screen. With this information in mind, copy the new loop code you entered to correctly place the keys in the space below. Recall that the piano is 800 pixels wide. "According to the text, Greenfoot refers to objects by the midpoint of their lengths and widths. I am working on exercise 5.18 (not the same as the book example) and it says: ![]() However, now, at the end of the week it is starting to make a bit more sense.I am working on my assignment for school and this question has thrown me for a loop, no pun intended, this chapter is about loops and arrays. As one can see by the length of this post, there was a lot of new information for a beginner like me. This week was a bit overwhelming for me at first. The computer does not know what to do for the 12 position. This could occur, for example, when you have an array that has 12 positions but we have only put 11 assigned variables. Since there are a near infinite number of things that fall in this category, there are a near infinite number of ways to write programs that cause runtime errors. The computer understands the code, it is just that program instructs the computer to do something that it is either incapable or unwilling to do. A run time error, on the other hand, will compile. A syntax error will prevent the code from compiling, as the computer does not understand it. ![]() This could include misspelling a word, forgetting a semicolon, or forgetting a line of code. One final thing that was leaned this week was the difference between a syntax error and a run time error. A syntax error or format error is when you make a mistake in writing your code. The full six video playlist can be found here. These two videos are the last two of six videos that explain everything that is taught in chapter 5 of the Greenfoot textbook and is explained above. Each item in an array is called an element, and each element is accessed by its numerical index. Instead of having a separate code for each object that is needed, an array groups similar variables together. The length of an array is established when the array is created. An array is a container object that holds a fixed number of values of a single type. An array is an object that can hold many variables, and thus can store many values. This can be accomplished through a concept called an array. Now, we have the task of being able to control each piano key with its own keyboard key and to produce its own sound. If it is always true you will create an infinite loop, which means the instructions will be repeated an infinite amount of time. This is important because without it, the condition will always be true or never be true. We can make that sound play every time the crab eats a worm by adding a single line to our crab class that calls aySound after we remove a worm from the world: Give that a try. It is important to note that a counter that increases the variable must be included in the statements portion. The scenario comes with a sound ready for you to use, named 'eating.wav'. ![]() The general for a while loop is as follows: yesterday I need again help in my game, i need a background sound. This is similar to the for loop, although it has a few differences. How to add a loop background sound that goes in multiple levels and stops when the character dies. It can describe the characteristics of the object.Īnother new concept is the while loop. A constructor is called automatically when a new instance of an object is created. It constructs the values (provides data for the object). It is invoked at the time of object creation. Secondly, it has no return type (such as void, boolean, int, ect.). A constructor is a special type of method that is used to initialize the object. First of all, it has the same name as the class name. It looks a lot like a method, however, there are two big differences. This introduces a new topic, the constructor. ![]()
0 Comments
Leave a Reply. |
Details
AuthorWrite something about yourself. No need to be fancy, just an overview. ArchivesCategories |