Пример #1
0
        private void SpawnFuel()
        {
            const int maxRandomTries = 5;

            fuelSlot = GetRandomEmptySlot(maxRandomTries);
            if (fuelSlot == null)
            {
                //game has no empty tiles - shorted tail by 1 to allow space then try again
                AdjustFireDurration(-1);
                fuelSlot = GetRandomEmptySlot();

                Debug.Assert(fuelSlot != null, "Failed to spawn another fuel");
                //Need to test this
            }

            GameObjectManager     manager = sSystemRegistry.GameObjectManager;
            PyroGameObjectFactory factory = (PyroGameObjectFactory)sSystemRegistry.GameObjectFactory;

            GameObject fuelGameObject = factory.SpawnFuel(0, 0);

            manager.Add(fuelGameObject);

            //playerSlot.Setup(GameSlotStatus.Player, fireGameObject);
            fuelSlot.Setup(GameSlotStatus.Fuel, fuelGameObject);

            fuelGameObject.SetPosition(GetSlotLocation(fuelSlot.Position));

            //fires.Add(fireSlot);
        }
Пример #2
0
        private void SpawnFire(GameSlot fireSlot)
        {
            if (fireDurration > 0)
            {
                if (fireSlot.Contents == GameSlotStatus.Fire)
                {
                    fireSlot.Child.facingDirection = playerSlot.Child.facingDirection;
                    fireSlot.Child.life            = fireDurration;
                }
                else
                {
                    GameObjectManager     manager = sSystemRegistry.GameObjectManager;
                    PyroGameObjectFactory factory = (PyroGameObjectFactory)sSystemRegistry.GameObjectFactory;

                    GameObject fireGameObject = factory.SpawnFire(0, 0, fireDurration);
                    manager.Add(fireGameObject);

                    fireSlot.Setup(GameSlotStatus.Fire, fireGameObject);

                    fireGameObject.SetPosition(GetSlotLocation(fireSlot.Position));
                    fireGameObject.facingDirection = playerSlot.Child.facingDirection;

                    fires.Add(fireSlot);
                }
            }
        }
Пример #3
0
 public void CloneFrom(GameSlot src)
 {
     position.X = src.position.X;
     position.Y = src.position.Y;
     Child      = src.Child;
     Contents   = src.Contents;
 }
Пример #4
0
        private void KillPlayer()
        {
            playerSlot.Child.life = 0;
            playerSlot.Child      = null;
            playerSlot            = null;//This is just a link to the tileSlots

            SpawnDeadPlayer(lastMoveDirection.X, lastMoveDirection.Y);
        }
Пример #5
0
        public void TransferSlotFrom(GameSlot src)
        {
            Child    = src.Child;
            Contents = src.Contents;
            src.EmptySlot();

            Child.SetPosition(PyroGameManager.GetSlotLocation(X, Y));
        }
Пример #6
0
        public GameSlot Clone()
        {
            GameSlot result = new GameSlot(position.X, position.Y);

            result.Child    = Child;
            result.Contents = Contents;
            return(result);
        }
Пример #7
0
        private void MovePlayer(int xDif, int yDif)
        {
            GameSlot oldSlot = GetGameSlot(playerSlot.Position);
            GameSlot newSlot = GetGameSlot(playerSlot.Position, xDif, yDif);

            bool spawnNewFuel = false;
            bool movePlayer   = false;

            playerSlot.Child.facingDirection.X = xDif;
            playerSlot.Child.facingDirection.Y = yDif;

            if (newSlot.Contents == GameSlotStatus.Fuel)
            {
                ConsumeFuel(newSlot);
                spawnNewFuel = true;
                movePlayer   = true;
            }
            KillFiresBy1();//has to be after consume fuel to make sure last peice of trail doesnt move when consuming
            if (newSlot.Contents == GameSlotStatus.Fire)
            {
                movePlayer = HitFire(newSlot);
            }
            else if (newSlot.Contents == GameSlotStatus.Empty)
            {
                movePlayer = true;
            }

            if (movePlayer)
            {
                if (trackMoveList)
                {
                    moveLog.Add("moved (" + oldSlot.X + "," + oldSlot.Y + ") to (" + newSlot.X + "," + newSlot.Y + ")");
                }

                UpdateScore(ScoredAction.Move);
                //create fire
                ClearSlot(oldSlot);
                SpawnFire(oldSlot);

                //actualy move player
                if (newSlot.Contents == GameSlotStatus.Fire)
                {
                    //kill fire it will be recreated
                    ClearSlot(newSlot);
                }
                newSlot.Contents = GameSlotStatus.Player;
                playerSlot.SetPosition(newSlot.Position);
                lastMoveDirection.X = xDif;
                lastMoveDirection.Y = yDif;
            }

            if (spawnNewFuel)
            {
                SpawnFuel();
            }

            GenFireReport();
        }
