private void CheckEnterField(UserControl control, double afterY, double afterX, double beforeY, double beforeX) { if (control is CoinControl coin) { Coins++; this.coinCount.Content = Coins.ToString(); canvas.Children.Remove(coin); } else if (control is KeyControl key) { int keyy = (int)(afterY - 1.0) / 20; int keyx = (int)(afterX - 1.0) / 10; Key collectkey = PickUps.PickupKey(keyx, keyy, keys) as Key; ownedKeys.Add(collectkey); Keys++; this.keyCount.Content = Keys.ToString(); canvas.Children.Remove(key); } else if (control is DoorControl door) { int doory = (int)(afterY - 1.0) / 20; int doorx = (int)(afterX - 1.0) / 10; if (!PickUps.unlockTheDoor(doorx, doory, doors, ownedKeys)) { Keys--; keyCount.Content = Keys.ToString(); canvas.Children.Remove(door); } else { player.SetValue(Canvas.TopProperty, beforeY); player.SetValue(Canvas.LeftProperty, beforeX); } } else if (control is EscapeDoor escape) { if (Coins == coins.Count) { MainWindow window = (MainWindow)Application.Current.Windows.OfType <Window>().SingleOrDefault(w => w.IsActive); window.KeyDown -= CanvasKeyPreview; window.Content = new EscapePg(); } else { player.SetValue(Canvas.TopProperty, beforeY); player.SetValue(Canvas.LeftProperty, beforeX); } } }
private static bool CheckValidMove(int X, int Y, List <Key> ownedKeys, List <Key> keys, List <Door> doors, List <Coin> coins, ref object CoinLock, ref int points, List <LinkedList <IField> > readmap) { if (PickUps.PickUpCoin(X, Y, coins, ref CoinLock) == 1) { ++points; lock (CoinLock) { Console.ForegroundColor = ConsoleColor.White; Cursor.WriteString(readmap[0].Count + 11, 1, points.ToString()); } } else { IPickup mapKey = PickUps.PickupKey(X, Y, keys); if (mapKey != null) { ownedKeys.Add(mapKey as Key); lock (CoinLock) { Console.ForegroundColor = ConsoleColor.White; Cursor.WriteString(readmap[0].Count + 11, 2, ownedKeys.Count.ToString()); } } else { bool status = PickUps.unlockTheDoor(X, Y, doors, ownedKeys); if (status == true) { return(false); } else { lock (CoinLock) { Console.ForegroundColor = ConsoleColor.White; Cursor.WriteString(readmap[0].Count + 11, 2, ownedKeys.Count.ToString() + " "); } } } } return(true); }