Beispiel #1
0
 /// <summary>
 /// 选关卡
 /// </summary>
 /// <param name="View"></param>
 public void SelectLevel(LevelView View)
 {
     if (View.data.data.checkpoint <= curChapterData.curLevel[(int)this.curType] && View.data.unlock == true)
     {
         //if (View.data.data.csv_id != UserManager.Instance.curLeveldata.csv_id)
         //{
         curView = View;
         levelpop.SetInfo(curView);
         C2sSprotoType.checkpoint_hanging_choose.request obj = new C2sSprotoType.checkpoint_hanging_choose.request();
         obj.chapter    = curView.data.data.chapter;
         obj.checkpoint = curView.data.data.checkpoint;
         obj.type       = (int)curView.data.data.type;
         obj.csv_id     = curView.data.data.csv_id;
         NetworkManager.Instance.CheckPointChose(obj);
         //}
     }
     //else if (View.data.data.checkpoint == curChapterData.curLevel[(int)this.curType] && View.data.unlock == true)
     //{
     //    curView = View;
     //    levelpop.SetInfo(curView);
     //    C2sSprotoType.checkpoint_hanging_choose.request obj = new C2sSprotoType.checkpoint_hanging_choose.request();
     //    obj.chapter = curView.data.data.chapter;
     //    obj.checkpoint = curView.data.data.checkpoint;
     //    obj.type = (int)curView.data.data.type;
     //    obj.csv_id = curView.data.data.csv_id;
     //    NetworkManager.Instance.CheckPointChose(obj);
     //}
 }
        public Turn Solve(LevelView level, Enviroment enviroment, out bool isAttack)
        {
            isAttack = false;
            //если монстры атакуют более чем двумя или их рядом слишком много - убегаем на другой конец карты
            if ((level.Monsters.Count(m => m.Location.IsInRange(level.Player.Location, 1)) > 1 ||
                 level.Monsters.Count(m => m.Location.IsInRange(level.Player.Location, 3)) > 3) && level.Monsters.Count() > 2)
            {
                enviroment.EnemyMap.Multiplyer = 2;
                var map = Map.Sum(enviroment.TravelMap, enviroment.EnemyMap);

                var spots = GetSaveSpots(level, enviroment);

                Location target = new Location(0, 0);
                foreach (var sp in spots)
                {
                    target = sp.Near().Where(p => enviroment.TravelMap.IsTravaible(p)).OrderBy(p => p.Distance(level.Player.Location)).FirstOr(new Location(-1, -1)); //эта клетка вроде всегда свободна
                    if (target.X >= 0)
                    {
                        break;
                    }
                }

                var solve = ManualStep(map, target, level, enviroment, out isAttack);
                if (solve != null)
                {
                    return(solve);
                }
                return(AutomaticStep(map, target, level, out isAttack));
            }
            return(null);
        }
Beispiel #3
0
 /// <summary>
 /// 换难度
 /// </summary>
 /// <param name="type"></param>
 public void SelectDifficulty(Def.levelType type)
 {
     curType      = type;
     curFousLevel = curChapterData.curLevel[(int)type];
     if (curFousLevel > curChapterData.typeMax[(int)type])
     {
         curFousLevel = curChapterData.typeMax[(int)type];
     }
     levelpop.SetLevelList(GetLevelListByType(type));
     if (UserManager.Instance.curLeveldata == null)//新账号初始化挂机
     {
         curView = levelpop.levelViewList[0];
     }
     else
     {
         if (UserManager.Instance.curLeveldata.chapter != curChapterData.csv_id)
         {
             curView = GetLevelView(curFousLevel);
         }
         else
         {
             curView = GetLevelView(UserManager.Instance.curLeveldata.checkpoint);
         }
     }
     SelectLevel(curView);
 }
Beispiel #4
0
        public static List <Location> FindShortestPath(LevelView levelView, Location from, Func <Location, bool> isTarget)
        {
            var queue = new Queue <Location>();

            queue.Enqueue(from);
            var previous = new Dictionary <Location, Location> {
                [from] = default(Location)
            };

            while (queue.Any())
            {
                var currentLocation = queue.Dequeue();
                var nextLocations   = GetAdjacentLocations(currentLocation, levelView)
                                      .Where(l => IsPassable(l, levelView) || isTarget(l))
                                      .Where(l => !previous.ContainsKey(l));

                foreach (var nextLocation in nextLocations)
                {
                    previous[nextLocation] = currentLocation;
                    queue.Enqueue(nextLocation);

                    if (isTarget(nextLocation))
                    {
                        return(CreatePath(from, nextLocation, previous));
                    }
                }
            }
            return(null);
        }
