发新话题
打印

[讨论] 十以内加法代码精简

十以内加法代码精简

为自己的孩子设计的十以内加法,请高手们精简一下代码!
fscommand("fullscreen", "true");
Selection.setFocus(jieguo);//设定文本焦点
TextField.prototype.onChanged = function() {//限制输入文本为数字
if (this.text != "-" && isNaN(this.text)) {
  this.text = '';
}
};
var shu = 0;//初始化五角星数
next_btn._visible = 0;//继续按钮不可见
function shuzi() {//随机抽取和为十以内的数
fir_num = random(11);
sec_num = random(11);
if (fir_num+sec_num<=10) {
  fir_txt = fir_num;
  sec_txt = sec_num;
} else {
  cs();
}
}
shuzi();//打开程序就出现数字
function cs() {//保证每次出现和为十以内的数
shuzi();
}
function wjx(shu) {//出现五角星
_root.attachMovie("wjx_mc","wjx"+shu,shu);
_root["wjx"+shu]._x = 24+shu*50;
if (shu<7) {//第一行7个五角星
  _root["wjx"+shu]._y = 145;
} else if (shu>6 && shu<14) {//第二行7个五角星
  _root["wjx"+shu]._x = 24+(shu-7)*50;
  _root["wjx"+shu]._y = 145+50;
} else {
  for (var i = 1; i<15; i++) {//保证只出现两行五角星
   removeMovieClip(_root["wjx"+i]);
   _root.shu = 0;
  }
}
}
wc_btn.onPress = function() {//判断对错
if (jieguo.text != "") {
  if (fir_txt+sec_txt == jieguo.text) {
   wjx(shu);
   shu++;
   wc_btn._visible = 0;
   next_btn._visible = 1;
  } else {
   trace("做错了");
   wc_btn._visible = 0;
   next_btn._visible = 1;
  }
} else {
  trace("你还没做呢")
}
};
next_btn.onPress = function() {//出现下一题
jieguo.text = "";
shuzi();
wc_btn._visible = 1;
next_btn._visible = 0;
updateAfterEvent();//刷屏出现新数字
};
十以内加法1.0.fla (56.5 KB)

TOP

updateAfterEvent();//刷屏出现新数字

TOP

发新话题