예제 #1
0
파일: Zombie.cs 프로젝트: kjchiu/zomgame-2
 /// <summary>
 /// This state changing function is used for the SEARCH state. The location is where the zombie will be heading.
 /// </summary>
 /// <param name="state">This will be "Search", otherwise the destination is ignored.</param>
 /// <param name="destination">The destination for the search.</param>
 public void ChangeStateTo(string state, MapBlock destination)
 {
     currentState = stateList[state];
     if (state.Equals(ZombieStateNames.SEARCH_STATE))
     {
         ((SearchState)currentState).Destination = destination;
     }
 }
예제 #2
0
파일: Map.cs 프로젝트: kjchiu/zomgame-2
 public void SetBlockAt(MapBlock nBlock, int x, int y)
 {
     if (IsInMap(x, y))
     {
         nBlock.Coordinates = new Coord(x, y);
         mapBlocks[x, y]    = nBlock;
     }
 }
예제 #3
0
 public void SetBlockAt(MapBlock nBlock, int x, int y)
 {
     if (IsInMap(x, y))
     {
         nBlock.Coordinates = new Coord(x, y);
         mapBlocks[x, y]    = nBlock;
     }
     else
     {
         throw new BlockOutOfBoundsException(x, y);
     }
 }
예제 #4
0
 public override void Move(MapBlock aDestination)
 {
     // check for objects here, etc.
     //
     if (aDestination.Passable)
     {
         iMove(this, aDestination.Coordinates);
         return;
     }
     if (aDestination.CreatureInBlock is Zombie)
     {
         Attack(aDestination.CreatureInBlock);
     }
 }
예제 #5
0
 public Map(int _width, int _height)
 {
     width     = _width;
     height    = _height;
     lights    = new List <Light>();
     mapBlocks = new MapBlock[_width, _height];
     lightMap  = new Color[_width, _height];
     for (int i = 0; i < _width; i++)
     {
         for (int j = 0; j < _height; j++)
         {
             mapBlocks[i, j]             = new MapBlock(this);
             mapBlocks[i, j].Coordinates = new Coord(i, j);
             lightMap[i, j] = Color.Gray;
         }
     }
     mapZombies = new List <Creature>();
 }
예제 #6
0
        public void RemoveObject(GameObject aGameObject)
        {
            MapBlock lObjectBlock = aGameObject.Location;

            lObjectBlock.RemoveObject(aGameObject);
        }
예제 #7
0
 /// <summary>
 /// //H is calculated using the Manhattan method - just check the difference in X and Y, then add them together
 /// </summary>
 /// <param name="to">The block to check to.</param>
 public void CalculateH(MapBlock to)
 {
     H = Math.Abs(this.AttachedBlock.Coordinates.X - to.Coordinates.X) +
         Math.Abs(this.AttachedBlock.Coordinates.Y - to.Coordinates.Y);
 }
예제 #8
0
        MapBlock attachedBlock;         //the MapBlock that this PathBlock represents

        public PathBlock(MapBlock m, PathBlock p)
        {
            attachedBlock = m;
            parent        = p;
            G             = 0;
        }
예제 #9
0
        public List <PathBlock> AStarPath(MapBlock from, MapBlock to, bool willBreakThroughStuff)
        {
            if (!to.Passable)
            {
                //int closestH = 1000;
                foreach (MapBlock mb in to.SurroundingBlocks)
                {
                    PathBlock p = new PathBlock(mb, null);
                    p.CalculateH(from);
                }
            }
            List <PathBlock> pathToTake = new List <PathBlock>();         //final result
            List <PathBlock> openList   = new List <PathBlock>();         //possible paths to check
            List <PathBlock> closedList = new List <PathBlock>();         //all spaces that have been checked

            PathBlock first = new PathBlock(from, null);

            first.G = 0;
            first.CalculateH(to);

            openList.Add(new PathBlock(from, null));

            if (from.Equals(to))
            {
                return(pathToTake);
            }

            while (openList.Count > 0)
            {
                PathBlock blockToCheck = openList[0];

                if (blockToCheck.AttachedBlock.Equals(to))
                {
                    //path found, work backwards from blockToCheck's parent.
                    //
                    PathBlock backtracker = blockToCheck;
                    while (backtracker.Parent != null)
                    {
                        pathToTake.Insert(0, backtracker);
                        backtracker = backtracker.Parent;
                    }
                    return(pathToTake);
                }
                openList.Remove(blockToCheck);
                closedList.Add(blockToCheck);

                foreach (MapBlock mb in blockToCheck.AttachedBlock.SurroundingBlocks)
                {
                    PathBlock p = new PathBlock(mb, blockToCheck);
                    p.G = blockToCheck.G + 1;
                    p.CalculateH(to);

                    //ignore blocks in the closed list and those that aren't passable unless smashy smashy
                    //
                    if (!closedList.Contains(p))
                    {
                        int gScore = blockToCheck.G + 1;
                        if (!mb.Passable)                         //!passable means a prop is there. That means more time smashing.
                        {
                            gScore += 3;
                        }



                        if (!openList.Contains(p))
                        {
                            bool inserted = false;
                            for (int i = 0; i < openList.Count; i++)
                            {
                                if (openList[i].F > p.F)
                                {
                                    openList.Insert(i, p);
                                    inserted = true;
                                    break;
                                }
                            }
                            if (!inserted)
                            {
                                openList.Add(p);
                            }
                        }
                        else
                        {
                            //if the block is already in the openList, take the one with the lowest G value. If needed, switch the parent and recalculate G.
                            PathBlock blockInList = openList.Find((i) => i.Equals(p));
                            if (p.G < blockInList.G)
                            {
                                openList.Remove(blockInList);
                                bool inserted = false;
                                for (int i = 0; i < openList.Count; i++)
                                {
                                    if (openList[i].F > p.F)
                                    {
                                        openList.Insert(i, p);
                                        inserted = true;
                                        break;
                                    }
                                }
                                if (!inserted)
                                {
                                    openList.Add(p);
                                }
                                //blockInList.G = p.G;
                                //blockInList.Parent = blockToCheck;
                            }
                        }
                    }
                }
            }


            return(pathToTake);
        }
예제 #10
0
 public virtual void Move(MapBlock aDestination)
 {
 }