Beispiel #5
0
 private static bool IsLocationForAttack(LevelView levelView, Location location)
 {
     return(GetCountMonstersOnAttackRange(levelView, location) > 0 &&
            levelView.Field[location] != CellType.Wall &&
            levelView.Field[location] != CellType.Trap &&
            !levelView.GetItemAt(location).HasValue);
 }
Beispiel #6
0
 public LevelScreen(ScreenManager screens, InputBindings bindings, SoundEffects soundEffects, LevelView levelView)
 {
     _screens      = screens;
     _bindings     = bindings;
     _soundEffects = soundEffects;
     _levelView    = levelView;
 }
Beispiel #7
0
        public BadObjectMap(LevelView level, Func <LevelView, Location, bool> isObject, Func <LevelView, IEnumerable <Location> > getObjects, int radius = 4) : base(level.Field.Width, level.Field.Height)
        {
            var objects = getObjects(level).ToList();

            for (int x = 0; x < Width; x++)
            {
                for (int y = 0; y < Height; y++)
                {
                    travable[x, y] = true;
                }
            }
            foreach (var o in objects)
            {
                travable[o.X, o.Y] = false;
                for (int x = -radius; x <= radius; x++)
                {
                    for (int y = -radius; y <= radius; y++)
                    {
                        var loc = o + new Offset(x, y);
                        var d   = loc.Distance(o);
                        if (loc.X >= 0 && loc.X < Width && loc.Y >= 0 && loc.Y < Height && d < radius)
                        {
                            var newW = radius - d;
                            weigthes[loc.X, loc.Y] = Math.Max(weigthes[loc.X, loc.Y], newW);
                        }
                    }
                }
            }
        }
    void InitLevel(string[] rows)
    {
        GameFieldModel fieldModel  = new GameFieldModel(rows);
        PlayerModel    playerModel = new PlayerModel(new FieldBounds(fieldModel.Width, fieldModel.Height),
                                                     TileUtility.GetTiles(TileType.Body, fieldModel.Tiles));

        GameFieldView fieldView  = gameField.GetComponent <GameFieldView> ();
        Player        playerView = player.GetComponent <Player> ();

        PlayerController    playerController    = new PlayerController(playerModel, playerView);
        GameFieldController gameFieldController = new GameFieldController(fieldModel, fieldView);

        LevelModel levelModel = new LevelModel();
        LevelView  levelView  = GetComponent <LevelView> ();

        StepTimer           tickTimer       = GetComponent <StepTimer> ();
        StepTimerController timerController = new StepTimerController(levelModel, playerView, tickTimer);

        StatusPanelView       statusView            = statusPanel.GetComponent <StatusPanelView> ();
        StatusPanelController statusPanelController = new StatusPanelController(levelModel, statusView);

        SpawnController spawnController = new SpawnController(fieldModel, playerModel);

        LevelController levelController = new LevelController(playerModel, fieldModel, levelModel, levelView, tickTimer);
    }
Beispiel #9
0
            public override Turn MakeTurn(LevelView levelView)
            {
                if ((Bot.Health < panicHealth) && levelView.HealthPacks.Any())
                {
                    GoToState(() => new StateHeal(Bot));
                    return(Bot.State.MakeTurn(levelView));
                }
                if ((Bot.Health > panicHealth) && levelView.Monsters.Any())
                {
                    GoToState(() => new StateAttack(Bot));
                    return(Bot.State.MakeTurn(levelView));
                }
                if (!levelView.Monsters.Any() && !Bot.HasItem)
                {
                    GoToState(() => new StateEquip(Bot));
                    return(Bot.State.MakeTurn(levelView));
                }

                if (!levelView.Monsters.Any() && Bot.Health != maxHealth && levelView.HealthPacks.Any())
                {
                    GoToState(() => new StateHeal(Bot));
                    return(Bot.State.MakeTurn(levelView));
                }
                var exitLocation = levelView.Field.GetCellsOfType(CellType.Exit).FirstOrDefault();
                var path         = Algorithm.BFS(levelView, location => location == exitLocation);

                return(NextStep(levelView, path));
            }
        void IEventListenerSystem <StartGameEvent> .OnEvent(StartGameEvent contextEvent)
        {
            var levelGameObject = _resourceProvider.GetResourceView <LevelView>().gameObject;

            _level = context.CreateView <LevelView>(levelGameObject);
            _level.GetViews <View>().ForEach(_ => _.Initialize(context));
        }
