Пример #1
0
 public GameState()
 {
     bombs = new BombList();
     players = new PlayerList();
     map = new Map(0, 0);
     tickCount = 0;
 }
Пример #2
0
 internal void Map(int x, int y)
 {
     Map map = new Map(x, y);
     for (int rowCount = 0; rowCount < x; rowCount++)
     {
         string line = reader.ReadLine();
         Logger.WriteLineServer(line);
         string[] lineParts = line.Split(' ');
         for (int columnCount = 0; columnCount < y; columnCount++)
         {
             switch (lineParts[columnCount])
             {
                 case "0":
                     map.AddBlock(rowCount, columnCount, BlockType.Empty);
                     break;
                 case "1":
                     map.AddBlock(rowCount, columnCount, BlockType.Destructible);
                     break;
                 case "2":
                     map.AddBlock(rowCount, columnCount, BlockType.Indestructible);
                     break;
                 default:
                     throw new ProtocolError();
             }
         }
     }
     currentGameState.Map = map;
 }
Пример #3
0
        public void Tick(Map map, PlayerList players)
        {
            recentlyExplodedPoints = new List<Point2D>();
            // Make a list of all the bombs about to explode
            List<Bomb> bombsExploding = new List<Bomb>();
            foreach (Bomb bomb in bombs)
            {
                bomb.Tick();
                if (bomb.Timer == 0)
                {
                    bombsExploding.Add(bomb);
                }
            }
            // Detonate each bomb in the list.
            List<Bomb> bombsExploded = new List<Bomb>() ;
            List<Bomb> bombsExplodingNext = new List<Bomb>();
            do
            {
                foreach (Bomb bomb in bombsExploding)
                {
                    // if the bomb is on a player, kill the player
                    foreach (Player player in players.PlayersAt(bomb.X, bomb.Y))
                    {
                        if (player.X == bomb.X && player.Y == bomb.Y)
                        {
                            Logger.WriteLineInternal(player.X + ", " + player.Y + " and " + bomb.X + ", " + bomb.Y);
                            player.Alive = false;
                        }
                    }
                    // if the bomb is on a bomb, add that bomb to the list
                    foreach (Bomb stackedBomb in BombsAt(bomb.X, bomb.Y))
                    {
                        if (!(bombsExploding.Contains(stackedBomb) || bombsExplodingNext.Contains(stackedBomb) || bombsExploded.Contains(stackedBomb)))
                        {
                            bombsExplodingNext.Add(stackedBomb);
                        }
                    }
                    recentlyExplodedPoints.Add(new Point2D(bomb.X, bomb.Y));
                    // For each direction
                    for (int xDiff = -1; xDiff <= 1; xDiff++)
                    {
                        for (int yDiff = -1; yDiff <= 1; yDiff++)
                        {
                            if ((xDiff == 0 || yDiff == 0) && xDiff != yDiff)
                            {
                                // Cardinal direction. Maybe
                                // for 1 to 3
                                for (int i = 1; i <= 3; i++)
                                {
                                    int xPos = bomb.X + i * xDiff;
                                    int yPos = bomb.Y + i * yDiff;

                                    // if that position has a wall, destroy the wall then stop
                                    Block block = map.GetBlockAt(xPos, yPos);
                                    if (block == null || !block.Destroy())
                                    {
                                        break;
                                    }
                                    recentlyExplodedPoints.Add(new Point2D(xPos, yPos));
                                    // if that position is a player, kill the player
                                    foreach (Player player in players.PlayersAt(xPos, yPos))
                                    {
                                        Logger.WriteLineInternal(player.X + ", " + player.Y + " and " + xPos + ", " + yPos);
                                        player.Alive = false;
                                    }

                                    // if that position is a bomb, add it to the list
                                    foreach (Bomb stackedBomb in BombsAt(xPos, yPos))
                                    {
                                        if (!(bombsExploding.Contains(stackedBomb) || bombsExplodingNext.Contains(stackedBomb) || bombsExploded.Contains(stackedBomb)))
                                        {
                                            bombsExplodingNext.Add(stackedBomb);
                                        }
                                    }
                                }
                            }
                        }
                    }
                }
                bombsExploded.AddRange(bombsExploding);
                bombsExploding = bombsExplodingNext;
                bombsExplodingNext = new List<Bomb>();
            }
            while (bombsExploding.Count > 0);

            foreach (Bomb bomb in bombsExploded)
            {
                Console.WriteLine("Bomb REMOVED");
                bombs.Remove(bomb);
            }
        }