示例#1
0
        public Pathfinder(Map map)
        {
            width = map.Width;
            height = map.Height;

            InitializeSearchNodes(map);
        }
示例#2
0
        public Player(int lives, int gold, ref Map map, ref MessageHandler toast, ref WaveHandler waveHandler)
        {
            this.map = map;
            this.lives = lives;
            this.gold = gold;
            this.wave = 0;
            this.toast = toast;
            this.waveHandler = waveHandler;
            towers = new Tower[map.Width, map.Height];

            //XElement xml = new XElement("player");
            //xml.Save("test.xml");
        }
示例#3
0
 //Constructors
 /// <summary>
 /// Creates a new SearchNode.
 /// </summary>
 /// <param name="coords"></param>
 /// <param name="map"></param>
 public SearchNode(Point coords, Map map)
 {
     position = coords;
     if (map.GetIndex(position.X, position.Y) == 0)
     {
         walkable = true;
     }
     else if (map.GetIndex(position.X, position.Y) == -1)
     {
         walkable = true;
     }
     else if (map.GetIndex(position.X, position.Y) == -2)
     {
         walkable = true;
     }
     else
     {
         walkable = false;
     }
 }
示例#4
0
        /// <summary>
        /// Creates searchNodes for all the tiles and connect them to their neighbours
        /// </summary>
        private void InitializeSearchNodes(Map map)
        {
            searchNodes = new SearchNode[width, height];

            //Create nodes
            for (int x = 0; x < width; x++)
            {
                for (int y = 0; y < height; y++)
                {
                    SearchNode node = new SearchNode(new Point(x, y), map);

                    if (node.walkable == true)
                    {
                        node.neighbors = new SearchNode[4];
                        searchNodes[x, y] = node;
                    }
                }
            }

            //Connect nodes to neighbours
            for (int x = 0; x < width; x++)
            {
                for (int y = 0; y < height; y++)
                {
                    SearchNode node = searchNodes[x, y];

                    // If not relevant node, skip to next.
                    if (node == null || node.walkable == false)
                    {
                        continue;
                    }

                    Point[] neighbours = new Point[] {
                        new Point (x, y - 1), // The node above the current node.
                        new Point (x, y + 1), // The node below the current node.
                        new Point (x - 1, y), // The node left of the current node.
                        new Point (x + 1, y), // The node right of the current node.
                    };

                    for (int i = 0; i < neighbours.Length; i++)
                    {
                        Point position = neighbours[i];

                        // If position is not valid, skip to next.
                        if (position.X < 0 || position.X > width - 1 || position.Y < 0 || position.Y > height - 1)
                        {
                            continue;
                        }

                        SearchNode neighbour = searchNodes[position.X, position.Y];

                        // If unit can not walk on node, skip to next.
                        if (neighbour == null || neighbour.walkable == false)
                        {
                            continue;
                        }

                        node.neighbors[i] = neighbour;
                    }
                }
            }
        }
示例#5
0
 public static void SetPathfinder(Pathfinder pathfinder, Map map)
 {
     path.Start = map.Start;
     path.End = map.End;
     path.PFinder = pathfinder;
 }
