2016年10月24日 星期一

Week 08 許家勝

記憶方塊





void setup() {
  size(600,600);
  background(#030202);

  buttons[0] = new Button(20,20,270,#00ff00);
  buttons[1] = new Button(310,20,270,#ff0000);
  buttons[2] = new Button(20,310,270,#ffff00);
  buttons[3] = new Button(310,310,270,#0000ff);

}


void draw() {

  for(Button currentButton : buttons) {
    currentButton.display();
  }

}

void mousePressed() {
 
    for(Button currentButton : buttons) {
      if(currentButton.isMouseOver() == true) {
        currentButton.isLightOn = true;
      }
    }
 
}

void mouseReleased() {
 
    for(Button currentButton : buttons) {
        currentButton.isLightOn = false;
    }
}
class Button {

  float myX;
  float myY;
  float mySize;
  color myColor;
  color myDarkColor;

  boolean isLightOn = false;

  Button(float tempX, float tempY, float tempSize, color tempColor) {
    myX = tempX;
    myY = tempY;
    mySize = tempSize;
    myColor = tempColor;
 
    myDarkColor = lerpColor(0, myColor, 0.5);
  }

  void display() {
 
    if(isLightOn) {
      fill(myColor);
    }
    else {
      fill(myDarkColor);
    }
 
    rect(myX, myY, mySize, mySize);
  }

  boolean isMouseOver() {

    if(mouseX > myX && mouseX < (myX + mySize) &&
       mouseY > myY && mouseY < (myY + mySize)) {
     
       return true;
    } else {
      return false;
    }
 
  }

}

Button [] buttons = new Button[4];



到今天的進度用了顯示出4個色塊
用滑鼠點擊色塊會變亮
但對於系統自動隨機產生顯示給玩家記憶
有點卡關了....

沒有留言:

張貼留言