Ejemplo n.º 1
0
        private void btnAccept_Click(object sender, System.EventArgs e)
        {
            Cell newCell = new Cell();
            newCell.Initialize();

            newCell.ID = Convert.ToInt32(this.tbxBlockId.Text);
            newCell.Location.X = Convert.ToInt32(this.tbxLocationX.Text);
            newCell.Location.Y = Convert.ToInt32(this.tbxLocationY.Text);
            newCell.Location.Z = Convert.ToInt32(this.tbxLocationZ.Text);
            newCell.Location.Level = Convert.ToInt32(this.tbxLocationLevel.Text);

            newCell.Type = 0;
            if (this.chkUp.Checked) newCell.Type += (uint)Directions.Up;
            if (this.chkLeft.Checked) newCell.Type += (uint)Directions.Left;
            if (this.chkDown.Checked) newCell.Type += (uint)Directions.Down;
            if (this.chkRight.Checked) newCell.Type += (uint)Directions.Right;

            newCell.Attribute = 0;
            if (this.chkStart.Checked) newCell.Attribute += (uint)CellAttributes.IsStart;
            if (this.chkFinish.Checked) newCell.Attribute += (uint)CellAttributes.IsFinish;
            if (this.chkDrop.Checked) newCell.Attribute += (uint)CellAttributes.HasDrop;

            newCell.Option = 0;
            if (this.chkPortal.Checked) newCell.Option += (uint)CellOptions.Portal;

            newCell.OptionValue = Convert.ToInt32(this.tbxOptionValue.Text);

            Program.EditorForm.AddCell(newCell);
            Program.EditorForm.Invalidate();
            this.Close();
        }
Ejemplo n.º 2
0
        public CellEdit(Cell cell)
        {
            this.cell = cell;
            this.isCheckAllClicked = true;

            InitializeComponent();
            CustomInitialize();
            FillComponents();
        }
Ejemplo n.º 3
0
        void pbMap_Paint(object sender, PaintEventArgs e)
        {
            Graphics gGraphic = e.Graphics;

            GridLocation cellLocation = new GridLocation();
            Cell cell = new Cell();
            // CellGraph
            int cellsCountWidth = (int)Math.Ceiling(this.pbMap.Size.Width / 2d / GlobalConstants.CELL_WIDTH) * 2 + 1;
            int cellsCountHeight = (int)Math.Ceiling(this.pbMap.Size.Height / 2d / GlobalConstants.CELL_HEIGHT) * 2 + 1;

            // HACK: Correction values because the width and height of drawing region are not a multiple of CELL_WIDTH and CELL_HEIGHT
            int xCorrection = ((int)Math.Ceiling(this.pbMap.Size.Height * 1d / GlobalConstants.CELL_HEIGHT) * GlobalConstants.CELL_HEIGHT - this.pbMap.Size.Height) / 2;
            int yCorrection = ((int)Math.Ceiling(this.pbMap.Size.Width * 1d / GlobalConstants.CELL_WIDTH) * GlobalConstants.CELL_WIDTH - this.pbMap.Size.Width) / 2;

            for (int i = 0; i < cellsCountWidth; ++i)
                for (int j = 0; j < cellsCountHeight; ++j)
                {
                    int x, y;
                    x = (i - 1) * GlobalConstants.CELL_WIDTH - this.centralGPS.X + xCorrection + 25;
                    y = (j - 1) * GlobalConstants.CELL_HEIGHT - this.centralGPS.Y + yCorrection + 25;
                    cellLocation.X = centralGPS.Location.X + i - cellsCountWidth / 2;
                    cellLocation.Y = centralGPS.Location.Y + j - cellsCountHeight / 2;
                    cellLocation.Z = centralGPS.Location.Z;
                    cellLocation.Level = centralGPS.Location.Level;
                    cell = GetCell(cellLocation);

                    gGraphic.DrawImage(PictureManager.GetPictureByType(cell.Type), x, y, GlobalConstants.CELL_WIDTH, GlobalConstants.CELL_HEIGHT);

                    // Draw Start Block
                    if (cell.HasAttribute(CellAttributes.IsStart))
                    {
                        gGraphic.DrawImage(PictureManager.StartImage, x + 5, y + 5, 40, 40);
                    }

                    // Draw Finish Block
                    if (cell.HasAttribute(CellAttributes.IsFinish))
                    {
                        gGraphic.DrawImage(PictureManager.FinishImage, x + 5, y + 5, PictureManager.FinishImage.Width, PictureManager.FinishImage.Height);
                    }

                    // Draw Ooze Drop
                    if (cell.HasAttribute(CellAttributes.HasDrop))
                    {
                        gGraphic.DrawImage(PictureManager.DropImage, x + 15, y + 10, 20, 30);
                    }

                    // Portal
                    if (cell.HasOption(CellOptions.Portal))
                    {
                        Image image = PictureManager.PortalImage;
                        gGraphic.DrawImage(image,
                            x + (GlobalConstants.CELL_WIDTH - image.Width) / 2,
                            y + (GlobalConstants.CELL_HEIGHT - image.Height) / 2,
                            PictureManager.PortalImage.Width, PictureManager.PortalImage.Height);
                    }
                }
        }
