コード例 #1
0
ファイル: Game.cs プロジェクト: L4fter/Orb
    private void CreateCelestialSystemFromScene()
    {
        celestialSystem = resolver.Resolve <CelestialSystem>();
        var planets     = planetFactory.CollectAllAvailablePlanets();
        var centralStar = planets.OrderByDescending(planet => planet.SimulatedEntity.Mass).First();

        celestialSystem.AddCentralStar(centralStar);
        celestialSystem.Add(planets);

        var allAvailableWeapons = weaponFactory.GetAllAvailableTypes();

        var onlyPlanets = planets.Except(new[] { centralStar }).ToList();
        var randomIndex = Random.Range(0, onlyPlanets.Count);

        var randomPlanet = onlyPlanets.Skip(randomIndex).First();
        var randomWeapon = allAvailableWeapons[Random.Range(0, allAvailableWeapons.Count)];

        weaponFactory.AddWeapon(randomWeapon, randomPlanet);
        inputPlanetController.Control(randomPlanet, randomPlanet.Weapon);
        playerStatsProvider.SetPlayerPlanet(randomPlanet);

        onlyPlanets.Remove(randomPlanet);

        randomIndex  = Random.Range(0, onlyPlanets.Count);
        randomPlanet = onlyPlanets.Skip(randomIndex).First();
        randomWeapon = allAvailableWeapons[Random.Range(0, allAvailableWeapons.Count)];
        weaponFactory.AddWeapon(randomWeapon, randomPlanet);
        aiPlanetController.Control(randomPlanet, randomPlanet.Weapon);
    }
コード例 #2
0
        /// <summary>
        /// Loads a minimized data set for design time.
        /// </summary>
        /// <returns>
        /// A minimized <see cref="CelestialSystem"/>.
        /// </returns>
        public CelestialSystem LoadSampleData()
        {
            var sun = new CelestialBody()
            {
                Name        = "Sun",
                IoPin       = 4,
                Description = "The Sun is the star at the center of the Solar System and is by far the most important source of energy for life on Earth. It is a nearly perfect spherical ball of hot plasma, with internal convective motion that generates a magnetic field via a dynamo process.",
            };

            var earth = new CelestialBody()
            {
                Name        = "Earth",
                IoPin       = 26,
                Description = "Earth is the third planet from the Sun, the densest planet in the Solar System, the largest of the Solar System's four terrestrial planets, and the only astronomical object known to harbor life.",
                Day         = new TimeSpan(24, 0, 0),
                Orbit       = 150,
                Year        = TimeSpan.FromDays(365)
            };

            var mars = new CelestialBody()
            {
                Name        = "Mars",
                Description = "Mars is the fourth planet from the Sun and the second smallest planet in the Solar System, after Mercury. Named after the Roman god of war, it is often referred to as the \"Red Planet\" because the iron oxide prevalent on its surface gives it a reddish appearance.",
                Day         = new TimeSpan(24, 39, 0),
                Orbit       = 230,
                Year        = TimeSpan.FromDays(687)
            };


            var iceFact = new CelestialFact()
            {
                Title       = "Planets with ice",
                Contributor = "Bienz / Vasek Family",
                Description = "Both Earth and Mars have ice but Mars contains very little ice.",
                Bodies      = new List <CelestialBody>()
                {
                    earth,
                    mars
                }
            };

            var system = new CelestialSystem()
            {
                Bodies = new List <CelestialBody>()
                {
                    sun,
                    earth,
                    mars
                },
                Facts = new List <CelestialFact>()
                {
                    iceFact
                }
            };

            string ssjson = JsonConvert.SerializeObject(system, Formatting.Indented);

            return(system);
        }
コード例 #3
0
ファイル: Game.cs プロジェクト: L4fter/Orb
    private void CreateCelestialSystemFromSerialized()
    {
        celestialSystem = csProvider.CreateFromSerialized(projectileFactory, planetFactory, weaponFactory);
        var aiPlanet = celestialSystem.Planets[csProvider.AiControlledPlanetIndex];

        aiPlanetController.Control(aiPlanet, aiPlanet.Weapon);

        var playerPlanet = celestialSystem.Planets[csProvider.PlayerControlledPlanetIndex];

        inputPlanetController.Control(playerPlanet, playerPlanet.Weapon);
        playerStatsProvider.SetPlayerPlanet(playerPlanet);
    }
