示例#1
0
        public Movimiento CalcularMovimiento(ArbolGeneral <Planeta> arbol)
        {
            if (!arbol.getDatoRaiz().EsPlanetaDeLaIA())
            {
                ArrayList lista = new ArrayList();
                lista = preordenCaminoIA(lista, arbol);
                Planeta origen  = (Planeta)lista[lista.Count - 1];
                Planeta destino = (Planeta)lista[lista.Count - 2];
                return(new Movimiento(origen, destino));
            }
            else
            {
                ArrayList lista = new ArrayList();
                lista = preordenCaminoJugador(lista, arbol);
                int     a = 0, b = 1;
                Planeta origen  = (Planeta)lista[a];
                Planeta destino = (Planeta)lista[b];
                for (int i = 0; i < lista.Count; i++)
                {
                    Planeta elegido       = (Planeta)lista[i];
                    Planeta elegidoMasUno = (Planeta)lista[i + 1];
                    if (elegido.EsPlanetaDeLaIA() && !elegidoMasUno.EsPlanetaDeLaIA())
                    {
                        return(new Movimiento(elegido, elegidoMasUno));
                    }
                }

                return(new Movimiento(origen, destino));
            }
        }
示例#2
0
 public PlanetRenderer(Planeta planet)
 {
     this.planet     = planet;
     this.ellipse    = new Ellipse(planet.position, planet.size, planet.size);
     this.brush      = planet.game.brushes[planet.team];
     this.textFormat = new TextFormat(planet.game.factoryWrite, "Arial", 20);
     this.textLayout = new TextLayout(planet.game.factoryWrite, planet.population.ToString(), textFormat, 36.0f, 24.0f);
 }
示例#3
0
 public GameScene(Game game)
     : base(game)
 {
     this.selectedPlanet        = null;
     this.objects               = LevelLoader.objects;
     this.arbolDePlanetas       = LevelLoader.arbolDePlanetas;
     game.scene.arbolDePlanetas = LevelLoader.arbolDePlanetas;
     this.playerTeam            = 1;
     objects.Add(new IA(game));
     objects.Add(new WinLooseChecker(game));
 }
示例#4
0
        public Route(Game game, Planeta source, Planeta destination) : base(game)
        {
            this.source       = source;
            this.destination  = destination;
            this.ships        = new List <Ship>();
            this.autoTransfer = false;
            this.acc          = 0.0f;
            double angle = Math.Atan2(source.position.Y - destination.position.Y, source.position.X - destination.position.X);

            this.start         = source.position - source.size * new Vector2((float)Math.Cos(angle), (float)Math.Sin(angle));
            this.end           = destination.position + destination.size * new Vector2((float)Math.Cos(angle), (float)Math.Sin(angle));
            this.routeRenderer = new RouteRenderer(this);
        }
示例#5
0
        private static void setPlanets(Game game, List <Planeta> planets, uint enemyCount)
        {
            enemyCount++;
            List <int> unusedPlanets = Enumerable.Range(0, planets.Count).ToList();

            for (int i = 0; i < enemyCount; i++)
            {
                int randomIndex = unusedPlanets[rnd.Next(unusedPlanets.Count)];
                unusedPlanets.Remove(randomIndex);
                Planeta randomPlanet = planets[randomIndex];
                randomPlanet.population = 10;
                randomPlanet.team       = i + 1;
            }
        }
示例#6
0
 public Ship(Game game, Route route, Planeta source, Planeta destination, uint population, int team)
     : base(game)
 {
     this.population  = population;
     this.team        = team;
     this.route       = route;
     this.source      = source;
     this.destination = destination;
     this.direction   = destination.position - source.position;
     this.direction.Normalize();
     this.position     = calculateStartPosition();
     this.speed        = 30.0f;
     this.shipRenderer = new ShipRenderer(this);
 }
示例#7
0
 public override void OnMouseClick(int x, int y, MouseButtons mouseButtons)
 {
     foreach (Planeta planet in objects.Where(obj => obj is Planeta))
     {
         if (planet.IsClicked(x, y))
         {
             if (selectedPlanet == null && (planet.team == playerTeam))
             {
                 selectedPlanet = planet;
             }
             else
             {
                 if (mouseButtons == MouseButtons.Left)
                 {
                     SendFleet(selectedPlanet, planet);
                 }
                 else if (mouseButtons == MouseButtons.Right)
                 {
                     foreach (Route route in objects.Where(obj => obj is Route))
                     {
                         if (((route.source == selectedPlanet) && (route.destination == planet)) ||
                             ((route.source == planet) && (route.destination == selectedPlanet)))
                         {
                             if (route.autoTransfer == false)
                             {
                                 if (route.source != selectedPlanet)
                                 {
                                     Vector2 temp = route.start;
                                     route.start = route.end;
                                     route.end   = temp;
                                 }
                                 route.autoTransfer = true;
                                 route.source       = selectedPlanet;
                                 route.destination  = planet;
                             }
                             else
                             {
                                 route.autoTransfer = false;
                             }
                             break;
                         }
                     }
                 }
                 selectedPlanet = null;
             }
             break;
         }
     }
 }
示例#8
0
        private static void createCentralPlanet(Game game, List <Planeta> planets, List <Route> routes)
        {
            Vector2    position            = new Vector2(400.0f, 300.0f) + rnd.NextVector2(new Vector2(-20.0f, -20.0f), new Vector2(20.0f, 20.0f));
            Planeta    central             = new Planeta(game, position, (uint)(20 + rnd.Next(40)), (uint)rnd.Next(10));
            int        routesCount         = rnd.Next(1, 4);
            List <int> indicesNotConnected = Enumerable.Range(0, planets.Count).ToList <int>();

            for (int i = 0; i < routesCount; i++)
            {
                int planetIndex = indicesNotConnected[rnd.Next(indicesNotConnected.Count)];
                indicesNotConnected.Remove(planetIndex);
                routes.Add(new Route(game, central, planets[planetIndex]));
            }
            planets.Add(central);
        }
示例#9
0
 public void SendFleet(Planeta from, Planeta to)
 {
     foreach (Route route in objects.Where(obj => obj is Route))
     {
         if (((route.source == from) && (route.destination == to)) || ((route.source == to) && (route.destination == from)))
         {
             if (from.population > 1)
             {
                 Ship ship = new Ship(game, route, from, to, from.population / 2, from.team);
                 objects.Add(ship);
                 route.AddShip(ship);
                 from.population /= 2;
                 break;
             }
         }
     }
 }
示例#10
0
        public ArrayList preordenCaminoJugador(ArrayList lista, ArbolGeneral <Planeta> arbol)
        {
            Planeta planeta = arbol.getDatoRaiz();

            lista.Add(planeta);
            if (planeta.EsPlanetaDelJugador())
            {
                return(lista);
            }
            else
            {
                foreach (ArbolGeneral <Planeta> i in arbol.getHijos())
                {
                    ArrayList lista2 = preordenCaminoJugador(lista, i);
                    if (lista2 != null)
                    {
                        return(lista2);
                    }
                    lista.RemoveAt(lista.Count - 1);
                }
            }

            return(null);
        }
示例#11
0
 public Movimiento(Planeta o, Planeta d)
 {
     this.origen  = o;
     this.destino = d;
 }