Beispiel #1
0
 public Unit[][] GenerateGrid(int xSize, int ySize)
 {
     Console.WriteLine("===Abstract Factory===");
     goldMinePrototype = (GoldMine)mapFactory.CreateSuperObstacle("Gold Mine", 0, 0);
     wonderPrototype   = (Wonder)mapFactory.CreateSuperObstacle("Wonder", 0, 0);
     stonePrototype    = (Stone)mapFactory.CreateObstacle("Stone", 0, 0);
     Console.WriteLine("========");
     Console.WriteLine("===Prototype===");
     //----------Testavimui
     //stonePrototype.TakeUnit(new Player());
     //goldMinePrototype.TakeUnit(new Player());
     //----------
     Grid = new Unit[ySize][];
     for (int y = 0; y < ySize; y++)
     {
         Grid[y] = new Unit[xSize];
         for (int x = 0; x < xSize; x++)
         {
             double obstacleValue = random.NextDouble();
             if (obstacleValue > CWonderThreshold && !IsInOuterZone(x, y) && !isNearbyObstacle(x, y))
             {
                 Grid[y][x] = (Unit)wonderPrototype.ShallowCopy();
                 Grid[y][x].SetCoordinates(x, y);
                 //----------Testavimui
                 //Console.WriteLine("Wonder original address " + wonderPrototype.GetHashCode() + " Wonder copy address " + Grid[y][x].GetHashCode());
                 //----------
             }
             else if (obstacleValue > CGoldMineThreshold && !IsInOuterZone(x, y) && !isNearbyObstacle(x, y))
             {
                 Grid[y][x] = (Unit)goldMinePrototype.ShallowCopy();
                 Grid[y][x].SetCoordinates(x, y);
                 //----------Testavimui
                 //Console.WriteLine("Gold Mine original address " + goldMinePrototype.GetHashCode() + " Gold Mine copy address " + Grid[y][x].GetHashCode());
                 //Console.WriteLine("Gold Mine Player original address " + goldMinePrototype.GetPlayer().GetHashCode() + " Gold Mine Player copy address " + Grid[y][x].GetPlayer().GetHashCode());
                 //----------
             }
             else if (obstacleValue > CStoneThreshold && !IsInOuterZone(x, y) && !isNearbyObstacle(x, y))
             {
                 //----------Testavimui
                 //Grid[y][x] = (Unit)stonePrototype.DeepCopy();
                 //----------
                 Grid[y][x] = (Unit)stonePrototype.ShallowCopy();
                 Grid[y][x].SetCoordinates(x, y);
                 //----------Testavimui
                 //Console.WriteLine("Stone original address " + stonePrototype.GetHashCode() + " Stone copy address " + Grid[y][x].GetHashCode());
                 //Console.WriteLine("Stone Player original address " + stonePrototype.GetPlayer().GetHashCode() + " Stone Player copy address " + Grid[y][x].GetPlayer().GetHashCode());
                 //----------
             }
             else
             {
                 Grid[y][x] = new Unit(x, y);
             }
         }
     }
     Console.WriteLine("========");
     return(Grid);
 }