示例#1
0
        /// <summary>
        /// Gets the tile object at the given position
        /// </summary>
        /// <param name="position">Relative Position to check</param>
        /// <returns>Tile at position</returns>
        public Maybe <Tile> GetTileByRelativePosition(Vector2 position)
        {
            Vector2 relativePosition = position + Center;

            return(Tiles.Any(t => t.Bounds.Contains(position))
                ? Maybe <Tile> .Some(Tiles.First(t => t.Bounds.Contains(position)))
                : Maybe <Tile> .None);
        }
        private void CheckGameStatus()
        {
            if (!GameOver && !Tiles.Any(x => x.IsMine == false && x.Covered))
            {
                EndGame(true);
            }

            if (!GameOver && Tiles.All(x => x.IsMine && x.Covered))
            {
                EndGame(true);
            }
        }
示例#3
0
文件: Map.cs 项目: ZADragnon/Rover
        public override string ToString()
        {
            StringBuilder stringBuilder = new StringBuilder();

            int maxX = Tiles.Any() ? Tiles.Max(x => x.X) : 1;
            int maxY = Tiles.Any() ? Tiles.Max(x => x.Y) : 1;

            for (int i = 0; i < maxY; i++)
            {
                stringBuilder.AppendLine(new string('#', maxX));
            }

            return(stringBuilder.ToString());
        }
示例#4
0
 public int Simulate(int occupied)
 {
     while (Tiles.Any(seat => seat.Changed))
     {
         foreach (var seat in Tiles)
         {
             seat.Changed = false;
         }
         foreach (var seat in Tiles)
         {
             var next = seat.GetNext(occupied);
             seat.Changed = next != seat.Occupied;
             seat.Next    = next;
         }
         foreach (var seat in Tiles)
         {
             seat.Occupied = seat.Next;
         }
     }
     return(Tiles.Count(seat => seat.Occupied));
 }
示例#5
0
        public void TryPlace(TileType type, Vector2 position)
        {
            var snappedPosition = BluePrint.GetSnappedPosition(position, SnapValue.Value, type);

            if (!Tiles.Any())
            {
                addTile(type, snappedPosition);
                return;
            }

            if (type == TileType.PlayerStart || type == TileType.Warp)
            {
                addUniqueTile(snappedPosition, type);
                return;
            }

            if (HasTileAtPixel(snappedPosition, type))
            {
                return;
            }

            addTile(type, snappedPosition);
        }
