示例#1
0
 public Bullet(Player con, Point origin, int dir)
 {
     shooter = con;
     pos = origin;
     Direction = dir;
     Console.WriteLine("Bullet shot at " + pos.X + "," + pos.Y + "," + direction);
      RandomGen r = new RandomGen();
      id = r.randomD(1000);
 }
示例#2
0
文件: AIMain.cs 项目: Vini2/TankGame
 private AIMain()
 {
     this.d = new List<DummyAI>();
     this.e = new RandomGen();
     this.f = new List<AIMessage>();
     this.g = new List<CoinPile>();
     base..ctor();
     return;
 }
示例#3
0
        private void createMap()
        {
            try
            {
                StreamReader sr = new StreamReader(ConfigurationManager.AppSettings.Get("MapPath"));
                String line;
                List<String> readInputs = new List<String>();
                while ((line = sr.ReadLine()) != null)
                {
                    readInputs.Add(line);
                }
                GameEngine.mapDetails = "";
                if (readInputs.Count != 0)
                {
                    GameEngine.mapSize = int.Parse(readInputs[0]);
                    GameEngine.mapDetails += readInputs[0] + ":" + readInputs[1] + ":" + readInputs[2];
                    Point tempPoint;
                    string[] tokens = readInputs[1].Split(new char[] { ';' });
                    for (int i = 0; i < tokens.Length; i++)
                    {
                        tempPoint = new Point(int.Parse(tokens[i].Substring(0, tokens[i].IndexOf(","))),
                            int.Parse(tokens[i].Substring(tokens[i].IndexOf(",") + 1, tokens[i].Length - tokens[i].IndexOf(",") - 1)));
                        GameEngine.brickLocations.Add(tempPoint);
                    }

                    tokens = readInputs[2].Split(new char[] { ';' });
                    for (int i = 0; i < tokens.Length; i++)
                    {
                        tempPoint = new Point(int.Parse(tokens[i].Substring(0, tokens[i].IndexOf(","))),
                            int.Parse(tokens[i].Substring(tokens[i].IndexOf(",") + 1, tokens[i].Length - tokens[i].IndexOf(",") - 1)));
                        GameEngine.obstacles.Add(tempPoint);
                    }
                    CoinPile tempCoinPile;
                    for (int i = 3; i < readInputs.Count; i++)
                    {
                        tokens = readInputs[i].Split(new char[] { ',', ';' });
                        tempCoinPile = new CoinPile(int.Parse(tokens[0]), int.Parse(tokens[1]));
                        tempCoinPile.AppearTime = int.Parse(tokens[2]);
                        tempCoinPile.LifeTime = int.Parse(tokens[3]);
                        tempCoinPile.Price = int.Parse(tokens[4]);
                        tempCoinPile.DisappearTime = tempCoinPile.AppearTime + tempCoinPile.LifeTime;
                        GameEngine.coinPileList.Add(tempCoinPile);
                    }
                }
                sortCoinPileLists();
            }
            catch (Exception ex1)
            {
                try
                {
                    writeConsoleLines("Generating the map");
                    GameEngine.mapSize = Constant.MAP_SIZE;
                    consoleLinesDoProgress();
                    RandomGen r = new RandomGen();
                    consoleLinesDoProgress();
                    // GameEngine.mapDetails = mapSize + ":";
                    consoleLinesDoProgress();
                    int maxBrick = Constant.MAX_BRICKS;
                    if (maxBrick < 5)
                    {
                        maxBrick = 5;
                        writeConsoleLines("Didn't I tell you to put at least 5? I am taking it as 5");

                    }
                    consoleLinesDoProgress();
                    int brickCount = r.randomD(maxBrick / 2, maxBrick);
                    consoleLinesDoProgress();
                    int lineCount = consoleLines.Count;
                    for (int i = 0; i < brickCount; i++)
                    {

                        int x = r.randomD(mapSize - 1);
                        int y = r.randomDP(mapSize - 1, mapSize, x);
                        Point p = new Point(x, y);
                        if (!brickLocations.Contains(p))
                        {
                            GameEngine.brickLocations.Add(p);
                            if (i != 0)
                            {
                                GameEngine.mapDetails = GameEngine.mapDetails + ";";
                            }
                            GameEngine.mapDetails = GameEngine.mapDetails + x + "," + y;
                            writeConsoleLines("Bricks:- " + (i + 1) + "/" + brickCount + " created", lineCount);
                        }
                        else
                        {
                            i--;
                        }

                    }
                    GameEngine.mapDetails = GameEngine.mapDetails + ":";

                    int maxObs = Constant.MAX_OBSTACLES;
                    int minObs = 8;
                    consoleLinesDoProgress();
                    if (maxObs < 8)
                    {
                        maxObs = 8;
                        writeConsoleLines("Didn't I tell you to put at least 8? I am taking it as 8");
                    }
                    if (minObs < brickCount)//More obstacals than bricks needed
                    {
                        minObs = brickCount;
                    }
                    if (minObs > maxObs)//But keep in the possible region
                    {
                        minObs = maxObs;
                    }
                    consoleLinesDoProgress();
                    int obsCount = r.randomD(minObs, maxObs);
                    lineCount = consoleLines.Count;

                    for (int i = 0; i < obsCount; i++)
                    {
                        int x = r.randomD(mapSize - 1);
                        int y = r.randomDP(mapSize - 1, mapSize, x);
                        Point p = new Point(x, y);
                        if ((!brickLocations.Contains(p)) & (!obstacles.Contains(p)))
                        {
                            GameEngine.obstacles.Add(p);
                            if (i != 0)
                            {
                                GameEngine.mapDetails = GameEngine.mapDetails + ";";
                            }
                            GameEngine.mapDetails = GameEngine.mapDetails + x + "," + y;
                            writeConsoleLines("Stone :- " + (i + 1) + "/" + obsCount + " created", lineCount);
                        }
                        else
                        {
                            i--;
                        }
                    }
                    GameEngine.mapDetails = GameEngine.mapDetails + ":";

                    consoleLinesDoProgress();
                    int waterCount = 10;
                    lineCount = consoleLines.Count;
                    for (int i = 0; i < waterCount; i++)
                    {

                        int x = r.randomD(mapSize - 1);
                        int y = r.randomDP(mapSize - 1, mapSize, x);
                        Point p = new Point(x, y);
                        if ((!brickLocations.Contains(p)) & (!obstacles.Contains(p)) & (!water.Contains(p)))
                        {
                            GameEngine.water.Add(p);
                            if (i != 0)
                            {
                                GameEngine.mapDetails = GameEngine.mapDetails + ";";
                            }
                            GameEngine.mapDetails = GameEngine.mapDetails + x + "," + y;
                            writeConsoleLines("water:- " + (i + 1) + "/" + waterCount + " created", lineCount);
                        }
                        else
                        {
                            i--;
                        }
                    }

                    //Create brick walls
                    for (int i = 0; i < brickLocations.Count; i++)
                    {
                        brickWalls.Add(new BrickWall(brickLocations[i]));
                    }

                    int tresCount = (Constant.CoinPile_RATE) * (Constant.LIFE_TIME / 60000);// CoinPiles for every 1 min
                    consoleLinesDoProgress();
                    MapItem tempMapItem;
                    consoleLinesDoProgress();

                    List<Point> points = CreatePointList(tresCount);

                    lineCount = consoleLines.Count;

                    for (int i = 0; i < Math.Min(tresCount, points.Count); i++)
                    {

                        try
                        {
                            tempMapItem = CreateMapItem(points[i], true);

                            List<MapItem> conflictPoints = new List<MapItem>();

                            for (int j = 0; j < CoinPileList.Count; j++)
                            {
                                conflictPoints.Add(CoinPileList[j]);
                            }

                            Boolean pass = GetMapItemAcceptance(tempMapItem, conflictPoints);

                            if (pass)
                            {
                                GameEngine.coinPileList.Add((CoinPile)tempMapItem);
                                writeConsoleLines("CoinPiles :- " + (i + 1) + "/" + Math.Min(tresCount, points.Count) + " created", lineCount);
                            }
                            else
                            {
                                i--;//Recalculate
                            }
                        }
                        catch (Exception e)
                        {
                            Console.WriteLine("...............................");
                            Console.WriteLine(e.StackTrace);
                            Console.WriteLine("...............................");
                        }
                    }

                    int lifePackCount = (Constant.LIFEPACK_RATE) * (Constant.LIFE_TIME / 60000);// CoinPiles for every 1 min
                    consoleLinesDoProgress();

                    points = CreatePointList(lifePackCount);

                    lineCount = consoleLines.Count;

                    for (int i = 0; i < Math.Min(lifePackCount, points.Count); i++)
                    {
                        try
                        {
                            tempMapItem = CreateMapItem(points[i], false);

                            List<MapItem> conflictPoints = new List<MapItem>();

                            for (int j = 0; j < CoinPileList.Count; j++)
                            {
                                conflictPoints.Add(CoinPileList[j]);
                            }
                            for (int j = 0; j < lifePackList.Count; j++)
                            {
                                conflictPoints.Add(lifePackList[j]);
                            }

                            Boolean pass = GetMapItemAcceptance(tempMapItem, conflictPoints);

                            if (pass)
                            {
                                GameEngine.lifePackList.Add((LifePack)tempMapItem);
                                writeConsoleLines("LifePacks :- " + (i + 1) + "/" + Math.Min(lifePackCount, points.Count) + " created", lineCount);
                            }
                            else
                            {
                                i--;//Recalculate
                            }
                        }
                        catch (Exception e)
                        {
                            Console.WriteLine("...............................");
                            Console.WriteLine(e.StackTrace);
                            Console.WriteLine("...............................");
                        }

                    }

                    writeConsoleLines("\nMap generation was successful!");

                    Console.Write("\n");
                    for (int i = 0; i < mapSize; i++)
                    {
                        for (int j = 0; j < mapSize; j++)
                        {
                            Point p = new Point(j, i);
                            if (brickLocations.Contains(p))
                            {
                                Console.Write("B");
                            }
                            else if (obstacles.Contains(p))
                            {
                                Console.Write("S");
                            }
                            else if (water.Contains(p))
                            {
                                Console.Write("W");
                            }
                            else
                            {
                                Console.Write("N");
                            }
                            Console.Write(" ");
                        }
                        Console.Write("\n");
                    }
                    Console.Write("\n");

                    sortCoinPileLists();

                }
                catch (Exception ex2)
                {
                    Console.WriteLine("Could not load nor generate Map!!!\n\n");
                    Console.WriteLine("Error Message: " + ex1.Message + "\n\n");
                    Console.WriteLine("Error Message: " + ex2.Message + "\n\n");
                    Console.WriteLine("Server not started! Please restart the server!");
                    while (true)
                    {
                        Console.ReadLine();
                    }
                }
            }
        }
