コード例 #1
0
        /// <summary>
        /// Start a new autobattle round and returns round result to BattleEngine
        /// </summary>
        /// <returns></returns>
        public RoundEnum StartRoundAuto()
        {
            // Turn fight loop, go until monsters or characters are dead
            while (RoundResult.Equals(RoundEnum.NextTurn))
            {
                // Fight still going

                // See whose turn it is
                CurrentPlayer = GetNextPlayerTurn();

                // Select turn choice (move, attack, skill)
                var choice = TurnChoice();

                // Do the turn with the current player
                TakeTurn(choice);

                // Check the round result
                RoundResult = GetRoundState();
            }


            Referee.BattleScore.RoundCount++;
            if (Referee.BattleScore.RoundCount > 100)
            {
                return(RoundEnum.GameOver);
            }

            // Round is over, return result to BattleEngine
            return(RoundResult);
        }
コード例 #2
0
        public ManualBattlePage(BattleEngine lastBattleEngine, RoundEnum lastRoundResult)
        {
            myBattleEngine = lastBattleEngine;
            BindingContext = myBattleEngine;
            RoundResult    = lastRoundResult;

            InitializeComponent();
        }
コード例 #3
0
        public ManualBattlePage()
        {
            myBattleEngine = new BattleEngine();
            BattleEngineInit();
            BindingContext = myBattleEngine;
            RoundResult    = RoundEnum.Unknown;

            InitializeComponent();
        }
コード例 #4
0
        /// <summary>
        /// Process attack from BattlePage
        /// </summary>
        public void AttackClicked()
        {
            // Auto select target
            Target = SelectMonsterToAttack();

            // Do the turn
            TakeTurn(TurnChoiceEnum.Attack);

            // Update round state
            RoundResult = GetRoundState();
        }
コード例 #5
0
        public void NewRoundPage_SetBattleStateEnum_RoundEnum_Unknown_Should_Pass()
        {
            // Arrange
            RoundEnum roundCondition = RoundEnum.Unknown;
            var       save           = BattleEngineViewModel.Instance.Engine.EngineSettings.BattleStateEnum;

            //Act
            page.SetBattleStateEnum(roundCondition);

            //Assert
            Assert.AreEqual(BattleStateEnum.Unknown, BattleEngineViewModel.Instance.Engine.EngineSettings.BattleStateEnum);

            //Reset - need to reset here to test the battlestateenum in engine view model.
            BattleEngineViewModel.Instance.Engine.EngineSettings.BattleStateEnum = save;
        }
コード例 #6
0
        public void BattlePageTwo_SetBattleStateEnum_RoundEnum_GraduationCeremony_Should_Pass()
        {
            // Arrange
            RoundEnum roundCondition = RoundEnum.GraduationCeremony;
            var       save           = BattleEngineViewModel.Instance.Engine.EngineSettings.BattleStateEnum;

            //Act
            page.SetBattleStateEnum(roundCondition);

            //Assert
            Assert.AreEqual(BattleStateEnum.GameOver, BattleEngineViewModel.Instance.Engine.EngineSettings.BattleStateEnum);

            //Reset - need to reset here to test the battlestateenum in engine view model.
            BattleEngineViewModel.Instance.Engine.EngineSettings.BattleStateEnum = save;
        }
コード例 #7
0
        // Call to make a new set of monsters...
        public void NewRound()
        {
            // End the existing round
            EndRound();

            // Populate New Monsters...
            AddMonstersToRound();

            // Make the PlayerList
            MakePlayerList();

            // Update Score for the RoundCount
            BattleScore.RoundCount++;
            RoundStateEnum = RoundEnum.NextTurn;
        }
コード例 #8
0
        // Get Round Turn Order

        // Rember Who's Turn


        // RoundNextTurn which uses PlayerCurrent as tracking which player
        public RoundEnum RoundNextTurn()
        {
            // No characters, game is over because game ends when characters die
            if (CharacterList.Count < 1)
            {
                // Game Over and exit do while loop from auto battle engine
                RoundStateEnum = RoundEnum.GameOver;
                return(RoundEnum.GameOver);
            }

            // Check if round is over when monsters are killed
            if (MonsterList.Count < 1)
            {
                // If over, New Round which loops back to main auto battle engine
                RoundStateEnum = RoundEnum.NewRound;
                return(RoundEnum.NewRound);
            }


            // Player current is the next players turn which is decided by recalculating the order
            // through making a list based on attributes starting with speed, level, etc
            // Then parse through the list to get the next players turn
            PlayerCurrent = GetNextPlayerTurn();

            // Decide Who to Attack
            if (PlayerCurrent.PlayerType == PlayerTypeEnum.Character)
            {
                // Get the player
                var myPlayer = CharacterList.Where(a => a.Guid == PlayerCurrent.Guid).FirstOrDefault();

                // Do the turn by going to the turn engine and either having monster or character attack
                TakeTurn(myPlayer);
            }
            // Add Monster turn here...
            else if (PlayerCurrent.PlayerType == PlayerTypeEnum.Monster)
            {
                // Get the player
                var myPlayer = MonsterList.Where(a => a.Guid == PlayerCurrent.Guid).FirstOrDefault();

                // Do the turn....
                TakeTurn(myPlayer);
            }

            RoundStateEnum = RoundEnum.NextTurn;
            return(RoundEnum.NextTurn);
        }