Beispiel #11
0
            public override Turn MakeTurn(LevelView levelView)
            {
                if (Bot.Health < panicHealth && levelView.HealthPacks.Any())
                {
                    GoToState(() => new StateHeal(Bot));
                    return(Bot.State.MakeTurn(levelView));
                }
                if (!levelView.Monsters.Any())
                {
                    GoToState(() => new StateIdle(Bot));
                    return(Bot.State.MakeTurn(levelView));
                }
                var nearbyMonster = levelView.Monsters.
                                    OrderBy(m => (m.Location - Bot.Location).Size()).
                                    ThenBy(m => m.Health).
                                    FirstOrDefault();

                if (nearbyMonster.HasValue && IsInAttackRange(Bot.Location, nearbyMonster.Location))
                {
                    return(Turn.Attack(nearbyMonster.Location - Bot.Location));
                }

                var path = Algorithm.BFS(levelView, location => location == nearbyMonster.Location);

                return(NextStep(levelView, path));
            }
Beispiel #12
0
 public void UpdateInfo(LevelView levelView)
 {
     Health   = levelView.Player.Health;
     Defence  = levelView.Player.Defence;
     Attack   = levelView.Player.Attack;
     Location = levelView.Player.Location;
 }
Beispiel #13
0
        private static Turn ExecuteFight(LevelView levelView)
        {
            var monsterInAttackRange = levelView.Monsters.First(m => levelView.Player.Location.IsInRange(m.Location, 1));
            var attackOffset         = monsterInAttackRange.Location - levelView.Player.Location;

            return(Turn.Attack(attackOffset));
        }
Beispiel #14
0
            public override Turn MakeTurn(LevelView levelView)
            {
                if (!levelView.Monsters.Any())
                {
                    var      items    = levelView.Items.OrderByDescending(GetItemValue);
                    var      bestItem = items.First();
                    ItemView currentItem;
                    levelView.Player.TryGetEquippedItem(out currentItem);
                    if (GetItemValue(currentItem) < GetItemValue(bestItem))
                    {
                        var pathToBestItem = Algorithm.BFS(levelView, location => location == bestItem.Location, true);
                        return(Turn.Step(pathToBestItem.First() - levelView.Player.Location));
                    }
                    Bot.HasItem = true;
                    GoToState(() => new StateIdle(Bot));
                    return(Bot.State.MakeTurn(levelView));
                }

                var nearestItem =
                    levelView.Items.OrderBy(i => (i.Location - levelView.Player.Location).Size())
                    .FirstOrDefault();
                var nearestMonster =
                    levelView.Monsters.OrderBy(i => (i.Location - levelView.Player.Location).Size())
                    .FirstOrDefault();

                if ((nearestItem.Location - Bot.Location).Size() < (nearestMonster.Location - Bot.Location).Size())
                {
                    GoToState(() => new StateIdle(Bot));
                    return(Bot.State.MakeTurn(levelView));
                }
                var path = Algorithm.BFS(levelView, location => location == nearestItem.Location);

                return(NextStep(levelView, path));
            }
    //private LevelView2 view2

    void Start()
    {
        //Text File Class
        textFile = new LevelLayoutFromTextFile();
        textFile.ReadTextFile();

        //model
        model = new LevelModel(18);

        // Controller

        /*
         * controller = new LevelController();
         * controller.SetModel(model);
         * controller.SetView(view);
         */

        inputController = new InputController();
        inputController.SetModel(model);

        // View
        view = new LevelView();
        // view.SetModel(model);
        view.SetTextFile(textFile);
        // view.Refresh();
        // view.UpdateTextDisplay(z);
    }
