private void RandomizeGrid(GridPane grid) { for (int x, y = 0, i = 0; y < grid.GridHeight; ++y) { for (x = 0; x < grid.GridWidth; ++x, ++i) { ((grid.Get(x, y) as LayoutPane).Children[0] as MenuItem) .ImageItem.Color = RandomColor(); } } }
private void CreateSession(Difficulty d, int t) { var gid = d == Difficulty.Easy ? "smallGrid": d == Difficulty.Medium ? "mediumGrid" : "largeGrid"; activeGrid = GetItem <GridPane>(gid); gridPane.Clear(); gridPane.Add(activeGrid); int w = activeGrid.GridWidth; int h = activeGrid.GridHeight; Session = new Session(w, h, t); for (int x, y = 0; y < h; ++y) { for (x = 0; x < w; ++x) { var fader = (activeGrid.Get(x, y) as LayoutPane).Children[1] as FadingPane; fader.FadeInTime = fader.FadeOutTime = ButtonFade; } } Session.NewIndex += (s, a) => { int y = a.Index / activeGrid.GridWidth; int x = a.Index % activeGrid.GridWidth; var fader = (activeGrid.Get(x, y) as StackPane).Children[1] as FadingPane; fader.FadeOut(); Console.WriteLine("Session says " + a.Index); }; Session.GameOver += (s, a) => { gameOverText.Text = string.Format("GameOver after {0} turn{1}", a.Turns, a.Turns == 1 ? "" : "s"); Console.WriteLine(string.Format("GameOver after {0} turn{1}", a.Turns, a.Turns == 1 ? "" : "s")); StopSession(true); }; }