示例#6
0
        /// <summary>
        /// Allows the game to perform any initialization it needs to before starting to run.
        /// This is where it can query for any required services and load any non-graphic
        /// related content.  Calling base.Initialize will enumerate through any components
        /// and initialize them as well.
        /// </summary>
        protected override void Initialize()
        {
            // TODO: Add your initialization logic here

            gameState = GameState.Menu;
            gameStateNumber = true;

            input = new Input();
            toast = new MessageHandler(width, height);
            networkMessages = new MessageHandler(width, height);
            userName = new TextInput(new Rectangle((width / 2) - 100, (height / 2) - 10, 200, 20));
            lobbyName = new TextInput(new Rectangle(100, 200, 200, 20));
            chatBox = new TextInput(new Rectangle(100, height - 40, 600, 20));
            network = new Network();
            chatlog = new List<string>();
            lobbyList = new List<Gui>();

            // Action bar objects
            actionButtons = new List<Button>();
            actionButtons.Add(new Button(new Rectangle(5, height - ACTIONBUTTONOFFSET_X, 60, 60), "10", "Basic ranged tower, medium damage, medium firing speed, medium ammunition speed, single target. 100 gold - 50% return", Keys.D1, 1));
            actionButtons.Add(new Button(new Rectangle(5 + ACTIONBUTTONOFFSET_X, height - ACTIONBUTTONOFFSET_X, 60, 60), "20", "Fast ranged tower, low damage, high firing speed, fast ammunition speed, single target. 200 gold - 50% return", Keys.D2, 3));
            actionButtons.Add(new Button(new Rectangle(width - (ACTIONBUTTONOFFSET_X * 2), height - ACTIONBUTTONOFFSET_X, 60, 60), "3", "Deletes a tower, 50% gold return for normal towers, 100% for walls.", Keys.D, 5));
            actionButtons.Add(new Button(new Rectangle(width - ACTIONBUTTONOFFSET_X, height - ACTIONBUTTONOFFSET_X, 60, 60), "0", "Starts a new wave.", Keys.N, 6));
            actionButtons.Add(new Button(new Rectangle(width - (ACTIONBUTTONOFFSET_X * 3), height - ACTIONBUTTONOFFSET_X, 60, 60), "1", "Place a blocking tower. 5 gold - 100% return.", Keys.D3, 15));

            // Upgrade tower button
            upgradeTowerButton = new Button(new Rectangle(0, 0, 60, 60), "upgradetower", "Upgrade the tower?", Keys.D9, 15);

            Gui.SetScreenSize(width, height);
            topbar = new Gui(new Rectangle(0, 0, width, 24));
            actionbar = new Gui(new Rectangle(0, (height - 70), width, 70));
            Button.GameHeight = height;
            Button.GameWidth = width;

            // Menu objects
            menuButtons = new List<Button>();
            menuButtons.Add(new Button(new Rectangle(width / 2 - MENUBUTTONOFFSET_X, MENUBUTTONOFFSET_X, 400, 70), "13", "Start a new game.", Keys.D1, 7));
            menuButtons.Add(new Button(new Rectangle(width / 2 - MENUBUTTONOFFSET_X, MENUBUTTONOFFSET_X + 75, 400, 70), "14", "Multiplayer.", Keys.D2, 8));
            menuButtons.Add(new Button(new Rectangle(width / 2 - MENUBUTTONOFFSET_X, MENUBUTTONOFFSET_X + (75 * 2), 400, 70), "15", "Check the game controls.", Keys.D3, 9));
            menuButtons.Add(new Button(new Rectangle(width / 2 - MENUBUTTONOFFSET_X, MENUBUTTONOFFSET_X + (75 * 3), 400, 70), "17", "Save the game.", Keys.D4, 13));
            menuButtons.Add(new Button(new Rectangle(width / 2 - MENUBUTTONOFFSET_X, MENUBUTTONOFFSET_X + (75 * 4), 400, 70), "16", "Exit the game.", Keys.D5, 10));

            // Multiplayer buttons
            multiplayerButtons = new List<Button>();
            multiplayerButtons.Add(new Button(new Rectangle(300, 200, 20, 20), "createlobby;", "Create lobby.", Keys.D1, 14));

            // join lobby buttons
            joinLobbyButtons = new List<Button>();

            // Map object
            map = new Map();
            pathfinder = new Pathfinder(map);
            pathview = new PathView();

            // Enemy objects
            Unit.SetPathfinder(pathfinder, map);
            Unit.LoadPath();
            waveHandler = new WaveHandler(enemies);
            pathview.Path = Unit.Path;

            ContentHolder.Initialize();

            // Player object
            player = new Player(5, 1000, ref map, ref toast, ref waveHandler);
            player.Wave = waveHandler.WaveNumber;

            storageHandler = new StorageHandler();

            base.Initialize();
        }