コード例 #9
0
        // Get Round Turn Order

        // Rember Who's Turn

        // RoundNextTurn
        public RoundEnum RoundNextTurn()
        {
            // No characters, game is over...
            if (CharacterList.Count < 1)
            {
                // Game Over
                RoundStateEnum = RoundEnum.GameOver;
                return(RoundStateEnum);
            }

            // Check if round is over
            if (MonsterList.Count < 1)
            {
                // If over, New Round
                RoundStateEnum = RoundEnum.NewRound;
                return(RoundEnum.NewRound);
            }

            // Decide Who gets next turn
            // Remember who just went...
            PlayerCurrent = GetNextPlayerTurn();

            // Decide Who to Attack
            // Do the Turn
            if (PlayerCurrent.PlayerType == PlayerTypeEnum.Character)
            {
                // Get the player
                var myPlayer = CharacterList.Where(a => a.Guid == PlayerCurrent.Guid).FirstOrDefault();

                // Do the turn....
                TakeTurn(myPlayer);
            }
            // Add Monster turn here...
            else if (PlayerCurrent.PlayerType == PlayerTypeEnum.Monster)
            {
                // Get the player
                var myPlayer = MonsterList.Where(a => a.Guid == PlayerCurrent.Guid).FirstOrDefault();

                // Do the turn....
                TakeTurn(myPlayer);
            }

            RoundStateEnum = RoundEnum.NextTurn;
            return(RoundStateEnum);
        }
コード例 #10
0
        /// <summary>
        /// Sets the battle state enum depending on the RoundCOndition
        /// </summary>
        /// <param name="RoundCondition"></param>
        /// <returns></returns>
        public bool SetBattleStateEnum(RoundEnum RoundCondition)
        {
            switch (RoundCondition)
            {
            case RoundEnum.GameOver:
            case RoundEnum.GraduationCeremony:
                BattleEngineViewModel.Instance.Engine.EngineSettings.BattleStateEnum = BattleStateEnum.GameOver;
                break;

            case RoundEnum.NewRound:
                BattleEngineViewModel.Instance.Engine.EngineSettings.BattleStateEnum = BattleStateEnum.NewRound;
                break;

            case RoundEnum.NextTurn:
                BattleEngineViewModel.Instance.Engine.EngineSettings.BattleStateEnum = BattleStateEnum.Battling;
                break;

            default:
                BattleEngineViewModel.Instance.Engine.EngineSettings.BattleStateEnum = BattleStateEnum.Unknown;
                break;
            }
            return(true);
        }
