public Form1() { InitializeComponent(); menuStrip1.Visible = false; using (var data = new SaveGameContext()) { var query = (from b in data.Levels select b); foreach (var item in query) { levels = item; data.Levels.Remove(item); } data.SaveChanges(); if (levels == null) { levels = new Levels(true); } } this.BackgroundImage = Resources.finkiman; levels = new Levels(true); windowType = WindowTypeSize.big; DoubleBuffered = true; animationFinish = new Timer(); animationFinish.Interval = 5; animationFinish.Tick += new EventHandler(animationFinish_Tick); levelTimer = new Timer(); levelTimer.Interval = 1000; levelTimer.Tick += new EventHandler(levelTimer_Tick); timeRect = new Rectangle(6 * Game.squareDimension + 2 * Figura.paddingX, menuStrip1.Height, 2 * Game.squareDimension, Game.squareDimension); FontSize = 14; this.FormBorderStyle = FormBorderStyle.FixedSingle; initializePoints(); paused = false; pauseMoves = pauseTime = 0; mainWindow = true; }
private void Form1_MouseUp(object sender, MouseEventArgs e) { if (moving) { while (game.adjust()) { Invalidate(); } if (game.endGame()) { animationFinish.Start(); levelTimer.Stop(); levels.getCurrentLevel().Finished = true; levels.getCurrentLevel().Time = timePerLevel; levels.getCurrentLevel().Moves = movesPerLevel; using (var soundPlayer = new SoundPlayer(Resources.applause)) { soundPlayer.Play(); } DialogResult d = MessageBox.Show("Continue to next level?", "Level finished", MessageBoxButtons.YesNo); if (d == DialogResult.Yes) { if (levels.CurrentLevel == levels.Count - 1) { int[] bt = new int[levels.Count]; int[] bm = new int[levels.Count]; for (int i = 0; i < levels.Count; i++) { bt[i] = levels[i].Time; bm[i] = levels[i].Moves; } levels = new Levels(levels.Male); for (int i = 0; i < levels.Count; i++) { levels[i].Time = bt[i]; levels[i].Moves = bm[i]; } } levels.nextLevel(); newGame(); animationFinish.Stop(); } else { if (levels.CurrentLevel == levels.Count - 1) { int[] bt = new int[levels.Count]; int[] bm = new int[levels.Count]; for (int i = 0; i < levels.Count; i++) { bt[i] = levels[i].Time; bm[i] = levels[i].Moves; } levels = new Levels(levels.Male); for (int i = 0; i < levels.Count; i++) { levels[i].Time = bt[i]; levels[i].Moves = bm[i]; } } animationFinish.Stop(); levels.nextLevel(); main_menu(); } } else { game.finishMove(); movesPerLevel++; } moving = false; } dX = dY = 0; }