Exemplo n.º 1
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;
            }
            // this if will be replaced in the future
            if (code == 3001)
            {
                mapMatrix.Shop.Run();
            }
            //
            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");
                    }
                    else
                    {
                        parentPage.IgnoreNextKey = false;
                    }
                }
                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);
            }
        }