public async void TipForUser() { if (isSolved) { return; } if (currentTipStep + 1 > dicLevelToAllowTipStep[currentLevel]) { DependencyService.Get <IToastAndViberate>().ShowToast("Oop! Out of tip balance. Level " + LevelIntToText(currentLevel) + " only allow " + dicLevelToAllowTipStep[currentLevel].ToString() + " tips step."); return; } currentTipStep++; Algorithm algo = new Algorithm(); List <Node> listRes = algo.Solve(arrStyle); MapSaver mSaver = new MapSaver(listRes.Count, arrStyle, listRes); if (listRes.Count > 0) { Node firstSolveNode = listRes[0]; for (int i = 0; i < 4; i++) { int nextIndexX = firstSolveNode.index / 4 + dx[i]; int nextIndexY = firstSolveNode.index % 4 + dy[i]; if (nextIndexX >= 0 && nextIndexX < 4 && nextIndexY >= 0 && nextIndexY < 4) { int nextIndex = nextIndexX * 4 + nextIndexY; arrStyle[nextIndex] = !arrStyle[nextIndex]; UpdateButton(nextIndex, true); } } arrStyle[firstSolveNode.index] = !arrStyle[firstSolveNode.index]; UpdateButton(firstSolveNode.index, true); //DependencyService.Get<IToastAndViberate>().ShowToast("Pressed index " + firstSolveNode.index + ". There are " + (listRes.Count - 1) + " step(s) to solve."); //DependencyService.Get<IToastAndViberate>().Vibration(200); } if (IsSolved()) { isSolved = true; await Task.Delay(500); finishPage.SetStar(ConvertStepToRating(dicStepToMap[currentLevel][currentMapIndex].nSolvedStep)); await PopupNavigation.PushAsync(finishPage); } else { if (App._dbHelper.GetSetting().ShowTipPopup == 1) { //show tip popup tipPopup.SetToggle(true); tipPopupVM.IsOn = true; tipPopupVM.TipBalance = (dicLevelToAllowTipStep[currentLevel] - currentTipStep).ToString(); tipPopupVM.RemainSteps = "- At least " + (listRes.Count - 1).ToString() + " step to solve."; tipPopup.BindingContext = tipPopupVM; await Task.Delay(500); await PopupNavigation.PushAsync(tipPopup); } } }
private void SolveAndSave() { Algorithm algo = new Algorithm(); List <Node> listRes = algo.Solve(arrStyle); mapSaved = new MapSaver(listRes.Count, arrStyle, listRes); }
private void BuildMap(List <Gate> listGate) { foreach (Gate gate in listGate) { int key = gate.LevelID; bool[] arrStyle = stringToArrayBool(gate.Map); MapSaver map = new MapSaver(key, arrStyle, null); if (dicStepToMap.ContainsKey(key)) { dicStepToMap[key].Add(map); } else { dicStepToMap.Add(key, new List <MapSaver>()); dicStepToMap[key].Add(map); } } }
private void BuidMap(string strMapFull) { string[] arrMapLevel = strMapFull.Split(new String[] { "\r\n" }, StringSplitOptions.None); string[] arrAnswer = strMapFull.Split(new String[] { "\r\n" }, StringSplitOptions.None); int nCountStep = -1; int nMap = 0; for (int i = 0; i < arrMapLevel.Length; i++) { int tmpCount = -1; if (arrMapLevel[i] == "") { nCountStep = -1; continue; } else if (Int32.TryParse(arrMapLevel[i], out tmpCount)) { nCountStep = tmpCount; dicStepToMap.Add(nCountStep, new List <MapSaver>()); } else { mapServer = new MapSaver(); mapServer.nSolvedStep = nCountStep; mapServer.listResult = GetListNodeAnswer(arrAnswer[nMap]); mapServer.arrStyle = new bool[16]; for (int j = 0; j < 4; j++) { string row = arrMapLevel[j + i]; if (MakeEachRow(row, j) == false) { break; } } i += 4; dicStepToMap[nCountStep].Add(mapServer); nMap++; } } }