This site requires JavaScript, please enable it in your browser!
Greenfoot back
kmykyten17
kmykyten17 wrote ...

2015/2/12

Piano Modified

kmykyten17 kmykyten17

2015/2/12

#
After modifying the Greenfoot book Ch. 5 scenario, I've run into problems. Whenever the scenario is run, all the sounds would play at once, and error messages would appear in a separate window. Now, after attempting to solve it, it compiles with no errors but the stage does not appear. Help! Given, the points where the keys should spawn might not be orderly, as i can't see them to fix it. Thank you. import greenfoot.*; // (World, Actor, GreenfootImage, and Greenfoot) /** * A piano that can be played with the computer keyboard. * * @author: M. Kolling * @version: 0.1 */ public class Piano extends World { private String whiteKeys = { "a", "s", "d", "f", "g", "h", "j", "k", "l", ";", "'", "\\" }; private String whiteNotes = { "ZL", "BoF", "MoF", "NoS", "PoL", "RoS", "SoW", "TT", "Shop", "Epona", "Saria", "Sun" }; private String blackKeys = { "q", "w", "e", "t", "y", "u", "i", "o", "p", "" }; private String blackNotes = { "Wmll", "Lost Woods", "LOnLon", "HF", "Goron", "KK", "ZD", "KV", "DADADA", "DAAAA", "End" }; // Assigning keys and sounds /** * * Make the piano. */ public Piano() { super(1500, 400, 1); makeKeys(); } private void makeKeys() { for(int i = 0; i < whiteKeys.length; i++) { Key key = new Key(whiteKeys,whiteNotes+".mp3", "Rupee3.png", "Rupee3-2.png"); addObject(key, 50 + (i*110), 80); } for(int i = 0; i < blackKeys.length; i++){ if( ! blackKeys.equals("") ) { Key key = new Key(blackKeys, blackNotes+".mp3", "Rupee1.png", "Rupee1-1.png"); addObject(key, 50 + (1*110), 240); } } } }
davmac davmac

2015/2/12

#
Please use code tags
kmykyten17 kmykyten17

2015/2/13

#
Sorry, I apologize for that. Never posted before.
import greenfoot.*;  // (World, Actor, GreenfootImage, and Greenfoot)

/**
 * A piano that can be played with the computer keyboard.
 * 
 * @author: M. Kolling
 * @version: 0.1
 */
public class Piano extends World
{ 
    private String whiteKeys =
        { "a", "s", "d", "f", "g", "h", "j", "k", "l", ";", "'", "\\" };
    private String whiteNotes =
        { "ZL", "BoF", "MoF", "NoS", "PoL", "RoS", "SoW", "TT", "Shop", "Epona", "Saria", "Sun" };
    private String blackKeys =
        { "q", "w", "e", "t", "y", "u", "i", "o", "p", "" };
    private String blackNotes =
        { "Wmll", "Lost Woods", "LOnLon", "HF", "Goron", "KK", "ZD", "KV", "DADADA", "DAAAA", "End" };
        // Assigning keys and sounds
    /**
     * * Make the piano.
     */ 
    public Piano()
    {
       super(1500, 400, 1);
       makeKeys();
   } 
   private void makeKeys()
     {
        for(int i = 0; i < whiteKeys.length; i++)
      {
           Key key = new Key(whiteKeys,whiteNotes+".mp3", "Rupee3.png", "Rupee3-2.png");
              addObject(key, 50 + (i*110), 80);
         }
         
       for(int i = 0; i < blackKeys.length; i++){
           if( ! blackKeys.equals("") ) { 
              Key key = new Key(blackKeys, blackNotes+".mp3", "Rupee1.png", "Rupee1-1.png");
                addObject(key, 50 + (1*110), 240);
         }
      }
   }
}
Hopefully that should change it.
danpost danpost

2015/2/13

#
It seems strange that your black notes are placed lower in the world than the white ones (240 on line 39 as opposed to 80 on line 33). Also, line 39 has all black keys placed at the same location ( '50 + (1*110)' ) , being the x coordinate value is always evaluated to 160.
davmac davmac

2015/2/13

#
Your code wouldn't compile. Here you're assigning an array to a String variable:
    private String blackKeys =
        { "q", "w", "e", "t", "y", "u", "i", "o", "p", "" };
Did you post your code again, or did you just copy from your previous post and put that between code tags? You need to post it again fully. Your first post is wrong. You can't just copy the text from it.
You need to login to post a reply.