Exemple #1
0
        //get the coin pile with the least cost path
        public void GetBestCoin(Square[] sqrs, Coin[] coins, Square current, int direction, out List<StarNode> bestP, out Coin targetCoin)
        {
            AStar ast = new AStar(sqrs, mapSize);
            List<StarNode> bestPath = null;
            Coin target = null;
            int minCost = int.MaxValue;

            foreach(Coin coin in coins)
            {
                int index = (int)(coin.position.X+(coin.position.Y*mapSize));
                if (sqrs[index].getSType() == 3)
                {
                    continue;
                }
                List<StarNode> path = ast.calculatePath(current, sqrs[index], direction);
                int cost = path[path.Count - 1].cost;

                if ((cost < minCost) && ((cost * Util.Constants.Timeout) < coin.remainTime))
                {
                    bestPath = path;
                    minCost = cost;
                    target = coin;
                }
            }

            bestP = bestPath;
            targetCoin = target;
            //return this.generateCommandList(bestPath, direction);
        }
Exemple #2
0
 //clears the commands list
 private void ClearPath()
 {
     commands.Clear();
     sqrPath.Clear();
     targetPack = null;
     targetCoin = null;
 }
Exemple #3
0
        protected override void Initialize()
        {
            graphics.PreferredBackBufferWidth = Util.Constants.ScreenWidth;
            graphics.PreferredBackBufferHeight = Util.Constants.ScreenHeight;
            graphics.IsFullScreen = false;
            graphics.ApplyChanges();
            Window.Title = "Battle Tanks";
            //mapSize = Util.Constants.MapSize;
            scale = Util.Constants.Scale;
            offset = Util.Constants.Offset;
            imageSize = Util.Constants.ImageSize;
            //Console.WriteLine(imageSize);
            cmn = new Communicator(serverIP,clientIP, serverPortNumber, clientPortNumber);
            playersSet = false;
            commands = new List<int>();
            sqrPath = new List<Square>();

            targetCoin = new Data_Items.Coin(0,0,0,0,0);
            targetPack = new Data_Items.LifePack(0, 0, 0, 0);
            lastTime = 0;
            shootcount = (float)0.1;
            sendOK = false;
            opMode = "";
            lastCommand = -1;
            lastSquare = null;

            isInRange = false;
            rangeDir = 0;
            skip = false;

            playerDead = false;
            gameInitializing = false;
            gameFinished = false;

            rect = new Texture2D(graphics.GraphicsDevice, 90, 30);
            Color[] data = new Color[90 * 30];
            for (int i = 0; i < data.Length; ++i)
                data[i] = Color.White;
            rect.SetData(data);

            tableBack = new Texture2D(graphics.GraphicsDevice, 385, 215);
            data = new Color[385 * 215];
            for (int i = 0; i < data.Length; ++i)
                data[i] = Color.White;
            tableBack.SetData(data);

            base.Initialize();
        }