コード例 #1
0
 /***************************        FIGHTS      ***************************/
 public bool FightRandomMonster(bool possibleToEscape = false)
 {
     // player will fight against a random monster
     // returns battle result (true = victory)
     // xp can be gained here, but gold/items cannot (you can do this separately inside your interaction)
     // unlike fights with wild monsters, in this fight it is impossible to run away by default
     // if you want to make it possible to run away, provide the optional argument and set it to true
     try
     {
         Monster monster = Index.RandomMonsterFactory().Clone().Create();
         if (monster != null)
         {
             Display.BattleScene newBattleScene = new Display.BattleScene(parentPage, this, CurrentPlayer, monster);
             Battle newBattle = new Battle(this, newBattleScene, monster, false, possibleToEscape);
             newBattle.Run();
             if (newBattle.battleResult)
             {
                 UpdateStat(7, monster.XPValue);
             }
             return(newBattle.battleResult);
         }
     }
     catch (IndexOutOfRangeException e)
     {
         parentPage.AddConsoleText("Podjeto nieudana probe wygenerowania potwora. Czy klasa Index zostala zaktualizowana?");
         parentPage.AddConsoleText(e.Message);
     }
     return(false);
 }
コード例 #2
0
 public void FightThisMonster(Monster monster)
 {
     // player will fight against a particular monster
     // xp can be gained here, but gold/items cannot (you can do this separately inside your interaction)
     if (monster != null)
     {
         Display.BattleScene newBattleScene = new Display.BattleScene(parentPage, currentPlayer, monster);
         Battle newBattle = new Battle(this, newBattleScene, monster, false);
         newBattle.Run();
         if (newBattle.battleResult)
         {
             UpdateStat(7, monster.XPValue);
         }
     }
 }
コード例 #3
0
 public bool FightThisMonster(Monster monster, bool possibleToEscape = false)
 {
     // player will fight against a particular monster
     // returns battle result (true = victory)
     // xp can be gained here, but gold/items cannot (you can do this separately inside your interaction)
     // unlike fights with wild monsters, in this fight it is impossible to run away by default
     // if you want to make it possible to run away, provide the optional second argument and set it to true
     if (monster != null)
     {
         Display.BattleScene newBattleScene = new Display.BattleScene(parentPage, this, CurrentPlayer, monster);
         Battle newBattle = new Battle(this, newBattleScene, monster, false, possibleToEscape);
         newBattle.Run();
         if (newBattle.battleResult)
         {
             UpdateStat(7, monster.XPValue);
         }
         return(newBattle.battleResult);
     }
     return(true);
 }
コード例 #4
0
 /***************************        FIGHTS      ***************************/
 public void FightRandomMonster()
 {
     // player will fight against a random monster
     // xp can be gained here, but gold/items cannot (you can do this separately inside your interaction)
     try
     {
         Monster monster = Index.RandomMonsterFactory().Clone().Create(currentPlayer.Level);
         if (monster != null)
         {
             Display.BattleScene newBattleScene = new Display.BattleScene(parentPage, currentPlayer, monster);
             Battle newBattle = new Battle(this, newBattleScene, monster, false);
             newBattle.Run();
             if (newBattle.battleResult)
             {
                 UpdateStat(7, monster.XPValue);
             }
         }
     }
     catch (IndexOutOfRangeException e)
     {
         parentPage.AddConsoleText("An attempt was made to create a monster but something went wrong. Did you remember to update the Index class?");
         parentPage.AddConsoleText(e.Message);
     }
 }