Beispiel #16
0
        private Turn Fight(LevelView levelView)
        {
            endFightHealthLimit = levelView.Monsters.Count() == 1 ? LowHealthLimit : HighHealthLimit;

            if (levelView.Player.Health < endFightHealthLimit && levelView.HealthPacks.Any())
            {
                automaton.PushAction(CollectHealth);
                return(automaton.CurrentAction.Invoke(levelView));
            }
            if (!levelView.Monsters.Any())
            {
                automaton.PopAction();
                automaton.PushAction(MoveToExit);
                return(automaton.CurrentAction.Invoke(levelView));
            }

            if (GetCountMonstersOnAttackRange(levelView, levelView.Player.Location) == 0) // all monsters on long distance
            {
                automaton.PushAction(FindMonster);
                return(automaton.CurrentAction.Invoke(levelView));
            }

            if (levelView.Monsters.Count() == 1 && !hasBestItem)
            {
                automaton.PushAction(Equip);
                return(automaton.CurrentAction.Invoke(levelView));
            }

            return(ExecuteFight(levelView));
        }
Beispiel #17
0
        public bool ExitIsClosed(LevelView level)
        {
            var exit = level.Field.GetCellsOfType(CellType.Exit).First();
            var neir = new Location[] { exit.Up(), exit.Down(), exit.Left(), exit.Right() };

            return(neir.All(p => level.Field[p] == CellType.Wall));
        }
Beispiel #18
0
        public Turn Solve(LevelView level, Enviroment enviroment, out bool isAttack)
        {
            isAttack = false;
            if (level.Player.Health < MaxHp && level.HealthPacks.Any())
            {
                enviroment.EnemyMap.Multiplyer = 2;
                var map = Map.Sum(enviroment.TravelMap, enviroment.EnemyMap);

                foreach (var hp in level.HealthPacks.OrderBy(h => h.Location.Distance(level.Player.Location)))
                {
                    var path = map.FindPath(level.Player.Location, hp.Location);
                    if (path == null) //бывают ситуации, когда полуживой монстр закрывает на проход к аптечкам. Добиваем его (раз нет других вариантов)
                    {
                        if (level.Monsters.Any(m => m.Location.IsInRange(level.Player.Location, 1)))
                        {
                            isAttack = true;
                            return(Turn.Attack(level.Monsters.First(m => m.Location.IsInRange(level.Player.Location, 1)).Location - level.Player.Location));
                        }
                    }
                    else
                    {
                        return(Turn.Step(path[1] - path[0]));
                    }
                }
            }
            return(null);
        }
Beispiel #19
0
        public void NewArea(
            EnvTypeInfo envTypeInfo,
            List <SpawnsInfo> spawnsInfos,
            LevelSettings levelSettings,
            LevelView outputLevel,
            Action <LevelAreaView> onDone = null)
        {
            // DebugUtils.Log(
            //     "LevelAreaGeneratorView.NewArea(); envType={0}", envType);
            area = outputLevel.NewArea(envTypeInfo);

            if (spawnsInfos.Count == 0)
            {
                if (onDone != null)
                {
                    onDone(area);
                }
                return;
            }

            Profiler.BeginSample("LevelAreaGeneratorView.NewArea()");
            this.envTypeInfo   = envTypeInfo;
            this.spawnsInfos   = spawnsInfos;
            this.levelSettings = levelSettings;
            this.onDone        = onDone;
            level            = outputLevel;
            spawnsInfosIndex = 0;
            NextObjectType();
            reservedSpawnPoints.Clear();
            InvokeRepeating("NewObject", objectSpawnRate, objectSpawnRate);
            Profiler.EndSample();
        }
Beispiel #20
0
        private static bool IsLastLevel(LevelView level)
        {
            var exit = level.Field.GetCellsOfType(CellType.Exit).First();
            var neir = new [] { exit.Up(), exit.Down(), exit.Left(), exit.Right() };

            return(neir.All(p => level.Field[p] == CellType.Wall));
        }
Beispiel #21
0
        public Turn MakeTurn(LevelView levelView, IMessageReporter messageReporter)
        {
            messageReporter.ReportMessage("Hey ho! I'm still breathing");



            return(Turn.Step((StepDirection)levelView.Random.Next(4)));
        }
Beispiel #22
0
 public InfluenceMap(LevelView levelView)
 {
     influenceCache            = new Dictionary <Location, int>();
     this.levelView            = levelView;
     monsterInfluenceSeed      = 32;
     arenaFighterInfluenceSeed = 8;
     wallInfluenceSeed         = CalculateMagicWallInfluenceSeed(Field);
 }
