//계산식을 초기화 시키는 메소드 private void ClearBtn_Click(object sender, EventArgs e) { result = 0; isNewNum = true; opt = operators.add; numResult.Text = "0"; }
private void AddBtn_Click(object sender, EventArgs e) { if (isNewNum == false) { //int num = Convert.ToInt32(numResult.Text); int num = int.Parse(numResult.Text); if (opt == operators.add) { result = result + num; } else if (opt == operators.sub) { result = result - num; } numResult.Text = result.ToString(); //새로운 숫자를 입력받기 위해 변수 값 변경 isNewNum = true; } Button optBtn = (Button)sender; if (optBtn.Text == "+") { opt = operators.add; } else if (optBtn.Text == "-") { opt = operators.sub; } }
private void pre_calc(operators op, float val) { if (is_paused) return; switch (op) { case operators.PLUS: prev += val; break; case operators.MINUS: prev -= val; break; case operators.MUL: if (prev == 0) prev = val; else prev *= val; break; case operators.DIV: if (val != 0) if (prev == 0) prev = val; else prev /= val; else error_handle(errors.DIVBY0); break; }; }
private void operate(operators op) { float cur; if (is_paused || !float.TryParse(inputBox.Text, out cur)) return; operated = true; pre_calc(cur_op, cur); switch (op) { case operators.PLUS: prevInputBox.Text += cur.ToString() + " + "; break; case operators.MINUS: prevInputBox.Text += cur.ToString() + " - "; break; case operators.MUL: prevInputBox.Text += cur.ToString() + " ✕ "; break; case operators.DIV: if (cur != 0) prevInputBox.Text += cur.ToString() + " ÷ "; else error_handle(errors.DIVBY0); break; } inputBox.Text = prev.ToString(); cur_op = op; }
internal List <operators> ChooseOperators(operators main, int size) { int newOp = 0; List <operators> op = new List <operators>(); switch (main) { case operators.AddSub: for (int i = 0; i < size; i++) { newOp = Random.Range(0, 2); op.Add((operators)newOp); } break; case operators.AddSubMult: op.Add(operators.Multiplication); newOp = Random.Range(0, 2); op.Add((operators)newOp); break; default: op.Add(operators.Division); newOp = Random.Range(0, 2); op.Add((operators)newOp); op.Add(operators.Multiplication); break; } return(op); }
private void eh_operator(operators value) { string text; text = calc_value.Text; switch (value) { case operators.DOT: if (!text.Contains(".")) { calc_value.Text = value + "."; } break; case operators.ADD: break; case operators.SUBTRACT: break; case operators.MULTIPLY: break; case operators.DIVIDE: break; case operators.EQUALS: break; } }
internal void SetCombatMusic(operators a_op, bool a_boss) { AudioClip adding = null; int op; if ((int)a_op > (int)operators.Division) { op = (int)operators.Fortress; } else { op = (int)a_op; } if (a_boss) { adding = combatMusic[op]; } else { adding = bossMusic[op]; } if (adding != null) { musicSource.clip = adding; musicSource.Play(); } }
private void Clear_Click(object sender, EventArgs e) { Result = 0; isNewNum = true; opt = operators.Add; // 기본값 NumScreen.Text = "0"; }
public ActionResult DeleteConfirmed(int id) { operators operators = db.operators.Find(id); db.operators.Remove(operators); db.SaveChanges(); return(RedirectToAction("Index")); }
public void displayHighScores(int ops) //Displaying best after changing our operator. { currentOperator = ops; operators op = (operators)ops; bestBox.text = monsterManager.highScores.returnRanking(op, showScores); }
public ActionResult Edit([Bind(Include = "id,full_name,experience,salary,id_region")] operators operators) { if (ModelState.IsValid) { db.Entry(operators).State = EntityState.Modified; db.SaveChanges(); return(RedirectToAction("Index")); } ViewBag.id_region = new SelectList(db.regions, "id", "name", operators.id_region); return(View(operators)); }
public double Calculate(double d1, operators op, double d2) { double res = op switch { operators.plus => res = Sum(d1, d2), operators.minus => res = Sub(d1, d2), operators.mult => res = Mult(d1, d2), operators.div => res = Div(d1, d2) }; return(res); }
public ActionResult Details(int?id) { if (id == null) { return(new HttpStatusCodeResult(HttpStatusCode.BadRequest)); } operators operators = db.operators.Find(id); if (operators == null) { return(HttpNotFound()); } return(View(operators)); }
public Question(int min, int max) { first = rnd.Next(min, max); second = rnd.Next(min, max); if(first < second) { int safe = first; first = second; second = safe; } currentOp = (operators)rnd.Next(0, 2); }
// GET: Operators/Edit/5 public ActionResult Edit(int?id) { if (id == null) { return(new HttpStatusCodeResult(HttpStatusCode.BadRequest)); } operators operators = db.operators.Find(id); if (operators == null) { return(HttpNotFound()); } ViewBag.id_region = new SelectList(db.regions, "id", "name", operators.id_region); return(View(operators)); }
//Above, but for scores. public int checkScore(operators op, float newScore, int andLevel, string playerName, int startingI = 0) { for (int i = startingI; i < 5; i++) { if (newScore > highScoreScore[i, (int)op]) { checkScore(op, highScoreScore[i, (int)op], highScoreLevel[i, (int)op], highScoreNames[i, (int)op], (i + 1)); highScoreScore[i, (int)op] = newScore; highScoreLevel[i, (int)op] = andLevel; highScoreNames[i, (int)op] = playerName; return(i); } } return(-1); }
//Check if we got a level higher than startingIndex //As an example, the external check would be first place, so 0. //If that was true, we'd continually check the score we're replacing is better than any other score. public int checkLevel(operators op, int newLevel, float andScore, string playerName, int startingIndex = 0) { for (int i = startingIndex; i < 5; i++) { if (newLevel > HighLevelLevels[i, (int)op]) { checkLevel(op, HighLevelLevels[i, (int)op], highLevelScore[i, (int)op], highLevelNames[i, (int)op], (i + 1)); HighLevelLevels[i, (int)op] = newLevel; highLevelScore[i, (int)op] = andScore; highLevelNames[i, (int)op] = playerName; return(i); } } return(-1); //We got no high score. }
//Return the highest score's stats, public string returnBest(operators op, bool Score) { string returning = ""; if (Score) { returning += "Best " + op.ToString() + " Score run by " + highScoreNames[0, (int)op] + "\n"; returning += "Points: " + highScoreScore[0, (int)op].ToString() + ". Levels: " + highScoreLevel[0, (int)op].ToString(); } else { returning += "Best " + op.ToString() + " Level run by " + highLevelNames[0, (int)op] + "\n"; returning += "Levels: " + HighLevelLevels[0, (int)op].ToString() + ". Points: " + highLevelScore[0, (int)op].ToString(); } return(returning); }
public void OperatorPress(operators inputOperator) { if (ResultValue == "") { OldValue = NewValue; } else { OldValue = ResultValue; } NewValue = ""; DecimalClicked = false; Operator = inputOperator; ResultValue = ""; MainDisplay = ""; SecondaryDisplay = OldValue; }
private void Add_Click(object sender, EventArgs e) { if (isNewNum == false) { float num = int.Parse(NumScreen.Text); if (opt == operators.Add) { Result = sum(Result, num); } else if (opt == operators.Sub) { Result = sub(Result, num); } else if (opt == operators.Multi) { Result = multi(Result, num); } else if (opt == operators.Div) { Result = division(Result, num); } NumScreen.Text = Result.ToString(); isNewNum = true; } Button optButton = (Button)sender; if (optButton.Text == "+") { opt = operators.Add; } else if (optButton.Text == "-") { opt = operators.Sub; } else if (optButton.Text == "*") { opt = operators.Multi; } else if (optButton.Text == "/") { opt = operators.Div; } }
//Checking if the calculation needs rounding. Returns true if yes. //a_operator is + or -, and a_digits as the number of digits of the comparison being made bool Rounding(float[] a_numbers, operators a_operator, int a_digits) { float[] shortened = new float[a_numbers.Length]; a_numbers.CopyTo(shortened, 0); for (int i = 0; i < a_numbers.Length; i++) { shortened[i] = a_numbers[i] % a_digits; } float total = shortened[0]; switch (a_operator) { case operators.Addition: for (int i = 1; i < a_numbers.Length; i++) { total += shortened[i]; } if (total >= a_digits) { return(true); } break; case operators.Subtraction: for (int i = 1; i < a_numbers.Length; i++) { total -= shortened[i]; } if (total < (a_digits / 10)) { return(true); } break; default: break; } return(false); }
private void calc(operators op, float val) { if (is_paused) return; switch (op) { case operators.PLUS: inputBox.Text = (prev + val).ToString(); break; case operators.MINUS: inputBox.Text = (prev - val).ToString(); break; case operators.MUL: inputBox.Text = (prev * val).ToString(); break; case operators.DIV: if (val != 0) inputBox.Text = (prev / val).ToString(); else error_handle(errors.DIVBY0); break; }; operated = false; }
//Return the Ranking scores. //No for loop because 1st, 2nd is different for each, and we'd need another array for that. public string returnRanking(operators op, bool Score) { int index = 0; string returning = ""; if (Score) { returning = op.ToString() + " Score Rankings:\n"; returning += "1st is " + highScoreNames[index, (int)op] + " at " + highScoreScore[index, (int)op].ToString() + " Points\n"; index++; returning += "2nd is " + highScoreNames[index, (int)op] + " at " + highScoreScore[index, (int)op].ToString() + " Points\n"; index++; returning += "3rd is " + highScoreNames[index, (int)op] + " at " + highScoreScore[index, (int)op].ToString() + " Points\n"; index++; returning += "4th is " + highScoreNames[index, (int)op] + " at " + highScoreScore[index, (int)op].ToString() + " Points\n"; index++; returning += "5th is " + highScoreNames[index, (int)op] + " at " + highScoreScore[index, (int)op].ToString() + " Points\n"; } else { returning = op.ToString() + " Level Rankings:\n"; returning += "1st is " + highLevelNames[index, (int)op] + " at " + HighLevelLevels[index, (int)op].ToString() + " Levels\n"; index++; returning += "2nd is " + highLevelNames[index, (int)op] + " at " + HighLevelLevels[index, (int)op].ToString() + " Levels\n"; index++; returning += "3rd is " + highLevelNames[index, (int)op] + " at " + HighLevelLevels[index, (int)op].ToString() + " Levels\n"; index++; returning += "4th is " + highLevelNames[index, (int)op] + " at " + HighLevelLevels[index, (int)op].ToString() + " Levels\n"; index++; returning += "5th is " + highLevelNames[index, (int)op] + " at " + HighLevelLevels[index, (int)op].ToString() + " Levels\n"; } return(returning); }
//A helper function that helps us do math based 2 operands and an operation /// <summary> /// returns (a op b), a applied operation on b /// </summary> /// <param name="op"></param> /// <param name="a"></param> /// <param name="b"></param> /// <returns></returns> int DoSomeMath(operators op, int a, int b) { int result = 0; switch (op) { case operators.addition: result = a + b; break; case operators.subtraction: result = a - b; break; case operators.multiplication: result = a * b; break; case operators.division: result = a / b; break; } return(result); }
//return a string based on an operation string OpToString(operators op) { string result = ""; switch (op) { case operators.addition: result = "+"; break; case operators.subtraction: result = "-"; break; case operators.multiplication: result = "*"; break; case operators.division: result = "/"; break; } return(result); }
internal void CalculateBODMAS(QuizButton a_running, int failures) { mainOp = a_running.Operator; variableCount = a_running.variableCount; variablesUsed = new List <float>(variableCount); variablesUsed = questionManager.randomiseBODMASNumbers(a_running); List <float> summingNumbers = new List <float>(5); List <operators> summingOps; summingOps = questionManager.ChooseOperators(a_running.Operator, (variableCount - 1)); StoredOps = new List <operators>(summingOps); //Randomise as many numbers as required, within range. for (int i = 0; i < variableCount; i++) { summingNumbers.Add((int)variablesUsed[i]); } if (a_running.Operator == operators.AddSubMultDiv) { AnswerNeeded = summingNumbers[0] / summingNumbers[1]; switch (summingOps[1]) { case operators.Addition: AnswerNeeded = AnswerNeeded + summingNumbers[2]; break; case operators.Subtraction: AnswerNeeded = AnswerNeeded - summingNumbers[2]; break; } AnswerNeeded = AnswerNeeded * summingNumbers[3]; } else { while (summingOps.Count > 0) { if (summingOps.Contains(operators.Division)) { int i = summingOps.IndexOf(operators.Division); summingNumbers[i] /= summingNumbers[(i + 1)]; summingNumbers.RemoveAt(i + 1); summingOps.RemoveAt(i); continue; } if (summingOps.Contains(operators.Multiplication)) { int i = summingOps.IndexOf(operators.Multiplication); summingNumbers[i] *= summingNumbers[(i + 1)]; summingNumbers.RemoveAt(i + 1); summingOps.RemoveAt(i); continue; } if (summingOps.Contains(operators.Addition)) { int i = summingOps.IndexOf(operators.Addition); summingNumbers[i] += summingNumbers[(i + 1)]; summingNumbers.RemoveAt(i + 1); summingOps.RemoveAt(i); continue; } if (summingOps.Contains(operators.Subtraction)) { int i = summingOps.IndexOf(operators.Subtraction); summingNumbers[i] -= summingNumbers[(i + 1)]; summingNumbers.RemoveAt(i + 1); summingOps.RemoveAt(i); continue; } } AnswerNeeded = summingNumbers[0]; } bool whole = questionManager.IsWhole(AnswerNeeded); //if Answer is too low/too high, or requires rounding to solve, we try again. if ((AnswerNeeded <= a_running.minAnswer || AnswerNeeded > a_running.maxAnswer || !whole) && failures < 20) { int failed = failures + 1; CalculateBODMAS(a_running, failed); return; } if (failures >= 20) { Debug.Log("Failed"); } ResetAll(); if (a_running.Operator == operators.AddSubMultDiv) { operatorsText[3].text = "("; operatorsText[0].text = " / "; operatorsText[1].text = " + "; operatorsText[2].text = ") x "; operatorsText[2].gameObject.SetActive(true); FortressButtons[3].gameObject.SetActive(true); } else { operatorsText[3].text = ""; for (int i = 0; i < 3; i++) { if (i < (variableCount - 1)) { switch (StoredOps[i]) { case operators.Addition: operatorsText[i].text = "+ "; break; case operators.Subtraction: operatorsText[i].text = "- "; break; case operators.Multiplication: operatorsText[i].text = "x "; break; case operators.Division: operatorsText[i].text = "/ "; break; default: break; } } } operatorsText[2].gameObject.SetActive(false); FortressButtons[3].gameObject.SetActive(false); } AnswerText.text = " = " + AnswerNeeded.ToString(); SetDraggers(); Defend.interactable = false; }
public Question(int num1, int num2, operators opPara) { currentOp = opPara; first = num1; second = num2; }
//Monster is initiated. public override void loadMonster() { ArrowsFired = false; ArrowContainer.SetActive(false); questions = FindObjectOfType <questionManager>(); if (!multipleContainer) { multipleContainer = FindObjectOfType <multipleContainer>(); } multipleContainer.SetAttacks(true, false); multipleContainer.DisableThisAndCalculator(); m_button = (BossButton)parent.quizRunning; Operator = parent.quizRunning.Operator; if (Operator == operators.Addition) //Addition resets in difficulty. { m_button.enemyChoices = 2; m_button.enemyAnswerRange = 3; bossSpacing = 4; } if (Operator > operators.Division && m_button.quizIndex < 9) { Fortress.SetPatience(5); } else { Fortress.patience.gameObject.SetActive(false); } if (sprite != null) { Destroy(sprite.gameObject); } if (parent.quizRunning.monsterArt != null) { sprite = Instantiate(parent.quizRunning.monsterArt, monsterSpot.transform, false); sprite.transform.localScale = parent.quizRunning.monsterArt.transform.localScale; animator = sprite.GetComponentInChildren <Animator>(); startingPosition = sprite.transform.localPosition; startingRotation = sprite.transform.localRotation; } enemyPhase = false; health = parent.quizRunning.MonsterHealth; attack = parent.quizRunning.MonsterAttack; if (Operator == operators.Multiplication) { bar.setMaxHealth(health, false, true); validNumbers = 2; multHealthOne = 4; multHealthTwo = 4; multHealthThree = 4; Heads = 3; multAttacks = 3; } else { bar.setMaxHealth(health, false); } if (!music) { music = FindObjectOfType <MusicManager>(); } if (music) { music.SetCombatMusic(parent.quizRunning.Operator, parent.quizRunning.boss); } if (Operator == operators.Subtraction) { subtractionContainer.SetUpSubtraction(health); } CreateQuestion(); }
//Generates either 1 or 2 operations based on difficulty/settings, and our parentheses IEnumerator GenerateOperations() { //Reset our operations to none op1 = operators.none; op2 = operators.none; //Reset our parentheses parentheses = false; //if our settings allow parentheses if (MathSettingManager.Instance.parentheses) { parentheses = true; //Generate a random position for our parentheses parenthesesPos = Random.Range(0, 2); } //List of operations based on settings, we will use this to generate our operations List <int> opList = new List <int>(); //Checking our settings to see what operations we want to include //0 = addition //1 = subtraction //2 = multiplcation //3 = division if (MathSettingManager.Instance.addition) { //add the + operation to the list to include it opList.Add(0); } if (MathSettingManager.Instance.subtraction) { //add the - operation to the list to include it opList.Add(1); } if (MathSettingManager.Instance.multiplication) { //add the * operation to the list to include it opList.Add(2); } if (MathSettingManager.Instance.division) { //add the / operation to the list to include it opList.Add(3); } //shuffle our list of operations to randomly choose operations for (int i = 0; i < opList.Count; i++) { int n = opList[i]; int rand = Random.Range(0, opList.Count); opList[i] = opList[rand]; opList[rand] = n; } //if our settings allow two operations if (MathSettingManager.Instance.twoOp) { //Finally we set the op2 to the first index of the randomly shuffled list of operations op2 = SetOp(opList[0]); } //Finally we set op1 to the 2nd index of the list op1 = SetOp(opList[1]); yield return(null); }