コード例 #5
0
        private void LocationEvents(int code)
        {
            // events and interactions that happen at special map locations

            /* Note: there is a weird display issue where KeyDown event fires twice when a game interaction occurs
             * I have made several attempts to trace it, but it remains elusive
             * The internet offers contradictory opinions, some people claim it's caused by an underlying WPF bug
             * In any case, IgnoreNextKey serves as a workaround
             * Be careful, though, since it means the movement will not be smooth around interactions by default
             * If you want smooth movement for some specific interaction, you need to overwrite IgnoreNextKey inside the relevant if-clause
             * Update: it seems the above is true only for Interactions with Enterable set to true
             * I'm going to experimentally remove IgnoreNextKey trigger for Enterable = false
             */
            if (code > 1)
            {
                parentPage.IgnoreNextKey = true;
            }
            //
            if (code == 1000)
            {
                try
                {
                    Monster monster = mapMatrix.CreateMonster(playerPosLeft, playerPosTop, currentPlayer.Level);
                    if (monster != null)
                    {
                        BattleScene newBattleScene = new BattleScene(parentPage, this, currentPlayer, monster);
                        Battle      newBattle      = new Battle(this, newBattleScene, monster);
                        newBattle.Run();
                        if (newBattle.battleResult)
                        {
                            mapMatrix.MemorizedMonsters[mapMatrix.Width * PlayerPosTop + PlayerPosLeft] = null; // this monster was defeated
                            parentPage.UpdateMonster(mapMatrix.Width * PlayerPosTop + PlayerPosLeft, mapMatrix.HintMonsterImage(playerPosLeft, playerPosTop), mapMatrix.Width);
                            // restore position from before the battle
                            parentPage.MovePlayer("reverse");
                            UpdateStat(7, monster.XPValue);
                        }
                        else
                        {
                            // restore position from before the battle
                            mapMatrix.MemorizedMonsters[mapMatrix.Width * PlayerPosTop + PlayerPosLeft] = monster; // remember this monster until the next time
                            parentPage.MovePlayer("reverse");
                        }
                    }
                    else
                    {
                        parentPage.IgnoreNextKey = false;
                    }
                }
                catch (IndexOutOfRangeException e)
                {
                    parentPage.AddConsoleText("Podjeto nieudana probe wygenerowania potwora. Czy klasa Index zostala zaktualizowana?");
                    parentPage.AddConsoleText(e.Message);
                }
            }
            else if (code >= 2000 && code < 3000)
            {
                mapMatrix = metaMapMatrix.GetCurrentMatrix(code - 2000);
                InitializeMapDisplay(metaMapMatrix.GetPreviousMatrixCode() + 2000);
            }
            else if (code > 3000)
            {
                if (!mapMatrix.Interactions[mapMatrix.Width * PlayerPosTop + PlayerPosLeft].Enterable)
                {
                    parentPage.IgnoreNextKey = false;
                }
                mapMatrix.Interactions[mapMatrix.Width * PlayerPosTop + PlayerPosLeft].Run();
                if (mapMatrix.Interactions[mapMatrix.Width * PlayerPosTop + PlayerPosLeft].Enterable == false)
                {
                    parentPage.MovePlayer("reverse");
                }
                if (CurrentlyComplete >= 100)
                {
                    parentPage.AddConsoleText("\n");
                    parentPage.AddConsoleColorText("Gratulacje! Quest zostal ukonczony. Mozesz zakonczyc gre w tym miejscu lub kontynuowac rozgrywke, jezeli masz na to ochote.", "blue");
                    parentPage.AddConsoleText("\n");
                }
            }
        }
コード例 #6
0
        private void LocationEvents(int code)
        {
            // events and interactions that happen at special map locations

            /* Note: there is a weird display issue where KeyDown event fires twice when a game interaction occurs
             * I have made several attempts to trace it, but it remains elusive
             * The internet offers contradictory opinions, some people claim it's caused by an underlying WPF bug
             * In any case, IgnoreNextKey serves as a workaround
             * Be careful, though, since it means the movement will not be smooth around interactions by default
             * If you want smooth movement for some specific interaction, you need to overwrite IgnoreNextKey inside the relevant if-clause
             */
            if (code > 1)
            {
                parentPage.IgnoreNextKey = true;
            }

            // 2-4 are temporary codes for testing
            if (code == 2)
            {
                IInteraction inter = new ItemSellInteraction(this);
                inter.Run();
            }
            else if (code == 3)
            {
                SendText("\nHere is your magic training and magic staff.");
                currentPlayer.XP += 150;
                ProduceItem("item0001");
            }
            else if (code == 4)
            {
                SendText("Here is your armor.");
                AddRandomClassItem();
            }
            else if (code == 1000)
            {
                try
                {
                    Monster monster = mapMatrix.CreateMonster(playerPosLeft, playerPosTop, currentPlayer.Level);
                    if (monster != null)
                    {
                        BattleScene newBattleScene = new BattleScene(parentPage, currentPlayer, monster);
                        Battle      newBattle      = new Battle(this, newBattleScene, monster);
                        newBattle.Run();
                        if (newBattle.battleResult)
                        {
                            parentPage.UpdateMonster(mapMatrix.Width * PlayerPosTop + PlayerPosLeft, mapMatrix.HintMonsterImage(playerPosLeft, playerPosTop), mapMatrix.Width);
                            UpdateStat(7, monster.XPValue);
                            mapMatrix.stored[mapMatrix.Width * PlayerPosTop + PlayerPosLeft] = null; // this monster was defeated
                        }
                        else
                        {
                            mapMatrix.stored[mapMatrix.Width * PlayerPosTop + PlayerPosLeft] = monster;  // remember this monster until the next time
                        }
                        // restore position from before the battle
                        parentPage.MovePlayer("reverse");
                    }
                }
                catch (IndexOutOfRangeException e)
                {
                    parentPage.AddConsoleText("An attempt was made to create a monster but something went wrong. Did you remember to update the Index class?");
                    parentPage.AddConsoleText(e.Message);
                }
            }
            else if (code >= 2000 && code < 3000)
            {
                mapMatrix = metaMapMatrix.GetCurrentMatrix(code - 2000);
                InitializeMapDisplay(metaMapMatrix.GetPreviousMatrixCode() + 2000);
            }
        }