Пример #8
0
 private void ClearSlot(GameSlot slot)
 {
     if (slot.Contents == GameSlotStatus.Fire)
     {
         slot.Child.life = 0;
         ClearDeadFires();
     }
     slot.Contents = GameSlotStatus.Empty;//clears player from Slot
 }
Пример #9
0
        private bool HitFire(GameSlot slot)
        {
            bool continueMoving = true;

            if (!CanWalkOnFire)
            {
                continueMoving = false;
                KillPlayer();
                gameState = GameState.GameOver;
            }
            return(continueMoving);
        }
Пример #10
0
        private void ConsumeFuel(GameSlot slot)
        {
            FuelCollected++;
            AdjustFireDurration(1);
            UpdateScore(ScoredAction.CollectFuel);

            slot.Child.life--;
            if (slot.Child.life == 0)
            {
                slot.Child    = null;
                slot.Contents = GameSlotStatus.Empty;
            }
        }
Пример #11
0
        //basicly rewritten by AISmartScan(1) - kept for nostalsia sake
        private void AISimplePlanMove()
        {
            Point    newDir   = new Point(0, 0);
            GameSlot fuelSlot = GetFuelSlot();

            if (fuelSlot.X > playerSlot.X)
            {
                newDir.X = 1;
            }
            else if (fuelSlot.X < playerSlot.X)
            {
                newDir.X = -1;
            }
            else if (fuelSlot.Y > playerSlot.Y)
            {
                newDir.Y = 1;
            }
            else if (fuelSlot.Y < playerSlot.Y)
            {
                newDir.Y = -1;
            }

            playerSlot.Child.facingDirection.X = newDir.X;
            playerSlot.Child.facingDirection.Y = newDir.Y;

            GameSlot newSlot = GetNextGameSlot();

            if (!newSlot.IsSafeToWalkOn())//fire in front
            {
                playerSlot.Child.facingDirection = RotateSimpleVector(playerSlot.Child.facingDirection, 3);
                newSlot = GetNextGameSlot();
                if (!newSlot.IsSafeToWalkOn())// fire to left
                {
                    playerSlot.Child.facingDirection = RotateSimpleVector(playerSlot.Child.facingDirection, 2);
                    newSlot = GetNextGameSlot();
                    if (!newSlot.IsSafeToWalkOn())// fire to right - check backwards
                    {
                        //check  straight
                        playerSlot.Child.facingDirection = RotateSimpleVector(playerSlot.Child.facingDirection, 1);
                        newSlot = GetNextGameSlot();
                        if (!newSlot.IsSafeToWalkOn())// fire to right - check backwards
                        {
                            //crash straight
                            playerSlot.Child.facingDirection.X = lastMoveDirection.X;
                            playerSlot.Child.facingDirection.Y = lastMoveDirection.Y;
                        }
                    }
                }
            }
        }
Пример #12
0
        public PyroGameManager()
            : base()
        {
            random = new Random();
#if TestEnvironment
            random = new Random(2);
#endif
            Score      = 0;
            tileSlots  = GenerateSlots();
            playerSlot = new GameSlot(0, 0);

            //center tiles
            BoardXOffset = BoardXOffset + sSystemRegistry.ContextParameters.GameWidth / 2 - (GameWidthInSlots * SlotSize) / 2;
            BoardYOffset = BoardYOffset + sSystemRegistry.ContextParameters.GameHeight / 2 - (GameHeightInSlots * SlotSize) / 2;

            gameState = GameState.Loading;
        }
