Beispiel #1
0
 //Update field's and player's state
 public bool UpdateStatus(Player player, bool ok, Coord nextPos, System.Windows.Forms.Timer timer)
 {
     if (ok)
     {
         player.ChangePosition(nextPos);
         MapCell currentCell = Field[player.position.X, player.position.Y];
         if (player.position.CheckCoord(Exit.X, Exit.Y))
         {
             timer.Enabled = false;
             DialogResult result  = MessageBox.Show("You have won!");
             DialogResult result1 = MessageBox.Show(player.printScore(Doors));
             return(false);
         }
         else if (currentCell is Key)
         {
             player.Keys = new List <int>();
             Key key = currentCell as Key;
             player.Keys.Add(key.Tag);
             if (key.Picked == false)
             {
                 player.BackPack += 1;
             }
             key.Picked = true;
         }
         else if (currentCell is Coin)
         {
             Coin coin = currentCell as Coin;
             player.Coins++;
             coin.Picked = true;
         }
         return(true);
     }
     else
     {
         if (!In(nextPos.X, nextPos.Y) || Field[nextPos.X, nextPos.Y] is Wall)
         {
             Console.Beep();
         }
         else
         {
             Door door = Field[nextPos.X, nextPos.Y] as Door;
             if (player.Keys == null)
             {
                 Console.Beep();
             }
             else if (player.Keys.Contains(door.Tag))
             {
                 player.Doors = new List <int>();
                 door.Opened  = true;
                 player.Keys.Remove(door.Tag);
                 player.Doors.Add(door.Tag);
                 player.openedDoors += 1;
                 player.ChangePosition(nextPos);
             }
         }
         return(true);
     }
 }