protected void OnClickedOp(Button obj) { if (!isSelectedFirstNum) { return; } switch (obj.name) { case "op_add": calcOper = CalcOper.Add; break; case "op_sub": calcOper = CalcOper.Sub; break; case "op_mul": calcOper = CalcOper.Mul; break; case "op_div": calcOper = CalcOper.Div; break; } }
public void GenLevel(bool isNewLevel) { firstNum = Const.Invalid_Int; calcOper = CalcOper.None; SecondNum = Const.Invalid_Int; isSelectedFirstNum = false; leftCalcStepNum = 3; txtTips.text = ""; //所有的outline隐藏 HideOutline(); //结果牌隐藏 HideResult(); //显示扑克 ShowPoker(); //重置 if (!isNewLevel) { ResetPoker(); return; } //新生成 topLeftNum = Const.Invalid_Int; topRightNum = Const.Invalid_Int; bottomLeftNum = Const.Invalid_Int; bottomRightNum = Const.Invalid_Int; bool retCode = false; do { retCode = GenPoker(); }while (!retCode); }
protected void OnClickedNum(Button obj) { //一次运算中不能点同一位置的card if (firstNumCard == obj) { return; } obj.gameObject.GetComponent <Outline>().enabled = true; int operNum = Const.Invalid_Int; switch (obj.name) { //poker case "poker_topleft": operNum = topLeftNum; resultCard = btnResultTopLeft; break; case "poker_topright": operNum = topRightNum; resultCard = btnResultTopRight; break; case "poker_bottomleft": operNum = bottomLeftNum; resultCard = btnResultBottomLeft; break; case "poker_bottomright": operNum = bottomRightNum; resultCard = btnResultBottomRight; break; //result case "result_topleft": operNum = int.Parse(obj.GetComponentInChildren <Text>().text); resultCard = btnResultTopLeft; break; case "result_topright": operNum = int.Parse(obj.GetComponentInChildren <Text>().text); resultCard = btnResultTopRight; break; case "result_bottomleft": operNum = int.Parse(obj.GetComponentInChildren <Text>().text); resultCard = btnResultBottomLeft; break; case "result_bottomright": operNum = int.Parse(obj.GetComponentInChildren <Text>().text); resultCard = btnResultBottomRight; break; } bool shouldResult = false; switch (calcOper) { case CalcOper.None: firstNum = operNum; firstNumCard = obj; isSelectedFirstNum = true; break; case CalcOper.Add: firstNum += operNum; shouldResult = true; break; case CalcOper.Sub: firstNum -= operNum; shouldResult = true; break; case CalcOper.Mul: firstNum *= operNum; shouldResult = true; break; case CalcOper.Div: if (operNum == 0) { //除0处理 calcOper = CalcOper.None; firstNumCard.gameObject.GetComponent <Outline>().enabled = false; obj.gameObject.GetComponent <Outline>().enabled = false; return; } firstNum /= operNum; shouldResult = true; break; } if (shouldResult) { calcOper = CalcOper.None; isSelectedFirstNum = false; firstNumCard.gameObject.SetActive(false); obj.gameObject.SetActive(false); resultCard.gameObject.SetActive(true); resultCard.GetComponentInChildren <Text>().text = firstNum.ToString(); --leftCalcStepNum; if (leftCalcStepNum == 0) { if (firstNum == correctResult) { PageMgr.ShowPage <UIResult>(); return; } GenLevel(false); } } }