示例#6
0
        public void Update()
        {
            // Update tiles
            if (Started && !Player.Dead)
            {
                // Hull flash possible match
                timeSinceLastMatch++;
                if (Player.ShipHull.FlashPossibleTiles && timeSinceLastMatch > 240)
                {
                    timeSinceLastMatch = 0;
                    List <Tile> possibleMatches = CheckPossibleMatches();
                    possibleMatches[Globals.Randomizer.Next(0, possibleMatches.Count())].Flash = 145;
                }

                bool canSelect = true;
                for (int i = 0; i < Tiles.Count; i++)
                {
                    for (int j = 0; j < Tiles[i].Count; j++)
                    {
                        Tiles[i][j].TilePosition = new Point(i, j);
                        Tiles[i][j].UpdateLevel(this);

                        if (!Tiles[i][j].Hidden)
                        {
                            // Above hidden
                            if (j < BoardSize.Y - 1 && Tiles[i][j + 1].Hidden && Tiles[i][j + 1].Size < 0.1)
                            {
                                if (Tiles[i][j].Mine)
                                {
                                    Tiles[i][j].Mine = false;
                                }

                                Tile temp = Tiles[i][j];
                                Tiles[i][j]     = Tiles[i][j + 1];
                                Tiles[i][j + 1] = temp;
                            }

                            // Select
                            if (canSelect && Globals.MState.LeftButton == ButtonState.Pressed && Globals.PrevMState.LeftButton == ButtonState.Released && Globals.MRectangle.Intersects(Tiles[i][j].Box) && !Tiles.Any(Column => Column.Any(item => item.Moving == true)))
                            {
                                canSelect = false;
                                if (Selected == null)
                                {
                                    Selected = Tiles[i][j];
                                }
                                else if (Selected == Tiles[i][j])
                                {
                                    Selected = null;
                                }
                                else
                                {
                                    // Check if pressed tile next to selected
                                    if (CheckAdjacent(i, j))
                                    {
                                        Tile temp = Tiles[i][j];
                                        Tiles[i][j]               = Selected;
                                        Tiles[i][j].Moving        = true;
                                        Tiles[i][j].ManuallyMoved = 180;
                                        Tiles[Selected.TilePosition.X][Selected.TilePosition.Y]               = temp;
                                        Tiles[Selected.TilePosition.X][Selected.TilePosition.Y].Moving        = true;
                                        Tiles[Selected.TilePosition.X][Selected.TilePosition.Y].ManuallyMoved = 180;

                                        // Check if swap is matching
                                        if (!CheckSingleMatch(i, j, Tiles) && !CheckSingleMatch(Selected.TilePosition.X, Selected.TilePosition.Y, Tiles))
                                        {
                                            Tiles[i][j]        = Tiles[Selected.TilePosition.X][Selected.TilePosition.Y];
                                            Tiles[i][j].Moving = false;
                                            Tiles[Selected.TilePosition.X][Selected.TilePosition.Y]        = Selected;
                                            Tiles[Selected.TilePosition.X][Selected.TilePosition.Y].Moving = false;
                                            GameObjects.Add(new Text(Tiles[i][j].Position - (Tiles[i][j].Position - Tiles[Selected.TilePosition.X][Selected.TilePosition.Y].Position), "Invalid Swap!", Color.Red, 60, 2, false, TextureManager.SpriteFont20));
                                        }
                                        Selected = null;
                                    }
                                    else
                                    {
                                        Selected = Tiles[i][j];
                                    }
                                }
                            }
                        }
                        else
                        {
                            if (Tiles[i][j].ManuallyMoved >= 0)
                            {
                                Tiles[i][j].ManuallyMoved = -1;
                            }

                            // "New" tile if hidden on top layer
                            if (j == 0)
                            {
                                Player player = (Player)GameObjects.First(item => item is Player);
                                Tiles[i][j].UnHide(player);
                            }
                        }
                    }
                }

                CheckMatch();

                // Modifiers

                if (HasModifier(Modifier.Asteroid))
                {
                    modifierTimer--;
                    // spawn rock if possible to move
                    if (modifierTimer < 0 && Globals.Randomizer.Next(0, 1001) < 3 && !(Player.ShipLocation == Location.left && !CheckPossibleMatches().Any(item => item.Type == TileType.right)) &&
                        !(Player.ShipLocation == Location.right && !CheckPossibleMatches().Any(item => item.Type == TileType.left)) &&
                        !(Player.ShipLocation == Location.middle && !CheckPossibleMatches().Any(item => item.Type == TileType.left) && !CheckPossibleMatches().Any(item => item.Type == TileType.right)))
                    {
                        modifierTimer = 120;
                        ToAdd.Add(new Rock(Player, this));
                    }
                }
                if (HasModifier(Modifier.Sun))
                {
                    modifierTimer--;
                    if (modifierTimer < 0 && Globals.Randomizer.Next(0, 1001) < 3)
                    {
                        modifierTimer = 120;
                        CombatText("The sun is heating up!");
                        Player.SetDamageOverTime(3, 6, 0);
                        if (GameObjects.Any(item => item is Enemy))
                        {
                            Enemy enemy = (Enemy)GameObjects.First(item => item is Enemy);
                            enemy.SetDamageOverTime(1, 6, 0);
                        }
                    }
                }
                if (HasModifier(Modifier.Satellite))
                {
                    Player.Energy.Change(0.04f);
                }
                if (HasModifier(Modifier.BlackHole))
                {
                    modifierTimer--;
                    if (modifierTimer < 0 && Globals.Randomizer.Next(0, 1001) < 4)
                    {
                        modifierTimer = 300;
                        CombatText("The tiles are heating up!");
                        for (int i = 0; i < Globals.Randomizer.Next(3, 7); i++)
                        {
                            while (true)
                            {
                                Point randomTile  = new Point(Globals.Randomizer.Next(0, BoardSize.X), Globals.Randomizer.Next(0, BoardSize.Y));
                                Point randomTile2 = new Point(Globals.Randomizer.Next(0, BoardSize.X), Globals.Randomizer.Next(0, BoardSize.Y));
                                while (randomTile.X == randomTile2.X && randomTile.Y == randomTile2.Y)
                                {
                                    randomTile2 = new Point(Globals.Randomizer.Next(0, BoardSize.X), Globals.Randomizer.Next(0, BoardSize.Y));
                                }
                                Tile temp = Tiles[randomTile.X][randomTile.Y];
                                Tiles[randomTile.X][randomTile.Y]   = Tiles[randomTile2.X][randomTile2.Y];
                                Tiles[randomTile2.X][randomTile2.Y] = temp;
                                if (!CheckSingleMatch(randomTile.X, randomTile.Y, Tiles) && !CheckSingleMatch(randomTile2.X, randomTile2.Y, Tiles))
                                {
                                    break;
                                }
                                else
                                {
                                    Tiles[randomTile2.X][randomTile2.Y] = Tiles[randomTile.X][randomTile.Y];
                                    Tiles[randomTile.X][randomTile.Y]   = temp;
                                }
                            }
                        }
                    }
                }
            }
            else if (Globals.KState.IsKeyDown(Keys.Enter))
            {
                Started = true;
            }

            // Game objects
            foreach (GameObject go in GameObjects)
            {
                go.UpdateLevel(this);
            }

            // Add
            foreach (GameObject toAdd in ToAdd)
            {
                GameObjects.Add(toAdd);
            }
            ToAdd.Clear();

            // Remove
            for (int i = GameObjects.Count - 1; i >= 0; i--)
            {
                if (GameObjects[i].Dead && !(GameObjects[i] is Player))
                {
                    if (GameObjects[i] is Enemy)
                    {
                        Player.GainExperience((int)EnemyDifficulty * 45 + 50 + Globals.Randomizer.Next(5, 10));
                        if (Rewards.Count() > 0)
                        {
                            foreach (Item reward in Rewards)
                            {
                                Player.AddItem(reward);
                            }
                            SceneManager.mapScene.NewItems.Flash = 10;
                        }
                        Player.Move = true;
                        Player.Health.Change(1);
                    }
                    GameObjects.RemoveAt(i);
                }
            }

            // Infobuttons
            ModuleInfo.Update();
            TileboardInfo.Update();
            EnergyInfo.Update();

            // Flee
            Flee.Update();
            if (Flee.Press() && EnemyDifficulty != Difficulty.Boss)
            {
                if (Player.ItemInInventory("Flee"))
                {
                    Player.GetItemInInventory("Flee").UseItem(Player, Player.GetItemInInventory("Flee"));
                }
            }
            if (Player.OutsideScreen())
            {
                Player.Move      = false;
                Player.Speed     = 0;
                Player.Position  = new Vector2(300, Globals.ScreenSize.Y - Player.Texture.Height);
                Player.Direction = Player.StandardDirection;
                LeaveLevel(GameObjects.Any(item => item is Enemy));
                Player.BonusDamageOneFight = 0;
            }
        }