Ejemplo n.º 4
0
 public void ReplaceCell(Cell cell)
 {
     RemoveCell(cell);
     AddCell(cell);
 }
Ejemplo n.º 5
0
        public void RemoveCell(Cell cell)
        {
            this.mapCells.Remove(cell.Location);

            if (this.maxCellId == cell.ID)
                --this.maxCellId;

            if (cell.HasAttribute(CellAttributes.IsStart))
                this.startLocations.Remove(cell.Location.Level);
            if (cell.HasAttribute(CellAttributes.IsFinish))
                this.startLocations.Remove(cell.Location.Level);

            this.isMapSaved = false;
        }
Ejemplo n.º 6
0
        public void AddCell(Cell cell)
        {
            if (this.mapCells.ContainsKey(cell.Location))
            {
                ReplaceCell(cell);
                return;
            }

            this.mapCells.Add(cell.Location, cell);

            if (Convert.ToInt32(cell.Location.Level) >= this.levelsCount)
                ++this.levelsCount;

            if (cell.HasAttribute(CellAttributes.IsStart))
                this.startLocations[cell.Location.Level] = cell.Location;
            if (cell.HasAttribute(CellAttributes.IsFinish))
                this.finishLocations[cell.Location.Level] = cell.Location;

            if (cell.ID > this.maxCellId)
                this.maxCellId = cell.ID;

            this.isMapSaved = false;
        }
Ejemplo n.º 7
0
Archivo: Map.cs Proyecto: scerdam/Maze
        private bool AddCell(Cell newCell, bool isReplaceOnExist = false)
        {
            // A Cell with the same id or at the same location exists
            if (this.mapCellsIds.ContainsKey(newCell.ID) || this.mapCells.ContainsKey(newCell.Location))
            {
                if (!isReplaceOnExist)
                    return false;

                this.mapCells.Remove(newCell.Location);
                this.mapCellsIds.Remove(newCell.ID);
            }

            this.mapCells.Add(newCell.Location, newCell);
            this.mapCellsIds.Add(newCell.ID, newCell.Location);
            return true;
        }
Ejemplo n.º 8
0
Archivo: Map.cs Proyecto: scerdam/Maze
        /// <summary>
        /// Gets a Cell of the map with the specified Location.
        /// </summary>
        /// <param name="location">Location where the Cell is expected to be.</param>
        /// <returns>Found Cell or default Cell value when no cells were found.</returns>
        public Cell GetCell(GridLocation location)
        {
            if (this.mapCells.ContainsKey(location))
                return this.mapCells[location];

            // return default cell
            Cell cell = new Cell();
            cell.Initialize();
            return cell;
        }
Ejemplo n.º 9
0
        public void GeneratePath(Cell startPoint, Cell finalPoint)
        {
            CellParam currentCell = new CellParam();
            CellParam finalCell = new CellParam();
            List<CellParam> bannedList = new List<CellParam>();
            Path = new List<Cell>();
            openList = new List<CellParam>();
            closeList = new List<CellParam>();

            // return empty Way at points on different levels OR
            // start and final points were not defined
            if (startPoint.Location.Level != finalPoint.Location.Level ||
                startPoint.ID == 0 && finalPoint.ID == 0)
                return;

            currentCell.InitializeCell();
            finalCell.InitializeCell();

            currentCell.ID = startPoint.ID;
            openList.Add(currentCell);

            finalCell.ID = finalPoint.ID;
            openList.Add(finalCell);

            while (currentCell.ID != finalPoint.ID)
            {
                Cell block = FindCell(openList, currentCell);
                FindNeighbors(block, finalCell);

                CellParam CellWithMinF = currentCell;
                if (!SearchInList(closeList, finalCell))
                {
                    CellWithMinF = GetCellWithMinF(bannedList);

                    if (CellWithMinF.Equals(currentCell))
                        bannedList.Add(currentCell);

                    currentCell = CellWithMinF;
                }
                else
                    break;
            }

            // No path was found
            if (closeList.Count == 0)
                return;

            currentCell = closeList[closeList.Count - 1];
            Path.Add(FindCell(openList, currentCell));

            for (int i = closeList.Count - 1; i >= 0; --i)   // CloseList[0] == Start Cell
            {
                if (closeList[i].ID == FindCell(closeList, Path[Path.Count - 1]).MID)
                {
                    Cell tempCell = new Cell();
                    tempCell = FindCell(closeList, closeList[i]);
                    if (!SearchInList(Path, tempCell))
                    {
                        Path.Add(tempCell);
                        i = closeList.Count;
                    }
                }
            }
        }
