Пример #1
0
        /// <summary>
        /// Allows the game to perform any initialization it needs to before starting to run.
        /// This is where it can query for any required services and load any non-graphic
        /// related content.  Calling base.Initialize will enumerate through any components
        /// and initialize them as well.
        /// </summary>
        protected override void Initialize()
        {
            MonsterManager.Initialize();
            SpellManager.Initialize();
            AttackManager.Initialize();
            SoundManager.Initialize();
            TextManager.Initialize(360, 413);
            TeamManager.Initialize();

            sceneOne = new BattleScene(1, 50, 130); // y was 139
            sceneOne.Initialize();

            sceneTwo = new BattleScene(2, 665, 130, true);
            sceneTwo.Initialize();

            combatThread = new Thread(CombatLoop);

            base.Initialize();
        }
Пример #2
0
        /// <summary>
        /// Allows the game to run logic such as updating the world,
        /// checking for collisions, gathering input, and playing audio.
        /// </summary>
        /// <param name="gameTime">Provides a snapshot of timing values.</param>
        protected override void Update(GameTime gameTime)
        {
            if (GamePad.GetState(PlayerIndex.One).Buttons.Back == ButtonState.Pressed || Keyboard.GetState().IsKeyDown(Keys.Escape))
            {
                Exit();
            }

            sceneOne.UpdateSceneText();
            sceneTwo.UpdateSceneText();
            sceneOne.Update(gameTime);
            sceneTwo.Update(gameTime);

            // Update Managers
            StatusSpriteManager.Update(gameTime);
            MagicSpriteManager.Update(gameTime);
            TeamManager.Update(gameTime);

            base.Update(gameTime);
        }
Пример #3
0
        /// <summary>
        /// LoadContent will be called once per game and is the place to load
        /// all of your content.
        /// </summary>
        protected override void LoadContent()
        {
            // Create a new SpriteBatch, which can be used to draw textures.
            spriteBatch = new SpriteBatch(GraphicsDevice);

            // Graphics
            gameBackground = Content.Load <Texture2D>("Graphics\\GameArea");
            font           = Content.Load <SpriteFont>("Graphics\\Font");

            // Managers
            MonsterManager.LoadContent();
            SpellManager.LoadContent();
            SoundManager.LoadContent(Content);
            TextManager.LoadContent(Content, font);
            TeamManager.LoadContent();
            StatusSpriteManager.LoadContent(Content);
            MagicSpriteManager.LoadContent(Content);

            // Populate the scenes with random monsters
            PopulateScenes();

            // Threading
            combatThread.Start();
        }
Пример #4
0
        /////////////
        // Helpers //
        /////////////

        /// <summary>
        /// Setup the two teams and battle scenes for the next battle
        /// </summary>
        private void PopulateScenes()
        {
            // Cleanup scenes
            sceneOne.ClearScene();
            sceneTwo.ClearScene();

            // Set the background image randomly
            string bgstr = bgs[Globals.rnd.Next(bgs.Length)];

            bg1 = Content.Load <Texture2D>("Graphics\\Backdrops\\" + bgstr);
            bg2 = Content.Load <Texture2D>("Graphics\\Backdrops\\" + bgstr);

            // Team one is always a pre-defined team
            teamOne = TeamManager.GetRandomTeam();
            sceneOne.PopulateScene(teamOne.TeamString, Content);
            TextManager.SetTeamName(1, teamOne.TeamName);

            // Sometimes pick a pre-defined team for scene two, but usually just generate one
            if (Globals.rnd.Next(100) < 20)
            {
                // Don't pit a team against itself
                do
                {
                    teamTwo = TeamManager.GetRandomTeam();
                }while (teamOne.TeamIndex == teamTwo.TeamIndex);
            }
            else
            {
                // Grab the "random" team and overwrite its team string
                teamTwo            = TeamManager.GetTeamByIndex(0);
                teamTwo.TeamString = GenerateRandomSceneString();
            }

            sceneTwo.PopulateScene(teamTwo.TeamString, Content);
            TextManager.SetTeamName(2, teamTwo.TeamName);
        }
Пример #5
0
        /// <summary>
        /// Write results of the battle and update team data
        /// </summary>
        private void WriteBattleResults()
        {
            // Build the match results string and save it
            // Example results string: "1,9,31,C;Emperor_2,B;BigHorn-Mantis-Icicle-VmpGirl-Gigas"
            int winner = sceneOne.HasLivingMonsters() ? 1 : 2;

            if (round >= ROUND_LIMIT)
            {
                winner = 0;
            }

            // Build and save the match results
            string matchResults = winner.ToString() + "," + round.ToString() + "," + turnTotal.ToString() + "," + sceneOne.SceneString + "," + sceneTwo.SceneString;

            using (StreamWriter file = new StreamWriter(RESULTS_PATH, true))
                file.WriteLine(matchResults);

            // Write battle results to db
            var db = DBConnection.Instance();

            db.DatabaseName = "ff2_monster_sim";
            db.Password     = Environment.GetEnvironmentVariable("FFSIM_MYSQL_PASSWORD", EnvironmentVariableTarget.User);
            if (db.IsConnected())
            {
                MySqlConnection conn = db.Connection;

                string sql = "INSERT INTO battle_results (winning_team, num_of_rounds, num_of_turns, team_one_string, team_two_string, entry_date) " +
                             "VALUES (@winning_team, @num_of_rounds, @num_of_turns, @team_one_string, @team_two_string, @entry_date);";

                MySqlCommand cmd = new MySqlCommand(sql, conn);
                cmd.Parameters.AddWithValue("@winning_team", winner);
                cmd.Parameters.AddWithValue("@num_of_rounds", round);
                cmd.Parameters.AddWithValue("@num_of_turns", turnTotal);
                cmd.Parameters.AddWithValue("@team_one_string", sceneOne.SceneString);
                cmd.Parameters.AddWithValue("@team_two_string", sceneTwo.SceneString);
                cmd.Parameters.AddWithValue("@entry_date", DateTime.Now);
                cmd.ExecuteNonQuery();
            }
            else
            {
                Debug.Write("Unable to connect to the database. Results written to local text file");
            }

            // Update team data
            // Wtf is this?
            int winStateOne, winStateTwo;

            if (winner == 0)
            {
                winStateOne = winStateTwo = 2;
            }
            else if (winner == 1)
            {
                winStateOne = 1;
                winStateTwo = 0;
            }
            else
            {
                winStateOne = 0;
                winStateTwo = 1;
            }
            TeamManager.UpdateTeamData(teamOne, round, winStateOne);
            TeamManager.UpdateTeamData(teamTwo, round, winStateTwo);
            TeamManager.WriteTeamData();
        }