Пример #13
0
        public override void Reset()
        {
            sSystemRegistry.GameObjectManager.DestroyAll();
            ClearScoreIntoLastScore();
            FuelCollected      = 0;
            scoreSinceLastFuel = 0;

            ClearSlots(tileSlots);
            ClearSlots(fires);
            fires.Clear();
            ClearSlots(deadFires);
            deadFires.Clear();

            moveLog.Clear();

            lastMoveDirection = new Point(0, 0);

            lastInput           = new PlayerController();
            playerSlot          = new GameSlot(-1, -1);
            playerSlot.Contents = GameSlotStatus.Player;
        }
Пример #14
0
        public FixedSizeArray <GameSlot> GenerateSlots()
        {
            int slotCount = GameWidthInSlots * (GameHeightInSlots);
            FixedSizeArray <GameSlot> result = new FixedSizeArray <GameSlot>(slotCount);

            GameObjectManager     manager = sSystemRegistry.GameObjectManager;
            PyroGameObjectFactory factory = (PyroGameObjectFactory)sSystemRegistry.GameObjectFactory;

            for (int xx = 0; xx < slotCount; xx++)
            {
                int xPos = xx / GameWidthInSlots;
                int yPos = xx % GameWidthInSlots;

                GameObject emptyTile = factory.SpawnTileEmpty(xPos, yPos);
                manager.Add(emptyTile);

                GameSlot slot = new GameSlot(xPos, yPos);

                result.Add(slot);
            }

            return(result);
        }
Пример #15
0
        private int AIScoreMove(Point startPoint, Point dir, Point correctDirectionToGoal, int movesInFuture)
        {
            GameSlot option = GetGameSlot(startPoint, dir.X, dir.Y);

            int score = 0;

            if (!option.IsSafeToWalkOn(movesInFuture))
            {
                score = Int32.MinValue;//death here
            }
            else
            {
                int scoreFactorX = 1;
                int scoreFactorY = 1;
                if (aiZigZag)
                {
                    scoreFactorX = Math.Abs(correctDirectionToGoal.X) + dir.X;
                    scoreFactorY = Math.Abs(correctDirectionToGoal.Y) + dir.Y;
                }
                //calc score X score + Y score
                score = 0;
                if (dir.X == correctDirectionToGoal.X && dir.X == 0)//stright line
                {
                    if (option.Contents == GameSlotStatus.Fuel)
                    {
                        score += 3;
                    }
                    else
                    {
                        score += 2 * scoreFactorX;
                    }
                }
                else if ((dir.X < 0 && correctDirectionToGoal.X < 0) || (dir.X > 0 && correctDirectionToGoal.X > 0))//correct direction
                {
                    score += 1 * scoreFactorX;
                }
                else if ((dir.X < 0 && correctDirectionToGoal.X > 0) || (dir.X > 0 && correctDirectionToGoal.X < 0))//oposite dir
                {
                    score += -1 * scoreFactorX;
                }

                if (dir.Y == correctDirectionToGoal.Y && dir.Y == 0)//stright line
                {
                    if (option.Contents == GameSlotStatus.Fuel)
                    {
                        score += 3;
                    }
                    else
                    {
                        score += 2 * scoreFactorY;
                    }
                }
                else if ((dir.Y < 0 && correctDirectionToGoal.Y < 0) || (dir.Y > 0 && correctDirectionToGoal.Y > 0))//correct direction
                {
                    score += 1 * scoreFactorY;
                }
                else if ((dir.Y < 0 && correctDirectionToGoal.Y > 0) || (dir.Y > 0 && correctDirectionToGoal.Y < 0))//oposite dir
                {
                    score += -1 * scoreFactorY;
                }
            }
            return(score);
        }