コード例 #11
0
        // If UI is enabled, there will be popups that guide you through battle as you click the next turn button
        // If not, it will drop you straight to the result page
        public async void BattleEngineStart_Command(object sender, EventArgs e)
        {
#if !EnableUI
            do
            {
                // If the round is over start a new one...
                if (RoundResult == RoundEnum.NewRound)
                {
                    myBattleEngine.NewRound();
                }

                PlayerInfo currentPlayer = myBattleEngine.GetNextPlayerInList();

                // Check if character or monster
                if (currentPlayer.PlayerType == PlayerTypeEnum.Character)
                {
                    string id = null;
                    RoundResult = myBattleEngine.RoundNextTurn(id);
                }

                // else monster turn
                else
                {
                    RoundResult = myBattleEngine.RoundNextTurn();
                }

                Debug.WriteLine(myBattleEngine.TurnMessage);
            } while (RoundResult != RoundEnum.GameOver);
#endif

#if EnableUI
            if (RoundResult != RoundEnum.GameOver)
            {
                // If the round is over start a new one...
                if (RoundResult == RoundEnum.NewRound)
                {
                    myBattleEngine.NewRound();

                    var answer = await DisplayAlert("New Round", "Begin", "Start", "Cancel");

                    if (answer)
                    {
                        await Navigation.PushAsync(new ManualBattlePage(myBattleEngine, RoundResult));

                        return;
                    }
                }

                PlayerInfo currentPlayer = myBattleEngine.GetNextPlayerInList();

                // Check if character or monster
                if (currentPlayer.PlayerType == PlayerTypeEnum.Character)
                {
                    string id = null;

                    var dataset = myBattleEngine.MonsterList.Where(a => a.Alive).ToList();

                    string[] names = new string[dataset.Count];
                    string[] IDs   = new string[dataset.Count];

                    int ctr = 0;

                    foreach (var data in dataset)
                    {
                        names[ctr] = data.Name;
                        IDs[ctr]   = data.Guid;
                        ctr++;
                    }

                    var action = await DisplayActionSheet("Select Monster", null, null, names);

                    ctr = 0;

                    foreach (var data in dataset)
                    {
                        if (action == data.Name)
                        {
                            id = IDs[ctr];
                            break;
                        }

                        ctr++;
                    }

                    RoundResult = myBattleEngine.RoundNextTurn(id);
                }

                // else monster turn
                else
                {
                    RoundResult = myBattleEngine.RoundNextTurn();
                }


                var response = await DisplayAlert("Turn Result", myBattleEngine.TurnMessage, "Continue", "Quit");

                if (!response)
                {
                    await Navigation.PushAsync(new OpeningPage());
                }
            }
#endif

            if (RoundResult == RoundEnum.GameOver)
            {
                myBattleEngine.EndBattle();

                string result =
                    "Battle Ended" +
                    " Total Experience :" + myBattleEngine.BattleScore.ExperienceGainedTotal +
                    " Rounds :" + myBattleEngine.BattleScore.RoundCount +
                    " Turns :" + myBattleEngine.BattleScore.TurnCount +
                    " Monster Kills :" + myBattleEngine.BattleScore.MonstersKilledList;

                var answer = await DisplayAlert("Game Result", result, "Set Name", "Restart");

                if (answer)
                {
                    // Link to enter name
                    await Navigation.PushAsync(new EditScorePage(new ScoreDetailViewModel(myBattleEngine.BattleScore)));
                }

                else
                {
                    await Navigation.PushAsync(new OpeningPage());
                }
            }
        }
コード例 #12
0
        // Get Round Turn Order

        // Rember Who's Turn

        // RoundNextTurn
        public RoundEnum RoundNextTurn()
        {
            // No characters, game is over...
            if (CharacterList.Count < 1)
            {
                // Game Over
                RoundStateEnum = RoundEnum.GameOver;
                return(RoundStateEnum);
            }

            // Check if round is over
            if (MonsterList.Count < 1)
            {
                // If over, New Round
                RoundStateEnum = RoundEnum.NewRound;
                return(RoundEnum.NewRound);
            }

            // Decide Who gets next turn
            // Remember who just went...
            //if autobattle, do everything automatically
            if (BattleScore.AutoBattle)
            {
                // Decide Who to Attack
                // Do the Turn
                if (PlayerCurrent.PlayerType == PlayerTypeEnum.Character)
                {
                    // Get the player
                    var myPlayer = CharacterList.Where(a => a.Guid == PlayerCurrent.Guid && a.Name == PlayerCurrent.Name).FirstOrDefault();

                    // Do the turn....
                    TakeTurn(myPlayer);
                }
                // Add Monster turn here...
                else if (PlayerCurrent.PlayerType == PlayerTypeEnum.Monster)
                {
                    // Get the player
                    var myPlayer = MonsterList.Where(a => a.Guid == PlayerCurrent.Guid && a.Name == PlayerCurrent.Name).FirstOrDefault();
                    Debug.WriteLine("Player after selected from list: " + myPlayer.Name);
                    // Do the turn....
                    TakeTurn(myPlayer);
                }
            }

            //if move is rest or use item, DO NOT DO ATTACK

            if (TurnType == MoveEnum.Attack)
            {
                // Decide Who to Attack
                // Do the Turn
                if (PlayerCurrent.PlayerType == PlayerTypeEnum.Character)
                {
                    // Get the player
                    var myPlayer = CharacterList.Where(a => a.Guid == PlayerCurrent.Guid && a.Name == PlayerCurrent.Name).FirstOrDefault();

                    // Do the turn....
                    TakeTurn(myPlayer);
                }
                // Add Monster turn here...
                else if (PlayerCurrent.PlayerType == PlayerTypeEnum.Monster)
                {
                    // Get the player
                    var myPlayer = MonsterList.Where(a => a.Guid == PlayerCurrent.Guid && a.Name == PlayerCurrent.Name).FirstOrDefault();
                    Debug.WriteLine("Player after selected from list: " + myPlayer.Name);
                    // Do the turn....
                    TakeTurn(myPlayer);
                }

                //check to see again if game is over

                // No characters, game is over...
                if (CharacterList.Count < 1)
                {
                    // Game Over
                    RoundStateEnum = RoundEnum.GameOver;
                    return(RoundStateEnum);
                }

                // Check if round is over
                if (MonsterList.Count < 1)
                {
                    // If over, New Round
                    RoundStateEnum = RoundEnum.NewRound;
                    return(RoundEnum.NewRound);
                }
                PlayerCurrent = GetNextPlayerTurn();
                Debug.WriteLine("\n\nPlayer current new just chosen backend for next turn: " + PlayerCurrent.Name);
                RoundStateEnum = RoundEnum.NextTurn;
                return(RoundStateEnum);
            }
            else
            {
                //move to next turn, but do not attack, if character
                //if monster, always attack
                if (PlayerCurrent.PlayerType == PlayerTypeEnum.Monster)
                {
                    // Get the player

                    var myPlayer = MonsterList.Where(a => a.Guid == PlayerCurrent.Guid && a.Name == PlayerCurrent.Name).FirstOrDefault();
                    Debug.WriteLine("Player after selected from list: " + myPlayer.Name);
                    // Do the turn....
                    TakeTurn(myPlayer);
                }
                else if (PlayerCurrent.PlayerType == PlayerTypeEnum.Character)
                {
                    //get character
                    var myPlayer = CharacterList.Where(a => a.Guid == PlayerCurrent.Guid && a.Name == PlayerCurrent.Name).FirstOrDefault();

                    //increment turn count manually since you're not calling TakeTurn anymore
                    BattleScore.TurnCount++;
                }

                //check again to see if round over
                // No characters, game is over...
                if (CharacterList.Count < 1)
                {
                    // Game Over
                    RoundStateEnum = RoundEnum.GameOver;
                    return(RoundStateEnum);
                }

                // Check if round is over
                if (MonsterList.Count < 1)
                {
                    // If over, New Round
                    RoundStateEnum = RoundEnum.NewRound;
                    return(RoundEnum.NewRound);
                }
                PlayerCurrent = GetNextPlayerTurn();
                Debug.WriteLine("\n\nPlayer current new just chosen backend for next turn: " + PlayerCurrent.Name);
                RoundStateEnum = RoundEnum.NextTurn;
                return(RoundStateEnum);
            }
        }
