예제 #1
0
        public IGameElement Create(LevelContext context, IList<IGameElement> elements, double timeDelta)
        {
            passedTime += timeDelta;
            Food food = null;
            if (passedTime >= foodCreationTimeInterval)
            {
                passedTime = 0.0d;
                ResetTimer();
                Vector2 newLocation;
                do
                {
                    newLocation = new Vector2(rand.Next(0, context.Settings.HorizontalTileCount - 1),
                                              rand.Next(0, context.Settings.VerticalTileCount - 1));
                }
                while (context.IsCellEmpty(newLocation));

                food = new Food(
                    aliveTime,
                    new Transform(
                            () => new Color(230, 126, 34),
                            () => AssetReference.WhitePixel,
                            () => Vector2.One,
                            () => newLocation,
                            () => 0.0f,
                            () => 0.0f));
                food.SetDisposable(Disposable.Create(elements, food));
            }
            return food;
        }
예제 #2
0
파일: AddTailState.cs 프로젝트: gmich/Snake
 public void Handle(LevelContext context)
 {
     context.SnakeHead.Bind(context.TailSpawner.Spawn(context.
         SnakeHead.
         TailLocation
         .AsVector2()));
     context.Score++;
 }
예제 #3
0
파일: Food.cs 프로젝트: gmich/Snake
 public void Update(LevelContext context, double deltaTime)
 {
     passedTime += deltaTime;
     if (passedTime >= aliveTime)
     {
         disposable.Dispose();
     }
     if (transform.Location == context.SnakeHead.HeadGridLocation)
     {
         context.AddState(new AddTailState());
         disposable.Dispose();
     }
 }
예제 #4
0
파일: Level.cs 프로젝트: gmich/Snake
        public Level(ILevelProvider levelProvider, Action next, Action restart)
        {
            this.levelProvider = levelProvider;
            grid = levelProvider.Grid;
            levelSettings = levelProvider.LevelSettings;
            adjustmentRules = AdjustmentRules.Default(levelProvider.LevelSettings.HorizontalTileCount - 1,
                                                           levelProvider.LevelSettings.VerticalTileCount - 1);

            context = new LevelContext(levelProvider.Head,
                                       levelProvider.LevelSettings,
                                       levelProvider.TailSpawner,
                                       Direction.Left,
                                       restart,
                                       next,
                                       location =>
                                       {
                                           bool intersects = grid[(int)location.X, (int)location.Y].Collide();
                                           elements.ForEach(element => intersects|= element.Intersects(location));
                                           return intersects;
                                       },
                                       levelProvider.LevelSettings.MaxLives);
            elements.Add(levelProvider.Head);
        }
예제 #5
0
 public void Handle(LevelContext context)
 {
     context.Direction = direction;
 }
예제 #6
0
파일: SnakePiece.cs 프로젝트: gmich/Snake
 private void CheckBodyCollision(SnakePiece piece, LevelContext context, Point locationToTest)
 {
     if (piece != null)
     {
         if (locationToTest == piece.location)
         {
             if (piece.hasMoved)
             {
                 context.AddState(new DeathState());
             }
         }
         CheckBodyCollision(piece.Tail,context, locationToTest);
     }
 }
예제 #7
0
파일: SnakePiece.cs 프로젝트: gmich/Snake
 public void Update(LevelContext context, double deltaTime)
 {
     CheckBodyCollision(Tail, context, location);
 }