为什么 case 在 switch 中不能按预期工作?

问题描述

我有这个代码。当按下键时,n 值发生变化并绘制不同的东西。问题是每次它在最后一种情况下绘制东西。

int n = 0;
void setup(){
  size(900,600);
  background(0,0);
  nostroke();
}
void draw()
{
  switch (n) {
  case 1:
    fill(255,255,0);
    quad(0,height,width,0);
    fill(255,height/4,height*3/4,height*3/4);
  case 3:
    fill(255,255);
    quad(0,0);
    fill(220,20,60);
    ellipse(width/2,height/2,3*height/5,3*height/5);
  default: println("a"+n);
 }
}
void keypressed() {
  
  if (n == 3) {
    n = 1;
  } else {
    n ++;
  };
}

解决方法

暂无找到可以解决该程序问题的有效方法,小编努力寻找整理中!

如果你已经找到好的解决方法,欢迎将解决方案带上本链接一起发送给小编。

小编邮箱:dio#foxmail.com (将#修改为@)