예제 #1
0
        public string makeName(List <MapPlanet> exists, string iWantThisName = "")
        {
            if (iWantThisName == "")
            {
                iWantThisName = "Безымянная";
            }

            bool   ohWeHave = true;
            int    index    = 1;
            string backup   = iWantThisName;

            while (ohWeHave)
            {
                MapPlanet f = exists.Where(c => c.name == iWantThisName).FirstOrDefault();

                if (f == null)
                {
                    ohWeHave = false;
                }
                else
                {
                    index++;
                    iWantThisName = backup + " " + index.ToString();
                }
            }

            return(iWantThisName);
        }
예제 #2
0
        static void Main(string[] args)
        {
            roverApi = new RoverOnMarsApi.Swagger.Api.RoverApi("http://localhost:5000");

            //Load map and obstacles that rover had elaborated
            obstacles = roverApi.RoverGetObstaclesGet();
            mapPlanet = roverApi.RoverGetMapPlanetGet();

            //Initialize rover position and direction
            Position      currentPosition  = new Position(1, 1);
            DirectionEnum currentDirection = DirectionEnum.Est;

            //Draw map with rover in current position and obstacles
            DrawUpdatedMap(currentPosition.X.Value, currentPosition.Y.Value, currentDirection);

            while (true)
            {
                Console.WriteLine("q = exit - Commands: f = forward, b = backward, l = left, r = right. es. f,f,l,r,b");
                //wait the command series
                string command = Console.ReadLine();

                if (command == "q")
                {
                    break;
                }
                else
                {
                    //move rover from remote
                    var movement = roverApi.RoverMoveRoverPost(
                        currentPosition,
                        command,
                        currentDirection);

                    currentPosition  = movement.Position;
                    currentDirection = movement.Direction;

                    //update map
                    DrawUpdatedMap(movement.Position.X.Value, movement.Position.Y.Value, currentDirection);

                    if (movement.Obstacle != null)
                    {
                        Console.WriteLine($"The rover was stopped by obstacle in coordinate [{movement.Obstacle.Position.X},{movement.Obstacle.Position.Y}]. Press Enter to be continue.");
                        Console.ReadLine();
                    }
                    else if (!movement.Result.Value)
                    {
                        Console.WriteLine("Command not supported. Press Enter to be continue.");
                        Console.ReadLine();
                    }
                }
            }
        }
예제 #3
0
파일: Renderer.cs 프로젝트: RikkiRu/ToSpace
        public void drawPlanetMap(MapPlanet x)
        {
            if (backgroundQuad == null)
            {
                float orth = display.ortoX + 5;
                if (display.ortoX < display.ortoY)
                {
                    orth = display.ortoY + 5;
                }

                backgroundStatic   = new textureObject(@"planet/PlanetBack", 1000, orth, orth);
                backgroundStatic.x = display.ortoX / 2;
                backgroundStatic.y = display.ortoY / 2;



                if (x.defaultQuad.type == typeOfquad.grass)
                {
                    backgroundQuad   = new textureObject(@"planet/planetGrass", 0, x.sizeX * quadSize, x.sizeY * quadSize, x.sizeX, x.sizeY);
                    backgroundQuad.x = (x.sizeX - 1) * quadSize / 2;
                    backgroundQuad.y = (x.sizeY - 1) * quadSize / 2;
                }

                border   = new textureObject(@"planet/border", 0, quadSize * (x.sizeX + 0.5f), quadSize * (x.sizeY + 0.5f));
                border.x = backgroundQuad.x;
                border.y = backgroundQuad.y;
            }

            else
            {
                display.drawObject(backgroundQuad);
            }

            for (int i = 0; i < x.sizeX; i++)
            {
                for (int j = 0; j < x.sizeY; j++)
                {
                    float xi = i * quadSize;
                    float xj = j * quadSize;

                    if (x.quads[i, j] != null)
                    {
                        drawQuad(x.quads[i, j], xi, xj);
                    }

                    if (x.objects[i, j] != null)
                    {
                        drawObject(x.objects[i, j], xi, xj);
                    }
                }
            }
        }
예제 #4
0
        /// <summary>
        /// Load the map of planet (example, by image recognition that write json file)
        /// </summary>
        private void LoadMapPlanet()
        {
            try
            {
                _mapPlanet = JsonConvert.DeserializeObject <MapPlanet>(System.IO.File.ReadAllText("Data/mapPlanet.json"));
            }
            catch (Exception ex)
            {
                _logger.LogError(ex.Message);

                _mapPlanet = new MapPlanet()
                {
                    Height = 10, Length = 10
                };
            }
        }
예제 #5
0
        public void generatorForNewPlayer(object p)
        {
            Player player = structure.PlayerList.Where(c => c.name == ((Player)p).name).FirstOrDefault();

            MapPlanet yourSweetHome = generator.generatePlanet(structure.world.planets, generator.defaultSizeX, generator.defaultSizeY, new MapPlanetQuad {
                type = typeOfquad.grass
            }, 50, 30, 30, 30, new mapPlanetResource {
                o2 = 100, temperature = 27
            });

            structure.world.planets.Add(yourSweetHome);



            bool govPlaced = false;

            while (!govPlaced)
            {
                int rx = generator.rand.Next(0, yourSweetHome.sizeX);
                int ry = generator.rand.Next(0, yourSweetHome.sizeY);

                if (yourSweetHome.quads[rx, ry] == null || yourSweetHome.quads[rx, ry].type == typeOfquad.grass || yourSweetHome.quads[rx, ry].type == typeOfquad.snow || yourSweetHome.quads[rx, ry].type == typeOfquad.desert)
                {
                    govPlaced = true;
                    yourSweetHome.objects[rx, ry] = new Building {
                        type = buildingType.capital, owner = player.name, resourses = new capitialResource {
                            populationLimit = 1, d_populdation = 1, d_eat = 1
                        }
                    };
                    player.resourceUpdater = yourSweetHome.objects[rx, ry];

                    yourSweetHome.sectors[rx, ry] = generator.generateSector(yourSweetHome.quads[rx, ry]);
                    player.currentMap             = yourSweetHome.sectors[rx, ry];
                }
            }


            Console.WriteLine("Сгенерирована карта для " + player.name);
        }
