private void setupNewQuestion() { vars = AlgorithmUtilities.RNG(Constants.MULTIPLY, numberOfVariables); //Debug AlgorithmUtilities.expandingVars(vars); for (int i = 0; i < gridValueList.Count; ++i) { gridValueList[i].init(); } setupQuestionString(vars); foreach (int i in vars) { Log.Debug(TAG, i + ""); } }
private void setupNewQuestion() { isFirstAnswerCorrect = false; vars = AlgorithmUtilities.RNG(Constants.MULTIPLY, numberOfVariables); //(ax + b)(cx + d) if (Constants.ONE_VAR == numberOfVariables) { for (int i = 0; i < gridValueList.Count; ++i) { gridValueList[i].init(); } setupQuestionString(vars); } foreach (int i in vars) { Log.Debug(TAG, i + ""); } }
public async void checkAnswers() { if (!isFirstAnswerCorrect) { GridValue[] gvArr = { midUpGV, midLowGV, midLeftGV, midRightGV }; if (AlgorithmUtilities.isFirstAnswerCorrect(vars, gvArr, numberOfVariables)) { isFirstAnswerCorrect = true; //Change color of draggable areas to signify "Done/Correct" upperLeftGrid.Drag += listeners.GridLayout_Drag; upperRightGrid.Drag += listeners.GridLayout_Drag; lowerLeftGrid.Drag += listeners.GridLayout_Drag; lowerRightGrid.Drag += listeners.GridLayout_Drag; //Shade red the other grids for (int i = 0; i < outerGridLayoutList.Count; ++i) { outerGridLayoutList[i].SetBackgroundResource(Resource.Drawable.shape); } for (int i = 0; i < innerGridLayoutList.Count; ++i) { innerGridLayoutList[i].SetBackgroundResource(Resource.Drawable.ok); innerGridLayoutList[i].Drag -= listeners.GridLayout_Drag; for (int j = 0; j < innerGridLayoutList[i].ChildCount; ++j) { var iv = innerGridLayoutList[i].GetChildAt(j) as AlgeTilesTextView; iv.LongClick -= listeners.clonedImageView_Touch; //iv.Visibility = ViewStates.Gone; } } expandedVars = AlgorithmUtilities.expandingVars(vars); foreach (var i in expandedVars) { Log.Debug(TAG, "Expanded in activity: " + i); } Toast.MakeText(Application.Context, "1:correct", ToastLength.Short).Show(); if (Constants.ONE_VAR == numberOfVariables) { x2ET.Enabled = true; xET.Enabled = true; oneET.Enabled = true; } else { x2ET.Enabled = true; y2ET.Enabled = true; xyET.Enabled = true; xET.Enabled = true; yET.Enabled = true; oneET.Enabled = true; } if (!muteToggle.Checked) { correct.Start(); } TileUtilities.generateInnerLayoutTileArrays(heightInPx, widthInPx, innerGridLayoutList, rectTileListList); upperRightGrid.drawRects(upperRightRectTileList); upperLeftGrid.drawRects(upperLeftRectTileList); lowerRightGrid.drawRects(lowerRightRectTileList); lowerLeftGrid.drawRects(lowerLeftRectTileList); } else { for (int i = 0; i < outerGridLayoutList.Count; ++i) { outerGridLayoutList[i].Drag -= listeners.GridLayout_Drag; } incorrectPrompt(innerGridLayoutList); Toast.MakeText(Application.Context, "1:incorrect", ToastLength.Short).Show(); } } else if (!isSecondAnswerCorrect) { Log.Debug(TAG, "isSecondAnswerCorrect branch"); GridValue[] gvArr = { upperLeftGV, upperRightGV, lowerLeftGV, lowerRightGV }; for (int i = 0; i < gvArr.Length; ++i) { Log.Debug(TAG, gvArr[i].ToString()); } if (AlgorithmUtilities.isSecondAnswerCorrect(expandedVars, gvArr, numberOfVariables)) { //Cancelling out int posX = 0; ViewGroup posXVG = null; if (upperRightGV.xVal != 0) { posX = upperRightGV.xVal; posXVG = upperRightGrid; } else { if (lowerLeftGV.xVal != 0) { posX = lowerLeftGV.xVal; posXVG = lowerLeftGrid; } } int posY = 0; ViewGroup posYVG = null; if (upperRightGV.yVal != 0) { posY = upperRightGV.yVal; posYVG = upperRightGrid; } else { if (lowerLeftGV.yVal != 0) { posY = lowerLeftGV.yVal; posYVG = lowerLeftGrid; } } int posXY = 0; ViewGroup posXYVG = null; if (upperRightGV.xyVal != 0) { posXY = upperRightGV.xyVal; posXYVG = upperRightGrid; } else { if (lowerLeftGV.xyVal != 0) { posXY = lowerLeftGV.xyVal; posXYVG = lowerLeftGrid; } } int negX = 0; ViewGroup negXVG = null; if (upperLeftGV.xVal != 0) { negX = upperLeftGV.xVal; negXVG = upperLeftGrid; } else { if (lowerRightGV.xVal != 0) { negX = lowerRightGV.xVal; negXVG = lowerRightGrid; } } int negY = 0; ViewGroup negYVG = null; if (upperLeftGV.yVal != 0) { negY = upperLeftGV.yVal; negYVG = upperLeftGrid; } else { if (lowerRightGV.yVal != 0) { negY = lowerRightGV.yVal; negYVG = lowerRightGrid; } } int negXY = 0; ViewGroup negXYVG = null; if (upperLeftGV.xyVal != 0) { negXY = upperLeftGV.xyVal; negXYVG = upperLeftGrid; } else { if (lowerRightGV.xyVal != 0) { negXY = lowerRightGV.xyVal; negXYVG = lowerRightGrid; } } int xToRemove = posX > negX ? negX : posX; List <AlgeTilesTextView> tobeRemovedX = new List <AlgeTilesTextView>(); List <AlgeTilesTextView> negTobeRemovedX = new List <AlgeTilesTextView>(); if (posX != 0 && negX != 0) { Log.Debug(TAG, "Cancelling out: " + posX + ", " + negX); Log.Debug(TAG, "To remove: " + xToRemove); for (int j = 0; j < posXVG.ChildCount; ++j) { AlgeTilesTextView alIV = posXVG.GetChildAt(j) as AlgeTilesTextView; if (alIV.getTileType().Equals(Constants.X_TILE) || alIV.getTileType().Equals(Constants.X_TILE_ROT)) { tobeRemovedX.Add(alIV); } } for (int j = 0; j < negXVG.ChildCount; ++j) { AlgeTilesTextView negalIV = negXVG.GetChildAt(j) as AlgeTilesTextView; if (negalIV.getTileType().Equals(Constants.X_TILE) || negalIV.getTileType().Equals(Constants.X_TILE_ROT)) { negTobeRemovedX.Add(negalIV); } } } int yToRemove = posY > negY ? negY : posY; List <AlgeTilesTextView> tobeRemovedY = new List <AlgeTilesTextView>(); List <AlgeTilesTextView> negTobeRemovedY = new List <AlgeTilesTextView>(); if (posY != 0 && negY != 0) { Log.Debug(TAG, "Cancelling out: " + posY + ", " + negY); Log.Debug(TAG, "To remove: " + yToRemove); for (int j = 0; j < posYVG.ChildCount; ++j) { AlgeTilesTextView alIV = posYVG.GetChildAt(j) as AlgeTilesTextView; if (alIV.getTileType().Equals(Constants.Y_TILE) || alIV.getTileType().Equals(Constants.Y_TILE_ROT)) { tobeRemovedY.Add(alIV); } } for (int j = 0; j < negYVG.ChildCount; ++j) { AlgeTilesTextView negalIV = negYVG.GetChildAt(j) as AlgeTilesTextView; if (negalIV.getTileType().Equals(Constants.Y_TILE) || negalIV.getTileType().Equals(Constants.Y_TILE_ROT)) { negTobeRemovedY.Add(negalIV); } } } int xyToRemove = posXY > negXY ? negXY : posXY; List <AlgeTilesTextView> tobeRemovedXY = new List <AlgeTilesTextView>(); List <AlgeTilesTextView> negTobeRemovedXY = new List <AlgeTilesTextView>(); if (posXY != 0 && negXY != 0) { Log.Debug(TAG, "Cancelling out: " + posXY + ", " + negXY); Log.Debug(TAG, "To remove: " + xyToRemove); for (int j = 0; j < posXYVG.ChildCount; ++j) { AlgeTilesTextView alIV = posXYVG.GetChildAt(j) as AlgeTilesTextView; if (alIV.getTileType().Equals(Constants.XY_TILE) || alIV.getTileType().Equals(Constants.XY_TILE_ROT)) { tobeRemovedXY.Add(alIV); } } for (int j = 0; j < negXYVG.ChildCount; ++j) { AlgeTilesTextView negalIV = negXYVG.GetChildAt(j) as AlgeTilesTextView; if (negalIV.getTileType().Equals(Constants.XY_TILE) || negalIV.getTileType().Equals(Constants.XY_TILE_ROT)) { negTobeRemovedXY.Add(negalIV); } } } //Added changing color of tiles to be cancelled and 2 second delay before cancelling out for (int j = 0; j < xToRemove; ++j) { tobeRemovedX[j].SetBackgroundResource(Resource.Drawable.cancelling); negTobeRemovedX[j].SetBackgroundResource(Resource.Drawable.cancelling); } for (int j = 0; j < yToRemove; ++j) { tobeRemovedY[j].SetBackgroundResource(Resource.Drawable.cancelling); negTobeRemovedY[j].SetBackgroundResource(Resource.Drawable.cancelling); } for (int j = 0; j < xyToRemove; ++j) { tobeRemovedXY[j].SetBackgroundResource(Resource.Drawable.cancelling); negTobeRemovedXY[j].SetBackgroundResource(Resource.Drawable.cancelling); } if (xToRemove + yToRemove + xyToRemove > 0) { await Task.Delay(Constants.CANCELOUT_DELAY); } for (int j = 0; j < xToRemove; ++j) { posXVG.RemoveView(tobeRemovedX[j]); negXVG.RemoveView(negTobeRemovedX[j]); } for (int j = 0; j < yToRemove; ++j) { posYVG.RemoveView(tobeRemovedY[j]); negYVG.RemoveView(negTobeRemovedY[j]); } for (int j = 0; j < xyToRemove; ++j) { posXYVG.RemoveView(tobeRemovedXY[j]); negXYVG.RemoveView(negTobeRemovedXY[j]); } //End Cancelling out Toast.MakeText(Application.Context, "2:correct", ToastLength.Short).Show(); if (!muteToggle.Checked) { correct.Start(); } //Loop through inner and prevent deletions by removing: listeners.clonedImageView_Touch for (int i = 0; i < outerGridLayoutList.Count; ++i) { outerGridLayoutList[i].SetBackgroundResource(Resource.Drawable.ok); outerGridLayoutList[i].Drag -= listeners.GridLayout_Drag; for (int j = 0; j < outerGridLayoutList[i].ChildCount; ++j) { var iv = outerGridLayoutList[i].GetChildAt(j) as AlgeTilesTextView; iv.LongClick -= listeners.clonedImageView_Touch; } } //Removing outer grid after 2nd correct (10-28-2016) upperRightGrid.clearRects(heightInPx, widthInPx); upperLeftGrid.clearRects(heightInPx, widthInPx); lowerRightGrid.clearRects(heightInPx, widthInPx); lowerLeftGrid.clearRects(heightInPx, widthInPx); upperRightRectTileList.Clear(); upperLeftRectTileList.Clear(); lowerRightRectTileList.Clear(); lowerLeftRectTileList.Clear(); isSecondAnswerCorrect = true; } else { Toast.MakeText(Application.Context, "2:incorrect", ToastLength.Short).Show(); incorrectPrompt(outerGridLayoutList); } } else if (!isThirdAnswerCorrect) { //TODO: Accomodate for two variables if (Constants.ONE_VAR == numberOfVariables) { int[] answer = new int[3]; int temp = 0; answer[0] = int.TryParse(x2ET.Text, out temp) ? temp : 0; answer[1] = int.TryParse(xET.Text, out temp) ? temp : 0; answer[2] = int.TryParse(oneET.Text, out temp) ? temp : 0; if ((Math.Abs(answer[0]) + Math.Abs(answer[1]) + Math.Abs(answer[2])) == 0) { isThirdAnswerCorrect = false; } else { if (expandedVars[0] == answer[0] && expandedVars[1] == answer[1] && expandedVars[2] == answer[2]) { isThirdAnswerCorrect = true; } } } else { int[] answer = new int[6]; int temp = 0; answer[0] = int.TryParse(x2ET.Text, out temp) ? temp : 0; answer[1] = int.TryParse(y2ET.Text, out temp) ? temp : 0; answer[2] = int.TryParse(xyET.Text, out temp) ? temp : 0; answer[3] = int.TryParse(xET.Text, out temp) ? temp : 0; answer[4] = int.TryParse(yET.Text, out temp) ? temp : 0; answer[5] = int.TryParse(oneET.Text, out temp) ? temp : 0; foreach (int i in answer) { Log.Debug(TAG, "answer:" + i); } foreach (int i in expandedVars) { Log.Debug(TAG, "expandedVars:" + i); } if ((Math.Abs(answer[0]) + Math.Abs(answer[1]) + Math.Abs(answer[2]) + Math.Abs(answer[3]) + Math.Abs(answer[4]) + Math.Abs(answer[5])) == 0) { isThirdAnswerCorrect = false; } else { if (expandedVars[0] == answer[0] && expandedVars[1] == answer[1] && expandedVars[2] == answer[2] && expandedVars[3] == answer[3] && expandedVars[4] == answer[4] && expandedVars[5] == answer[5]) { isThirdAnswerCorrect = true; } } } if (isThirdAnswerCorrect) { Toast.MakeText(Application.Context, "3:correct", ToastLength.Short).Show(); for (int i = 0; i < editTextList.Count; ++i) { editTextList[i].SetBackgroundResource(Resource.Drawable.ok); editTextList[i].Enabled = false; } if (!muteToggle.Checked) { correct.Start(); } } else { Toast.MakeText(Application.Context, "3:incorrect", ToastLength.Short).Show(); incorrectPrompt(editTextList); } } }