示例#4
0
        private List<Point> CreatePointList(int itemCount)
        {
            RandomGen r = new RandomGen();

            int lineCount = consoleLines.Count;

            List<Point> points = new List<Point>();

            for (int i = 0; i < mapSize; i++)
            {
                for (int j = 0; j < mapSize; j++)
                {
                    Point p = new Point(i, j);
                    points.Add(p);
                }
            }

            for (int i = 0; i < points.Count; i++)
            {
                if ((brickLocations.Contains(points[i])) | (obstacles.Contains(points[i])) | (water.Contains(points[i])))
                {
                    points.RemoveAt(i);
                    i--;
                }
            }

            while (points.Count < itemCount)
            {
                writeConsoleLines("Adjusting  point list size " + (points.Count * 100) / itemCount + "% done", lineCount);
                int i = r.randomDD(points.Count - 1);
                points.Add(points[i]);
            }
            writeConsoleLines("Adjusting  point list size 100% done", lineCount);

            return (points);
        }
示例#5
0
        private MapItem CreateMapItem(Point p, Boolean isCoinPile)
        {
            RandomGen r = new RandomGen();

            MapItem tempMapItem;
            if (isCoinPile)
            {
                tempMapItem = new CoinPile(p.X, p.Y);
                ((CoinPile)tempMapItem).Price = r.randomD(700, 2000);
            }
            else
            {
                tempMapItem = new LifePack(p.X, p.Y);
            }
            tempMapItem.LifeTime = r.randomD(Convert.ToInt32((Constant.MAP_SIZE / 4) * Constant.PLAYER_DELAY), Constant.LIFE_TIME / 10);
            tempMapItem.AppearTime = r.randomD(0, (Constant.LIFE_TIME - tempMapItem.LifeTime));

            tempMapItem.DisappearTime = tempMapItem.AppearTime + tempMapItem.LifeTime;
            return tempMapItem;
        }