예제 #6
0
        public MapPlanet generatePlanet(List <MapPlanet> exists, int sizeX, int sizeY, MapPlanetQuad defQuad, int waterPercent, int forestPercent, int icePercent, int desertPercent, mapPlanetResource enviroment)
        {
            MapPlanet res = new MapPlanet();

            res.name        = makeName(exists);
            res.defaultQuad = defQuad;

            lastX += distansePlanetX;
            res.x  = lastX;
            res.y  = lastY;
            if (inLineCurrent >= planetsPerLine)
            {
                lastY        += distansePlanetY;
                inLineCurrent = 0;
                lastX         = 0;
            }

            res.sizeX = sizeX;
            res.sizeY = sizeY;

            res.quads   = new MapPlanetQuad[sizeX, sizeY];
            res.objects = new GameObject[sizeX, sizeY];
            res.sectors = new mapSector[sizeX, sizeY];

            int Ssize = sizeX * sizeY;

            int oceanTotal  = Ssize * waterPercent / 100;
            int forestTotal = Ssize * forestPercent / 100;


            for (int i = 0; i < oceanTotal; i++)
            {
                int rx = rand.Next(0, sizeX);
                int ry = rand.Next(0, sizeY);

                res.quads[rx, ry]      = new MapPlanetQuad();
                res.quads[rx, ry].type = typeOfquad.water;
            }

            int LineIce = res.sizeY * icePercent / 100;

            for (int j = 0; j < LineIce; j++)
            {
                for (int i = 0; i < sizeX; i++)
                {
                    if (j == LineIce - 1)
                    {
                        if (res.quads[i, j] == null)
                        {
                            res.quads[i, j] = new MapPlanetQuad();
                        }
                        res.quads[i, j].type          = typeOfquad.snow;
                        res.quads[i, j].textureParams = 1;
                    }

                    else
                    {
                        if (res.quads[i, j] != null && res.quads[i, j].type == typeOfquad.water)
                        {
                            res.quads[i, j].type = typeOfquad.ice;
                        }
                        else
                        {
                            if (res.quads[i, j] == null)
                            {
                                res.quads[i, j] = new MapPlanetQuad();
                            }
                            res.quads[i, j].type          = typeOfquad.snow;
                            res.quads[i, j].textureParams = 0;
                        }
                    }
                }
            }



            int LineDesert = res.sizeY - res.sizeY * desertPercent / 100;

            for (int j = sizeY - 1; j >= LineDesert; j--)
            {
                for (int i = 0; i < sizeX; i++)
                {
                    if (j == LineDesert)
                    {
                        if (res.quads[i, j] == null)
                        {
                            res.quads[i, j] = new MapPlanetQuad();
                        }
                        res.quads[i, j].type          = typeOfquad.desert;
                        res.quads[i, j].textureParams = 1;
                    }

                    else
                    {
                        if (res.quads[i, j] != null && res.quads[i, j].type == typeOfquad.water)
                        {
                            if (rand.Next(0, 10) == 0)
                            {
                                res.quads[i, j].type = typeOfquad.oasis;
                            }
                            else
                            {
                                res.quads[i, j].type          = typeOfquad.desert;
                                res.quads[i, j].textureParams = 0;
                            }
                        }
                        else
                        {
                            if (res.quads[i, j] == null)
                            {
                                res.quads[i, j] = new MapPlanetQuad();
                            }
                            res.quads[i, j].type          = typeOfquad.desert;
                            res.quads[i, j].textureParams = 0;
                        }
                    }
                }
            }

            setupWaterTurns(ref res.quads, typeOfquad.water);
            setupWaterTurns(ref res.quads, typeOfquad.ice);



            for (int i = 0; i < forestTotal; i++)
            {
                int rx = rand.Next(0, sizeX);
                int ry = rand.Next(0, sizeY);

                typeOfquad tQuad = defQuad.type;
                if (res.quads[rx, ry] != null)
                {
                    tQuad = res.quads[rx, ry].type;
                }


                switch (tQuad)
                {
                case typeOfquad.snow:
                    res.objects[rx, ry] = new forest();
                    res.objects[rx, ry].textureParams = 0;
                    break;

                case typeOfquad.grass:
                    res.objects[rx, ry] = new forest();
                    res.objects[rx, ry].textureParams = 1;
                    break;

                case typeOfquad.desert:
                    res.objects[rx, ry] = new forest();
                    if (rand.Next(0, 2) == 0)
                    {
                        res.objects[rx, ry].textureParams = 2;
                    }
                    else
                    {
                        res.objects[rx, ry].textureParams = 3;
                    }
                    break;
                }
            }

            res.enviroment      = enviroment;
            res.enviroment.d_o2 = forestTotal;


            return(res);
        }