コード例 #4
0
        /// <summary>
        /// Initializes speech recognition and begins listening.
        /// </summary>
        /// <param name="system">
        /// The <see cref="CelestialSystem"/> used to build voice commands and return results.
        /// </param>
        /// <returns>
        /// A <see cref="Task"/> that yields the result of the operation.
        /// </returns>
        public async Task <SpeechRecognitionResultStatus> InitializeAsync(CelestialSystem system)
        {
            // Validate
            if (isInitialized)
            {
                throw new InvalidOperationException("Already initialized.");
            }
            if (system == null)
            {
                throw new ArgumentNullException("system");
            }

            // Store
            this.system = system;

            // Create recognizer
            recognizer = new SpeechRecognizer();

            // Configure to never stop listening
            recognizer.ContinuousRecognitionSession.AutoStopSilenceTimeout = TimeSpan.MaxValue;

            // Subscribe to events
            recognizer.StateChanged += RecognizerStateChanged;
            recognizer.ContinuousRecognitionSession.Completed       += ContinuousRecognitionSession_Completed;
            recognizer.ContinuousRecognitionSession.ResultGenerated += RecognizerResultGenerated;

            // Load constraint
            var constraint = await LoadDynamicConstraintAsync();

            // Add constraint to recognizer
            recognizer.Constraints.Add(constraint);

            // Compile
            var compileResult = await recognizer.CompileConstraintsAsync();

            Debug.WriteLine("Grammar Compiled: " + compileResult.Status.ToString());

            // We're initialized now
            isInitialized = true;

            // If successful start recognition
            if (compileResult.Status == SpeechRecognitionResultStatus.Success)
            {
                await recognizer.ContinuousRecognitionSession.StartAsync(SpeechContinuousRecognitionMode.Default);
            }

            // Return the result
            return(compileResult.Status);
        }
コード例 #5
0
        private async void Initialize()
        {
            SelectedBodies = new ObservableCollection <CelestialBody>();
            dataManager    = new DataManager();
            if (this.IsInDesignMode)
            {
                system = dataManager.LoadSampleData();
            }
            else
            {
                system = await dataManager.LoadDataAsync();
                await InitSpeechAsync();

                InitIO();
            }
        }
コード例 #6
0
ファイル: Serializer.cs プロジェクト: L4fter/Orb
    public void Serialize(CelestialSystem cs)
    {
        scs = new SerializedCs();
        var planets = cs.Planets;

        scs.playerIndex = planets.FindIndex(planet => planet.ControlledBy is InputPlanetController);
        scs.aiIndex     = planets.FindIndex(planet => planet.ControlledBy is AiPlanetController);

        scs.planets = new List <SerializedPlanet>();
        foreach (var planet in planets)
        {
            scs.planets.Add(new SerializedPlanet()
            {
                entity     = SerializedEntity.FromEntity(planet.SimulatedEntity),
                hp         = planet.Hp,
                startHp    = planet.StartHp,
                color      = planet.Appearance.color,
                weaponType = planet.Weapon?.Type.Name,
            });
        }

        scs.planets.Add(new SerializedPlanet()
        {
            entity    = SerializedEntity.FromEntity(cs.centralStar.SimulatedEntity),
            hp        = cs.centralStar.Hp,
            startHp   = cs.centralStar.StartHp,
            color     = cs.centralStar.Appearance.color,
            isCentral = true,
        });


        scs.projectiles = new List <SerializedProjectile>();
        foreach (var projectile in cs.Projectiles)
        {
            scs.projectiles.Add(new SerializedProjectile()
            {
                entity = SerializedEntity.FromEntity(projectile),
            });
        }

        var json = JsonUtility.ToJson(scs);

        PlayerPrefs.SetString(saveGameKey, json);
        PlayerPrefs.Save();
    }
コード例 #7
0
 public AllBodiesEnumerable(CelestialSystem system)
 {
     this.system = system;
 }