Пример #1
0
        private void tryEat(GamePiece gamePiece, XYPointer nextCorindate, ObservableCollection<BasePresenterItem> items)
        {
            var goingToBeEatten = items.Where((m) =>
              {
                  //get the item that answers "next cordinate".
                  if (m.CurrentGamePiece.XPosition == nextCorindate.XProperty &&
                      m.CurrentGamePiece.YPosition == nextCorindate.YProperty)
                  {
                      return true;
                  }
                  return false;
              });

            var firstOrDeafult = goingToBeEatten.FirstOrDefault();
            if (firstOrDeafult != null)
            {
                if (firstOrDeafult is GrassPresenter)
                {
                    return;
                }
                if (firstOrDeafult is SnakePiecePresenter)
                {
                    //end game
                    DebugHelper.WriteLog("game eneded... bummer", "new snakes game manager");
                    return;
                }

                int index = items.IndexOf(firstOrDeafult);

                SnakePiecePresenter whoToFollow;
                if (snakeParts.Count > 0)
                {
                    whoToFollow = snakeParts.Last();
                }
                else
                {
                    whoToFollow = GetHeadItems(SnakePresenter.ArrayOfItems);
                }

                var snakePiece = new SnakePiece(nextCorindate.XProperty, nextCorindate.YProperty);
                SnakePiecePresenter newSnakepresetner = new SnakePiecePresenter(snakePiece,whoToFollow);
                snakeParts.Add(newSnakepresetner);
                items[index] = newSnakepresetner;

            }
            DebugHelper.WriteLog(string.Format("eatted {0},{1}", nextCorindate.XProperty, nextCorindate.YProperty), "new snakes game manager");
        }
Пример #2
0
 public SnakePiecePresenter(GamePiece g, SnakePiecePresenter WhoToFollow)
     : base(g)
 {
     WhoToFollowSnakePresenter = WhoToFollow;
 }
Пример #3
0
 public SnakePiecePresenter(GamePiece g, SnakePiecePresenter WhoToFollow)
     : base(g)
 {
     WhoToFollowSnakePresenter = WhoToFollow;
 }