public void Move(Direction direction) { switch (direction) { case Direction.Down: Snake.Move(Direction.Down); break; case Direction.Up: Snake.Move(Direction.Up); break; case Direction.Left: Snake.Move(Direction.Left); break; case Direction.Right: Snake.Move(Direction.Right); break; } _board.UpdateBoard(Snake); UpdateWindow(); if (_board.IsColision(Snake)) { Timer.Stop(); _timer.Dispose(); MessageBox.Show("You Lost!", "Message", MessageBoxButton.OK, MessageBoxImage.Exclamation); if (Points != 0) { GameRecord game = new GameRecord { Date = DateTime.Now, Game = "SnakeGame", Player = App.CurrentApp.MainViewModel.LoginViewModel.Player, Score = Points }; _gameRecordManager.Add(game); App.CurrentApp.MainViewModel.Refresh(); } } ; Run = false; }
public void IsXWinner() { if (Winner().Equals("../../Images/For TicTacToe/cat.jpg")) { GameRecord game = new GameRecord() { Date = DateTime.Now, Game = "TicTacToe", Score = 100, Player = App.CurrentApp.MainViewModel.LoginViewModel.Player }; _gameRecordManager.Add(game); App.CurrentApp.MainViewModel.Refresh(); } }
private async void DoorsCardFlipped(DoorsCardViewModel card) { if (flippegImage == false) { card.Visibility = true; int nrflipped = doorsCards.Count(c => c.Visibility && !c.Hidden); if (DoorsCards[DoorsCards.IndexOf(card)].FrontImage == $"../../Images/Doors/door4.jpg") { // MessageBox.Show("You win! Try next door!"); await Task.Delay(200); flippegImage = true; int oldScore = Score; StartGame(level); Score = oldScore + 10; } else if (DoorsCards[DoorsCards.IndexOf(card)].FrontImage == $"../../Images/Doors/blackcat.jpg") { MessageBox.Show("You Lost!", "Message", MessageBoxButton.OK, MessageBoxImage.Exclamation); flippegImage = true; IsEnabledSave = false; if (Score != 0) { GameRecord gameRecord = new GameRecord { Date = DateTime.Now, Game = "DoorsGame", Player = App.CurrentApp.MainViewModel.LoginViewModel.Player, Score = Score }; _gameRecordManager.Add(gameRecord); App.CurrentApp.MainViewModel.Refresh(); } ResetGame(); ResetScore(); } } }
private async void FlipCard(CardViewModel card) { card.Visibility = true; int nrflipped = Cards.Count(c => c.Visibility && !c.Hidden); if (nrflipped == 2) { var visibleCards = Cards.Where(c => c.Visibility && !c.Hidden).ToList(); int nrDistinctCards = visibleCards.Select(c => c.ImageUp).Distinct().Count(); await Task.Delay(200); if (nrDistinctCards == 1) { foreach (var c in visibleCards) { c.Hidden = true; } Score += 10; } else { foreach (var c in visibleCards) { c.Visibility = false; } } } int nrhidden = Cards.Count(c => c.Hidden); if (nrhidden == GridSize * GridSize && CurrentTime > 0) { DispatcherTimer.Stop(); MessageBox.Show("You Won!", "Message", MessageBoxButton.OK, MessageBoxImage.Exclamation); GameRecord gameRecord = new GameRecord { Date = DateTime.Now, Game = "PairGame", Player = App.CurrentApp.MainViewModel.LoginViewModel.Player, Score = Score }; _gameRecordManager.Add(gameRecord); App.CurrentApp.MainViewModel.Refresh(); CurrentTime = 0; Score = 0; IsEnabledSave = false; } //else //if (nrhidden != GridSize * GridSize && CurrentTime == 0) //{ // DispatcherTimer.Stop(); // MessageBox.Show("You Lost!", "Loser", MessageBoxButton.OK, // MessageBoxImage.Exclamation); // CurrentTime = 0; // Score = 0; // IsEnabledSave = false; //} }