コード例 #13
0
ファイル: RoundEngine.cs プロジェクト: loleeta/TRP
        // Get Round Turn Order
        // Rember Who's Turn
        // Starts next turn during round
        public RoundEnum RoundNextTurn()
        {
            // Debug statements
            Debug.WriteLine("Starting RoundEngine...");
            Debug.WriteLine("From Round Engine: " + RoundStateEnum);

            // No charaacters, game is over...
            if (CharacterList.Count < 1)
            {
                RoundStateEnum = RoundEnum.GameOver;
                return(RoundStateEnum);
            }

            // Check if round is over
            if (MonsterList.Count < 1)
            {
                // If over, New Round
                RoundStateEnum = RoundEnum.NewRound;
                return(RoundStateEnum);
            }

            // Decide Who gets next turn
            PlayerCurrent = GetNextPlayerInList();

            // Debug output of the next players name
            Debug.WriteLine(PlayerCurrent.Name);

            // Decide Who to Attack
            //Do the turn as a character
            if (PlayerCurrent.PlayerType == PlayerTypeEnum.Character)
            {
                // Get the current character for consumables
                CurrentCharacter = PlayerCharacter(PlayerCurrent);
                Debug.WriteLine("It's a Character!");

                // Get the player
                var myPlayer = CharacterList.Where(a => a.Guid == PlayerCurrent.Guid).FirstOrDefault();

                // Remove player from player list if null or dead
                if (myPlayer == null || !myPlayer.Alive)
                {
                    PlayerList.Remove(PlayerCurrent);

                    // Restart the turn
                    RoundNextTurn();
                }

                // Do the turn...
                TakeTurn(myPlayer);
            }
            // Monsters turn
            else if (PlayerCurrent.PlayerType == PlayerTypeEnum.Monster)
            {
                // Get the monster
                var myPlayer = MonsterList.Where(a => a.Guid == PlayerCurrent.Guid).FirstOrDefault();

                // If monster is dead or null remove it from the player list and restart round
                if (myPlayer == null || !myPlayer.Alive)
                {
                    // Remove
                    PlayerList.Remove(PlayerCurrent);

                    // Restart
                    RoundNextTurn();
                }

                // Do the turn...
                TakeTurn(myPlayer);
            }

            // Update the roundstatenum to next turn
            RoundStateEnum = RoundEnum.NextTurn;

            // Return the enum
            return(RoundStateEnum);
        }