Exemple #1
0
        public override void PickUp(Creature c)
        {
            c.gold += value;

            if (c as Player != null)
                GameLog.newMessage("You now have " + c.gold + " gold pieces (gained " + value + ").");

            map[x, y].RemoveItem(this);
            this.Destroy();
        }
        public static bool CalculatePath(TileMap map, Tile startTile, Tile endTile, out List<Tile> path)
        {
            me = map[startTile.x, startTile.y].creature;
            MapNode[,] nodeMap = new MapNode[map.mapX, map.mapY];
            path = new List<Tile>();
            if (startTile == null || startTile.walkable == false || endTile == null || endTile.walkable == false)
                return false;

            MapNode start = new MapNode(map, startTile);
            MapNode end = new MapNode(map, endTile);

            List<MapNode> openList = new List<MapNode>();
            List<MapNode> closedList = new List<MapNode>();

            start.score = new Score(0, 0 + hce(start, end));

            openList.Add(start); //add start node

            while (openList.Count > 0)
            {
                MapNode currentNode = Node_With_Min_f_Score(openList);

                if (currentNode.score.f_score == double.PositiveInfinity)
                {
                    return false;
                }

                if (currentNode == end)
                {
                    path = ConstructPath(currentNode, start);
                    return true;
                }

                closedList.Add(currentNode);
                currentNode.closed = true;

                if (currentNode.cost == double.PositiveInfinity)
                {
                    openList.Remove(currentNode);
                    currentNode.open = false;
                    continue;
                }

                foreach (MapNode neighbor in currentNode.getConnectedNodes(nodeMap)) //überprüfe jeden nachbar
                {

                    if (neighbor.closed)
                        continue;

                    double tentative_g_score = currentNode.score.g_score + currentNode.cost + neighbor.costModifier;
                    if (!neighbor.open) //wenn der nachbar noch nicht in der openlist ist oder der pfad kürzer...
                    {
                        neighbor.score = new Score(tentative_g_score, tentative_g_score + hce(neighbor, end));
                        openList.Add(neighbor);		//.....füge ihn hinzu bzw. aktualisiere ihn
                        neighbor.open = true;
                        //Debug.WriteLine(openList[neighbor].ToString());

                        neighbor.previousNode = currentNode;
                    }
                    else
                    {
                        if (tentative_g_score < openList.First(node => node == neighbor).score.g_score)
                        {
                            neighbor.score = new Score(tentative_g_score, tentative_g_score + hce(neighbor, end));
                            neighbor.previousNode = currentNode;
                        }
                    }
                }

                openList.Remove(currentNode);	// lösche die currentnode aus der openlist
                currentNode.open = false;
            }

            return false;
        }
Exemple #3
0
 protected virtual void attack(Creature creature)
 {
     xTo = creature.x;
     yTo = creature.y;
     attacking = true;
 }