protected override void OnNavigatedTo(System.Windows.Navigation.NavigationEventArgs e) { base.OnNavigatedTo(e); puzzleAdapter = (Application.Current as mPuzzle.App).puzzleAdapter; puzzleId = puzzleAdapter.selectedPuzzle; curPuzzle = puzzleAdapter.puzzleDic[puzzleId]; ImageBrush ib = new ImageBrush(); Uri imageUri = new Uri(curPuzzle.puzzleThumbnail, UriKind.Relative); puzzleThumbnail.Source = new BitmapImage(imageUri); }
public PuzzleResult(Puzzle puzzle) { timeeasy = puzzle.timeeasy; timemedium = puzzle.timemedium; timehard = puzzle.timehard; timeexpert = puzzle.timeexpert; moveseasy = puzzle.moveseasy; movesmedium = puzzle.movesmedium; moveshard = puzzle.moveshard; movesexpert = puzzle.movesexpert; puzzleid = puzzle.id; }
public GameController(int elx, int ely, Puzzle p, GameViewController gvc, IPuzzleGamePage pgp) { elementsX = elx; elementsY = ely; puzzle = p; gameViewController = gvc; gamePage = pgp; inputState = InputState.RELEASED_NO_SELECTION; randomize(elx, ely); gameViewController.setRandomization(randomMask); assembled = false; startTime = 0; thread = new GameThread(this); }
public void update(Puzzle puzzle) { name = puzzle.name; type = puzzle.genTypeString; dimensions = puzzle.genDimensionsString; if (puzzle.opened) { closedVisibility = Visibility.Collapsed; otherVisibility = Visibility.Visible; } else { closedVisibility = Visibility.Visible; otherVisibility = Visibility.Collapsed; } puzzleThumbnail = puzzle.puzzleThumbnail; timeeasy = Utils.formatTime(puzzle.timeeasy); timemedium = Utils.formatTime(puzzle.timemedium); timehard = Utils.formatTime(puzzle.timehard); timeexpert = Utils.formatTime(puzzle.timeexpert); moveseasy = puzzle.moveseasy; movesmedium = puzzle.movesmedium; moveshard = puzzle.moveshard; movesexpert = puzzle.movesexpert; timeeasyb = Utils.formatTime(puzzle.timeeasyb); timemediumb = Utils.formatTime(puzzle.timemediumb); timehardb = Utils.formatTime(puzzle.timehardb); timeexpertb = Utils.formatTime(puzzle.timeexpertb); moveseasyb = puzzle.moveseasyb; movesmediumb = puzzle.movesmediumb; moveshardb = puzzle.moveshardb; movesexpertb = puzzle.movesexpertb; placeeasy = puzzle.easyp; placemedium = puzzle.mediump; placehard = puzzle.hardp; placeexpert = puzzle.expertp; id = puzzle.id; opened = puzzle.opened; NotifyPropertyChanged(null); }
protected override void OnNavigatedTo(System.Windows.Navigation.NavigationEventArgs e) { base.OnNavigatedTo(e); reload = State.ContainsKey("assembled"); // reload puzzles and page state if (reload) { itime = (long)State["itime"]; imoves = (int)State["imoves"]; nextPuzzleOpened = (bool)State["nextPuzzleOpened"]; time = Utils.formatTime(itime); moves = imoves.ToString(); assembled = (bool)State["assembled"]; if (assembled) { prevTime = (long)State["prevTime"]; prevMoves = (int)State["prevMoves"]; uploaded = (bool)State["uploaded"]; if (uploaded) { internetBestMoves = (int)State["internetBestMoves"]; internetBestTime = (long)State["internetBestTime"]; internetPlace = (int)State["internetPlace"]; } } } puzzleAdapter = (Application.Current as mPuzzle.App).puzzleAdapter; puzzle = puzzleAdapter.puzzleDic[puzzleAdapter.selectedPuzzle]; diff = puzzleAdapter.selectedDifficulty; gameViewController = new GameViewController(3 + (int)diff, 5 + (int)diff, gameCanvas, Dispatcher); gameController = new GameController(3 + (int)diff, 5 + (int)diff, puzzle, gameViewController, this); if (reload) { gameViewController.digout(this.State); gameController.digout(this.State); if (assembled) { if (uploaded) { scorePanelInternet.Visibility = Visibility.Visible; resPlace.Text = internetPlace.ToString(); res4.Text = " Time: " + Utils.formatTime(internetBestTime) + "; Moves: " + internetBestMoves; scorePanelInternet.Visibility = Visibility.Visible; } else { buttonUpload.Visibility = Visibility.Visible; } bool betterScore = (imoves < prevMoves) || (imoves == prevMoves && itime < prevTime) || (prevMoves == 0 && prevTime == 0); if (betterScore) beterScoreText.Text = " Better score achieved!"; else beterScoreText.Text = " "; res1.Text = " Time: " + time + "; Moves: " + moves; res2.Text = " Time: " + Utils.formatTime(prevTime) + "; Moves: " + prevMoves; scorePanel.Visibility = Visibility.Visible; if (nextPuzzleOpened) buttonNextPuzzle.Visibility = Visibility.Visible; buttonPause.Visibility = Visibility.Collapsed; } movesText.Text = moves; timeText.Text = time; } Uri bitmapUri = new Uri(puzzle.puzzleImage, UriKind.Relative); BitmapImage bitmap = new BitmapImage(bitmapUri); bitmap.ImageOpened += new EventHandler<RoutedEventArgs>(bitmap_Loaded); gameViewController.setBitmap(bitmap); }
public PuzzleViewInfo(Puzzle puzzle) { update(puzzle); }
public void sync(Puzzle[] puzzles, int userid, IRestCallback cb) { if (!NetworkInterface.GetIsNetworkAvailable()) { cb.syncAllCallback(false, null); return; } lock (this) { if (webRequest != null) { cb.syncAllCallback(false, null); return; } } callback = cb; string request = String.Format(USERNAME_SERVICE + "/{0}/puzzle", userid); webRequest = (HttpWebRequest)WebRequest.Create(new Uri(request)); webRequest.Method = "POST"; IAsyncResult result = webRequest.BeginGetRequestStream(new AsyncCallback(requestSyncAllCreateStream), new SyncAllRequest(puzzles)); timer = new Timer(new TimerCallback(requestSyncAllTimeout), callback, 15 * 1000, Timeout.Infinite); }
public SyncAllRequest(Puzzle[] puzzles) { puzzleResults = new PuzzleResult[puzzles.Length]; int i = 0; foreach (Puzzle puzzle in puzzles) { puzzleResults[i] = new PuzzleResult(puzzle); ++i; } }
private void _iloadPuzzles() { Uri uri = new Uri(PUZZLES_LIST, UriKind.Relative); StreamResourceInfo sri = App.GetResourceStream(uri); XElement xe = XElement.Load(sri.Stream); sri.Stream.Close(); int puzzleCount = xe.Elements("Puzzle").Count(); if (puzzleCount > 0) { IEnumerable<XElement> ien = xe.Elements("Puzzle"); puzzle = new Puzzle[puzzleCount]; Puzzle tempPuzzle; int i = 0; foreach (XElement curPuzzle in ien) { tempPuzzle = new Puzzle(); //read puzzle id tempPuzzle.id = (int)curPuzzle.Element("id"); //read puzzle name tempPuzzle.name = (string)curPuzzle.Element("name"); //is puzzle opened? if (i < openedPuzzles) tempPuzzle.opened = true; else tempPuzzle.opened = false; //read puzzle picture filename string path = tempPuzzle.filepath = (string)curPuzzle.Element("path"); //read filetype if (path.EndsWith(Puzzle.JPG_FILE)) tempPuzzle.filetype = FileType.JPG; else if (path.EndsWith(Puzzle.PNG_FILE)) tempPuzzle.filetype = FileType.PNG; tempPuzzle.puzzleThumbnailBase = path.Substring(0, path.Length - 4) + "_thumbnail"; tempPuzzle.puzzleImage = path; //read x dimension tempPuzzle.xdimension = (int)curPuzzle.Element("xdimension"); //read y dimension tempPuzzle.ydimension = (int)curPuzzle.Element("ydimension"); if (tempPuzzle.ydimension >= tempPuzzle.xdimension) tempPuzzle.orientation = Orientation.PORTRAIT; else tempPuzzle.orientation = Orientation.LANDSCAPE; puzzle[i] = tempPuzzle; puzzleDic.Add(tempPuzzle.id, tempPuzzle); if (stop_flag) return; ++i; //if (puzzleLoader != null) // puzzleLoader.reportProgress(i / puzzleCount * 100); } } }
protected override void OnNavigatedTo(System.Windows.Navigation.NavigationEventArgs e) { base.OnNavigatedTo(e); reload = State.ContainsKey("assembled"); // reload puzzles and page state if (reload) { itime = (long)State["itime"]; imoves = (int)State["imoves"]; nextPuzzleOpened = (bool)State["nextPuzzleOpened"]; time = Utils.formatTime(itime); moves = imoves.ToString(); assembled = (bool)State["assembled"]; if (assembled) { prevTime = (long)State["prevTime"]; prevMoves = (int)State["prevMoves"]; uploaded = (bool)State["uploaded"]; if (uploaded) { internetBestMoves = (int)State["internetBestMoves"]; internetBestTime = (long)State["internetBestTime"]; internetPlace = (int)State["internetPlace"]; } } } puzzleAdapter = (Application.Current as mPuzzle.App).puzzleAdapter; puzzle = puzzleAdapter.puzzleDic[puzzleAdapter.selectedPuzzle]; diff = puzzleAdapter.selectedDifficulty; gameViewController = new GameViewController(5 + (int)diff, 3 + (int)diff, gameCanvas, Dispatcher); gameController = new GameController(5 + (int)diff, 3 + (int)diff, puzzle, gameViewController, this); if (reload) { gameViewController.digout(this.State); gameController.digout(this.State); if (assembled) { if (uploaded) { scorePanelInternet.Visibility = Visibility.Visible; resPlace.Text = internetPlace.ToString(); res4.Text = " Time: " + Utils.formatTime(internetBestTime) + "; Moves: " + internetBestMoves; scorePanelInternet.Visibility = Visibility.Visible; } else { buttonUpload.Visibility = Visibility.Visible; } bool betterScore = (imoves < prevMoves) || (imoves == prevMoves && itime < prevTime) || (prevMoves == 0 && prevTime == 0); if (betterScore) { beterScoreText.Text = " Better score achieved!"; } else { beterScoreText.Text = " "; } res1.Text = " Time: " + time + "; Moves: " + moves; res2.Text = " Time: " + Utils.formatTime(prevTime) + "; Moves: " + prevMoves; scorePanel.Visibility = Visibility.Visible; if (nextPuzzleOpened) { buttonNextPuzzle.Visibility = Visibility.Visible; } buttonPause.Visibility = Visibility.Collapsed; } movesText.Text = moves; timeText.Text = time; } Uri bitmapUri = new Uri(puzzle.puzzleImage, UriKind.Relative); BitmapImage bitmap = new BitmapImage(bitmapUri); bitmap.ImageOpened += new EventHandler <RoutedEventArgs>(bitmap_Loaded); gameViewController.setBitmap(bitmap); }