Beispiel #23
0
    void Start()
    {
        currentLevel     = PlayerPrefs.GetInt("CurrentLevel", 1);
        currentLevelView = Instantiate(levelPrefabs[currentLevel % levelPrefabs.Length]);

        Debug.Log("Current Level: " + currentLevel);
        SetupCameras();
    }
Beispiel #24
0
 public Turn HandleCycle(LevelView level)
 {
     if (!level.Monsters.Any())
     {
         return(null);
     }
     CycleDetected = true;
     return(null);
 }
        public IOrderedEnumerable <Location> GetSaveSpots(LevelView level, Enviroment enviroment)
        {
            var b = enviroment.Start;
            var e = enviroment.Exit;

            return(new[] { b, e, new Location(b.X, e.Y), new Location(e.X, b.Y) }
                   .OrderBy(s => level.Monsters.Count(m => s.IsInRange(m.Location, 3)))
                   .ThenByDescending(s => s.Distance(level.Player.Location)));
        }
Beispiel #26
0
        private bool TryGetBestStepToItem(LevelView level, out Location locationToStep)
        {
            locationToStep = FindByDijkstra(level, IsToConsider, GetCost);

            return(locationToStep != default(Location));

            bool IsToConsider(Location location)
            {
                level.Player.TryGetEquippedItem(out var item);

                return(level.GetItemAt(location).HasValue&&
                       level.GetItemAt(location).AttackBonus > item.AttackBonus &&
                       level.GetItemAt(location).DefenceBonus > item.DefenceBonus);
            }

            int GetCost(Location location)
            {
                if (level.Field[location] == CellType.Wall ||
                    level.Field[location] == CellType.Trap ||
                    level.GetMonsterAt(location).HasValue)
                {
                    return(100);
                }

                if (level.GetItemAt(location).HasValue)
                {
                    level.Player.TryGetEquippedItem(out var item);

                    if (level.GetItemAt(location).AttackBonus > item.AttackBonus &&
                        level.GetItemAt(location).DefenceBonus > item.DefenceBonus)
                    {
                        return(0);
                    }

                    return(100);
                }

                if (level.Field[location] == CellType.Exit)
                {
                    return(0);
                }

                if (level.Field[location] == CellType.Empty || level.Field[location] == CellType.PlayerStart)
                {
                    return(10 - GetNeighbours(location, NeighbourType.Eight)
                           .Count(x => level.Field[x] == CellType.Trap ||
                                  level.Field[x] == CellType.Wall));
                }

                if (level.Field[location] == CellType.Hidden)
                {
                    return(10);
                }

                throw new ArgumentOutOfRangeException(nameof(location));
            }
        }
Beispiel #27
0
        public LevelPresenter(ILevelModel levelModel, IGameTypeModel gameTypeModel, LevelView levelView)
        {
            levelModel.level
            .Subscribe(levelView.DisplayLevel)
            .AddTo(levelView);

            gameTypeModel.gameType
            .Subscribe(levelView.UpdateDigit)
            .AddTo(levelView);
        }
Beispiel #28
0
        public static TorpedoView GetInstance(Ammunition torpedo, LevelView levelViewRef)
        {
            TorpedoView rv = torpedoAvailablePool.Pop();

            rv.ammunition = torpedo;
            rv.postInitOnScene();
            rv.levelViewRef = levelViewRef;
            torpedoUsedPool.Add(torpedo, rv);
            return(rv);
        }
Beispiel #29
0
        public Turn MakeTurn(LevelView levelView, IMessageReporter messageReporter)
        {
            if (levelView.Player.Location == levelView.Field.GetCellsOfType(CellType.PlayerStart).Single())
            {
                lvlCount++;
                slave = new Slave(ref levelView, messageReporter, lvlCount);
            }

            return(slave.SlaveObjectives.Peek()());
        }
Beispiel #30
0
 void Awake()
 {
     levelController            = GetComponentInChildren <LevelController>();
     levelModel                 = new LevelModel();
     levelController.levelModel = levelModel;
     levelView = GetComponentInChildren <LevelView>();
     levelController.levelView = levelView;
     levelView.levelModel      = levelModel;
     levelView.levelController = levelController;
 }