Esempio n. 1
0
        /*
         * Create a map using the C++ library
         */

        public int[] getMoves(MapStrategy strategy, UnitAPI unit, PlayerAPI p1, PlayerAPI p2, int curr_p, GameAPI game)
        {
            int[] curr_pos = { unit.x, unit.y };
            Race  race     = (curr_p == 1) ? p1.race : p2.race;

            int[]      moves = new int[strategy.size * strategy.size];
            TileType[] tiles = new TileType[strategy.size * strategy.size];
            int[]      pos   = new int[strategy.size * strategy.size];


            foreach (var tmpUnit in p1.units)
            {
                pos[tmpUnit.y * strategy.size + tmpUnit.x] = 1;
            }
            foreach (var tmpUnit in p1.units)
            {
                pos[tmpUnit.y * strategy.size + tmpUnit.x] = 2;
            }


            for (int i = 0; i < strategy.size; i++)
            {
                for (int j = 0; j < strategy.size; j++)
                {
                    tiles[i + strategy.size * j] = game.map.tiles[i, j].getType();
                }
            }

            Algo_getMoves(nativeAlgo, tiles, strategy.size, pos, curr_pos, curr_p, race, moves);
            return(moves);
        }
Esempio n. 2
0
        public MapAPI createMap(MapStrategy strategy, GameAPI game)
        {
            MapAPI        map           = new Map(strategy.size);
            TileFlyweight tileFlyweight = new TileFlyweight();

            TileType[] tiles1D = new TileType[strategy.size * strategy.size];
            int[]      pos     = new int[strategy.size * strategy.size];
            int[]      posp1   = new int[2]; // posp1[0],posp1[1] : position (x,y) of unit's player1 at the beginning
            int[]      posp2   = new int[2];
            // Call to the dll method
            Algo_fillMap(nativeAlgo, tiles1D, strategy.size, pos);

            // Converts TileType (enum) 2D array into a Tile (object) array
            for (int i = 0; i < strategy.size; i++)
            {
                for (int j = 0; j < strategy.size; j++)
                {
                    map.tiles[i, j] = tileFlyweight.getTile(tiles1D[i + strategy.size * j]);
                    if (pos[i + strategy.size * j] == 1)
                    {
                        posp1[0] = i;
                        posp1[1] = j;
                    }
                    else if (pos[i + strategy.size * j] == 2)
                    {
                        posp2[0] = i;
                        posp2[1] = j;
                    }
                }
            }

            //Define units for each player
            placeUnits(map, game.player1, strategy.nb_units, posp1);
            placeUnits(map, game.player2, strategy.nb_units, posp2);
            return(map);
        }
Esempio n. 3
0
 public MapTilesFactory(MapType type)
 {
     this.map_strategy = getMapStrategy(type);
 }