Ejemplo n.º 10
0
 public PathFinder(Cell startPoint, Cell finishPoint)
     : this()
 {
     //GeneratePath(startPoint, finishPoint);
 }
Ejemplo n.º 11
0
 private bool SearchInList(List<Cell> List, Cell Element)
 {
     foreach (Cell el in List)
     {
         if (el.ID == Element.ID)
             return true;
     }
     return false;
 }
Ejemplo n.º 12
0
        // Find all passable neighbors
        private void FindNeighbors(Cell Block, CellParam FinalPoint)
        {
            CellParam currentCell = FindCell(openList, Block);

            for (int i = -1; i <= 1; ++i)
            {
                for (int j = -1; j <= 1; ++j)
                {
                    // Skip this cell
                    if (i == 0 && j == 0)
                        continue;

                    GridLocation location = new GridLocation();
                    location.X = Block.Location.X + i;
                    location.Y = Block.Location.Y + j;
                    location.Level = Block.Location.Level;

                    // Skip non-existed cell
                    if (Map.Instance.GetCell(location).Type == 16)
                        continue;

                    bool isNeighbourReachable = false;

                    switch (i * j)
                    {
                        case -1:
                            if (i == -1)    // diagonal moving - left and down
                            {
                                GridLocation locDown = Block.Location;
                                locDown.Y++;
                                GridLocation locLeft = Block.Location;
                                locLeft.X--;

                                // Check cell's passability
                                if ((Block.CanMoveTo(Directions.Down) &&
                                    Map.Instance.GetCell(locDown).CanMoveTo(Directions.Left)) &&
                                    (Block.CanMoveTo(Directions.Left) &&
                                    Map.Instance.GetCell(locLeft).CanMoveTo(Directions.Down)))
                                {
                                    isNeighbourReachable = true;
                                }
                            }
                            else    // diagonal moving - right and up
                            {
                                GridLocation locUp = Block.Location;
                                locUp.Y--;
                                GridLocation locRight = Block.Location;
                                locRight.X++;

                                if ((Block.CanMoveTo(Directions.Up) &&
                                    Map.Instance.GetCell(locUp).CanMoveTo(Directions.Right)) &&
                                    (Block.CanMoveTo(Directions.Right) &&
                                    Map.Instance.GetCell(locRight).CanMoveTo(Directions.Up)))
                                {
                                    isNeighbourReachable = true;
                                }
                            }
                            break;
                        case 1:
                            if (i == -1)    // diagonal moving - left and up
                            {
                                GridLocation locUp = Block.Location;
                                locUp.Y--;
                                GridLocation locLeft = Block.Location;
                                locLeft.X--;

                                if ((Block.CanMoveTo(Directions.Left) &&
                                    Map.Instance.GetCell(locLeft).CanMoveTo(Directions.Up)) &&
                                    (Block.CanMoveTo(Directions.Up) &&
                                    Map.Instance.GetCell(locUp).CanMoveTo(Directions.Left)))
                                {
                                    isNeighbourReachable = true;
                                }
                            }
                            else    // diagonal moving - right and down
                            {
                                GridLocation locDown = Block.Location;
                                locDown.Y++;
                                GridLocation locRight = Block.Location;
                                locRight.X++;

                                if ((Block.CanMoveTo(Directions.Down) &&
                                    Map.Instance.GetCell(locDown).CanMoveTo(Directions.Right)) &&
                                    (Block.CanMoveTo(Directions.Right) &&
                                    Map.Instance.GetCell(locRight).CanMoveTo(Directions.Down)))
                                {
                                    isNeighbourReachable = true;
                                }
                            }
                            break;
                        case 0:
                            if (i == 0)    // moving up or down
                            {
                                if ((j == -1 && Block.CanMoveTo(Directions.Up)) ||
                                    (j == 1 && Block.CanMoveTo(Directions.Down)))
                                {
                                    isNeighbourReachable = true;
                                }
                            }
                            else    // moving - right or left
                            {
                                if ((i == 1 && Block.CanMoveTo(Directions.Right)) ||
                                    (i == -1 && Block.CanMoveTo(Directions.Left)))
                                {
                                    isNeighbourReachable = true;
                                }
                            }
                            break;
                    }

                    if (!isNeighbourReachable)
                        continue;

                    CellParam Cell = new CellParam();
                    Cell.ID = Map.Instance.GetCell(location).ID;
                    Cell.MID = Block.ID;
                    if (i == 0 || j == 0)
                        Cell.G = currentCell.G + 10;    // Vertical or horizontal movement
                    else
                        Cell.G = currentCell.G + 14;    // Diagonal movement

                    Cell.H = (Math.Abs(location.X - FindCell(openList, FinalPoint).Location.X) + Math.Abs(location.Y - FindCell(openList, FinalPoint/*, CurrentMap*/).Location.Y)) * 10;
                    Cell.F = Cell.G + Cell.H;

                    if (!SearchInList(openList, Cell) && !SearchInList(closeList, Cell))
                    {
                        openList.Add(Cell);

                        if (!SearchInList(closeList, currentCell))
                            closeList.Add(currentCell);

                        if (SearchInList(openList, currentCell))
                            openList.Remove(currentCell);
                    }

                    if (Cell.ID == FinalPoint.ID)
                    {
                        if (!SearchInList(closeList, currentCell))
                            closeList.Add(currentCell);
                        closeList.Add(Cell);
                        return;
                    }
                }
            }
        }
