Last class (the 11th) Michael and Charles both asked that I help them with their projects. I did, and hence did not get the chance to work on Greenfoot.
Today (May 13th) I did work on Greenfoot.
I Started with Chapter 5.5 - Usuing Loops: The while loop. This chapter taught me new commands such as:
while (condition)
{
statement;
statement;
}
and the version of that staement which I can use to tell the computer to loop a specific amount of times
int i = 0;
while (i < 100)
{
statement;
statement;
i = i + 1
}
In my piano class I added that type of statement to make the piano keys, and make each piano key play a sound. But then in chapter 5.6 I learned how to use and array so each key made a different sound.
I used string names to make sure that each piano key played when I pressed a keyboard key. Once I made the code so I could connect a key with a sound, I used the same type of code to fix my earlier code of placing keys. Instead of having 12 in one spot, I had 12 spread out evenly.
private void makeKeys()
{
int i = 0;
while (i < whiteKeys.length)
{
Key key = new Key(whiteKeys[i], whiteNotes[i] + ".wav";
addObject(key, 54 + (i*63), 140);
i = i + 1
}
}
No comments:
Post a Comment