示例#7
0
        public void CheckMatch()
        {
            for (int i = 0; i < BoardSize.X; i++)
            {
                for (int j = 0; j < BoardSize.Y; j++)
                {
                    // Check if down is same
                    if (j < BoardSize.Y - 1)
                    {
                        int number = 1;
                        while (Tiles[i][j].Type == Tiles[i][j + number].Type && !Tiles[i][j + number].Hidden && !Tiles[i][j].Hidden && !Tiles[i][j + number].Moving && !Tiles[i][j].Moving)
                        {
                            number++;
                            if (j + number >= BoardSize.Y)
                            {
                                break;
                            }
                        }

                        if (number >= 3) // Match
                        {
                            // Player action
                            Player.Action(number, Tiles[i][j].Type, this, Tiles.Any(item => item.Any(tile => tile.ManuallyMoved > 0 && tile.TilePosition.X == i && tile.TilePosition.Y >= j && tile.TilePosition.Y <= j + number)));
                            for (int k = 0; k < number; k++)
                            {
                                Tiles[i][j + k].Hide();
                                // Mine
                                if (Tiles[i][j + k].Mine && Tiles.Any(item => item.Any(tile => tile.ManuallyMoved > 0 && tile.TilePosition.X == i && tile.TilePosition.Y >= j && tile.TilePosition.Y <= j + number)))
                                {
                                    Player.TakeDamage(20, 0, DamageType.laser, false);
                                }

                                // Create pieces and text
                                if (k == 0)
                                {
                                    GameObjects.Add(new Text(new Vector2(Tiles[i][j].Position.X, Tiles[i][j].Position.Y + (number * 64) / 2 - 32), Tiles[i][j + k].Type.ToString(), Color.Red, 120, 2, false, TextureManager.SpriteFont20));
                                }
                                Explosion(i, j + k);
                            }
                        }
                    }

                    // Check if right is same
                    if (i < BoardSize.X - 1 && !Tiles[i][j].Hidden)
                    {
                        int number = 1;
                        while (Tiles[i][j].Type == Tiles[i + number][j].Type && !Tiles[i + number][j].Hidden && !Tiles[i][j].Hidden && !Tiles[i + number][j].Moving && !Tiles[i][j].Moving)
                        {
                            number++;
                            if (i + number >= BoardSize.X)
                            {
                                break;
                            }
                        }

                        if (number >= 3) // Match
                        {
                            timeSinceLastMatch = 0;
                            // Player action
                            Player.Action(number, Tiles[i][j].Type, this, Tiles.Any(item => item.Any(tile => tile.ManuallyMoved > 0 && tile.TilePosition.Y == j && tile.TilePosition.X >= i && tile.TilePosition.X <= i + number)));
                            for (int k = 0; k < number; k++)
                            {
                                Tiles[i + k][j].Hide();
                                // Mine
                                if (Tiles[i + k][j].Mine && Tiles.Any(item => item.Any(tile => tile.ManuallyMoved > 0 && tile.TilePosition.Y == j && tile.TilePosition.X >= i && tile.TilePosition.X <= i + number)))
                                {
                                    Player.TakeDamage(20, 0, DamageType.laser, false);
                                }

                                // Create pieces and text
                                if (k == 0)
                                {
                                    GameObjects.Add(new Text(new Vector2(Tiles[i][j].Position.X + (number * 64) / 2 - 32, Tiles[i][j].Position.Y), Tiles[i + k][j].Type.ToString(), Color.Red, 120, 2, false, TextureManager.SpriteFont20));
                                }
                                Explosion(i + k, j);
                            }
                        }
                    }
                }
            }
        }
示例#8
0
 public bool isExistRebellionTargetTile()
 {
     return(Tiles.Any((StrategyHexTile x) => x != null && x.isColorChanged));
 }
示例#9
0
 public Maybe <Tile> GetTileByPoint(Point location)
 {
     return(Tiles.Any(t => t.Location == location)
         ? Maybe <Tile> .Some(Tiles.First(t => t.Location == location))
         : Maybe <Tile> .None);
 }