Beispiel #1
0
        public void pathfinder(MapCell start, MapCell end)
        {
            //set myPlayer
            foreach (Player p in players)
            {
                if (yourId == p.getId())
                {
                    myPlayer = p;
                }
            }
            m.setLock(true);

            try
            {
                int from = coordinateToPoint(start.getYPosition(), start.getXPosition());
                int to   = coordinateToPoint(end.getYPosition(), end.getXPosition());

                Console.WriteLine("START-COO (" + start.getXPosition() + " / " + start.getYPosition() + ")");
                Console.WriteLine("END-COO (" + end.getXPosition() + " / " + end.getYPosition() + ")");
                Console.WriteLine("START-NR X=" + from + "  END-NR Y=" + to);

                int   pathLength = map.width * map.height / 4;
                int[] path       = new int[pathLength];

                IntPtr pointer = findPath(from, to, getWalkable1dMap(), map.width, map.height, path.Length);
                Marshal.Copy(pointer, path, 0, path.Length);


                List <MapCell> cellList = new List <MapCell>();
                foreach (int item in path)
                {
                    cellList.Add(this.map.getCell(item % map.width, item / map.width));
                }


                m.setLock(false);
                pathwalker.setCoordinates(cellList);
            }
            catch (Exception e)
            {
                Console.WriteLine(e.Message);
            }
        }
Beispiel #2
0
 public void addCell(MapCell cell)
 {
     cells[cell.getXPosition()][cell.getYPosition()] = cell;
 }