Ejemplo n.º 13
0
        private Cell FindCell(List<CellParam> List, CellParam Cell)
        {
            Cell Block = new Cell();

            Block.Initialize();
            for (int i = 0; i < List.Count; ++i)
            {
                if (Cell.ID == List[i].ID)
                {
                    Block = Map.Instance.GetCell(List[i].ID);
                    break;
                }
            }
            return Block;
        }
Ejemplo n.º 14
0
 private CellParam FindCell(List<CellParam> List, Cell Block)
 {
     CellParam Cell = new CellParam();
     Cell.InitializeCell();
     for (int i = 0; i < List.Count; ++i)
     {
         if (Block.ID == List[i].ID)
             return List[i];
     }
     return Cell;
 }
Ejemplo n.º 15
0
 public void SetDestination(Cell destinationCell)
 {
     this.destinationCell = destinationCell;
 }
Ejemplo n.º 16
0
        /// <summary>
        /// RePaint PlayForm map pictures.
        /// Include images of the player, blocks and objects on a block
        /// </summary>
        private void RebuildGraphMap(Graphics gCellBP)
        {
            GridLocation PBLocation = new GridLocation();
            Cell Block = new Cell();

            List<Maze.Classes.Object> objectsOnMap = new List<Maze.Classes.Object>();

            // CellGraph
            for (int i = 0; i < GlobalConstants.GRIDMAP_WIDTH; ++i)
                for (int j = 0; j < GlobalConstants.GRIDMAP_HEIGHT; ++j)
                {
                    // Calculated location point for every block
                    int x, y;
                    x = /*CellPB.Location.X*/ +(i - 1) * GlobalConstants.CELL_WIDTH - (Player.Position.X - 25);
                    y = /*CellPB.Location.Y*/ +(j - 1) * GlobalConstants.CELL_HEIGHT - (Player.Position.Y - 25);
                    PBLocation.X = Player.Position.Location.X + i - GlobalConstants.GRIDMAP_WIDTH / 2;
                    PBLocation.Y = Player.Position.Location.Y + j - GlobalConstants.GRIDMAP_HEIGHT / 2;
                    PBLocation.Z = Player.Position.Location.Z;
                    PBLocation.Level = Player.Position.Location.Level;
                    Block = Map.Instance.GetCell(PBLocation);

                    // Draw Grid Cell image
                    gCellBP.DrawImage(PictureManager.GetPictureByType(Block.Type), x, y, GlobalConstants.CELL_WIDTH, GlobalConstants.CELL_HEIGHT);

                    // Draw Start Block
                    if (Block.HasAttribute(CellAttributes.IsStart))
                    {
                        gCellBP.DrawImage(PictureManager.StartImage, x + 5, y + 5, 40, 40);
                    }

                    // Draw Finish Block
                    if (Block.HasAttribute(CellAttributes.IsFinish))
                    {
                        gCellBP.DrawImage(PictureManager.FinishImage, x + 5, y + 5, 40, 40);
                    }

                    // Include all objects in this grid
                    objectsOnMap.AddRange(ObjectContainer.Instance.GetObjects(Block.Location));

                }

            /* Draw Visible Objects
             * Order:
             * 1. Slime
             * 2. GridObjects
             * 3. Units
             * 4. Slug
             */
            Image objectImage;

            for (int j = 0; j < 4; ++j)
                for (int i = 0; i < objectsOnMap.Count; ++i)
                {
                    // Default NULL
                    objectImage = null;
                    switch (j)
                    {
                        case 0:
                            // Slime
                            if (objectsOnMap[i].ObjectType == ObjectTypes.GridObject &&
                                ((GridObject)objectsOnMap[i]).GridObjectType == GridObjectTypes.Slime)
                            {
                                objectImage = PictureManager.SlimeImage;
                            }
                            else
                                continue;
                            break;
                        case 1:
                            // GridObjects
                            if (objectsOnMap[i].ObjectType == ObjectTypes.GridObject)
                            {
                                GridObject gridObject = (GridObject)objectsOnMap[i];
                                if (gridObject.GridObjectType == GridObjectTypes.Slime)
                                    continue;

                                objectImage = PictureManager.GetGridObjectImage(gridObject);
                            }
                            else
                                continue;
                            break;
                        case 2:
                            // Units
                            if (objectsOnMap[i].ObjectType == ObjectTypes.Unit)
                            {
                                Unit unit = (Unit)objectsOnMap[i];

                                // Check Smoke Cloud
                                // Draw objects with 'Smoke Cloud' effect if Slug also has it and vice versa
                                if (!(Player.HasEffectType(EffectTypes.SmokeCloud) ^ unit.HasEffectType(EffectTypes.SmokeCloud)))
                                    objectImage = PictureManager.GetUnitImage(unit);
                            }
                            else
                                continue;
                            break;
                        case 3:
                            // Slug
                            if (objectsOnMap[i].ObjectType == ObjectTypes.Slug)
                                objectImage = PictureManager.GetSlugImage((Slug)objectsOnMap[i]);
                            else
                                continue;
                            break;
                    }

                    if (objectImage == null)
                        continue;

                    // Determine object image coords
                    // relative to the object position on Cell and Player (as a center of the GridMap)
                    int xCoord = this.pbGridMap.Size.Width / 2 - ((Player.Position.Location.X - objectsOnMap[i].Position.Location.X) *
                            GlobalConstants.CELL_WIDTH + Player.Position.X - objectsOnMap[i].Position.X) - objectImage.Size.Width / 2;
                    int yCoord = this.pbGridMap.Size.Height / 2 - ((Player.Position.Location.Y - objectsOnMap[i].Position.Location.Y) *
                            GlobalConstants.CELL_HEIGHT + Player.Position.Y - objectsOnMap[i].Position.Y) - objectImage.Size.Height / 2;

                    gCellBP.DrawImage(objectImage, xCoord, yCoord,
                        objectImage.Size.Width, objectImage.Size.Height);
                }
        }
Ejemplo n.º 17
0
Archivo: Unit.cs Proyecto: scerdam/Maze
        /// <summary>
        /// Relocates the unit to the specifed destination <see cref="Cell"/>.
        /// </summary>
        /// <param name="destinationCell">A cell where the unit is relocating</param>
        public void TeleportTo(Cell destinationCell)
        {
            // save old position
            GPS prevPosition = Position;
            Position = new GPS(destinationCell.Location, 25, 25);

            if (Relocated != null)
                Relocated(this, new PositionEventArgs(prevPosition, Position));
        }
Ejemplo n.º 18
0
Archivo: Map.cs Proyecto: scerdam/Maze
        /// <summary>
        /// Gets a Cell of the map with the specified ID.
        /// </summary>
        /// <param name="cellId">ID of the Cell.</param>
        /// <returns>Found Cell or default Cell value when no cells were found.</returns>
        public Cell GetCell(int cellId)
        {
            if (this.mapCellsIds.ContainsKey(cellId) && this.mapCells.ContainsKey(this.mapCellsIds[cellId]))
                return this.mapCells[this.mapCellsIds[cellId]];

            // return default cell
            Cell defaultCell = new Cell();
            defaultCell.Initialize();
            return defaultCell;
        }