Example #1
0
 override public PrefromResult Perform(float delta)
 {
     LivesModel.Instance().DecLives();
     AnalyticsWrapper.ReportReturnToMenu(DifficultyModel.Instance().number, GameModel.Instance());
     SceneManager.LoadScene("MenuScene");
     return(PrefromResult.COMPLETED);
 }
Example #2
0
        public static void Apply(MazeModel mazeData)
        {
            foreach (NodeVO deadEnd in mazeData.deadEnds)
            {
                NodeVO node         = deadEnd;
                int    currentScore = DifficultyModel.Instance().minScore;
                int    ds           = 1;

                while (node != null && node.score == 0)
                {
                    currentScore += ds;
                    node.score    = currentScore;
                    //define score delta
                    if (node.score <= DifficultyModel.Instance().minScore)
                    {
                        ds = 1;
                    }

                    if (node.score >= DifficultyModel.Instance().maxScore)
                    {
                        ds = -1;
                    }

                    node = node.previousNode;
                }
            }
        }
Example #3
0
 void UpdateVisibility()
 {
     _handRenderer.enabled =
         DifficultyModel.Instance().tutorialPresent&&
         _playerDirection != _correctDirection &&
         _correctDirection != NodeVO.DIRECTION_INVALID_IDX &&
         !_waitingNextLevel;
 }
Example #4
0
        override public PrefromResult Perform(float delta)
        {
            if (DifficultyModel.Instance().number > PlayerPrefs.GetInt("maxlevel", 0))
            {
                PlayerPrefs.SetInt("maxlevel", DifficultyModel.Instance().number);
            }

            return(PrefromResult.COMPLETED);
        }
Example #5
0
        override public PrefromResult Perform(float delta)
        {
            var game = GameModel.Instance();

            game.state = GameModel.STATE_INITED;
            game.timeBonus.SetValue(DifficultyModel.Instance().maxTimeBonus, DifficultyModel.Instance().minTimeBonus, DifficultyModel.Instance().bonusTime);
            game.movesLeft.SetValue(MazeModel.Instance().deadEnds [0].GetDistance() * 2);

            MazePaceNotifications.GAME_UPDATED.Dispatch();

            return(PrefromResult.COMPLETED);
        }
Example #6
0
        //设置AI游戏难度
        public void SetChessModel(DifficultyModel level)
        {
            switch (level)
            {
            case DifficultyModel.easy: SearchEngine._searchDepth = 1; break;

            case DifficultyModel.middle: SearchEngine._searchDepth = 2; break;

            case DifficultyModel.difficult: SearchEngine._searchDepth = 3; break;

            default: break;
            }
        }
Example #7
0
        override public PrefromResult Perform(float delta)
        {
            //todo persistent data provider?
            DifficultyModel.Instance().number = PlayerPrefs.GetInt("maxlevel", 0) / 2;
            GameModel.Instance().maxScore.SetValue(PlayerPrefs.GetInt("highscore", 0));

            GameModel.Instance().score.SetValue(0);

            PlayerModel.Instance().cellPosition.x = 0;
            PlayerModel.Instance().cellPosition.y = 0;

            return(PrefromResult.COMPLETED);
        }
Example #8
0
		override public PrefromResult Perform (float delta)
		{
			var player = PlayerModel.Instance ();
			IntPointVO pos = player.cellPosition;
			int directionIdx = player.directionIdx;
			NodeVO node = MazeModel.Instance ().GetNode (pos.x, pos.y);
			GameModel game = GameModel.Instance ();

			game.AddScore ((int)((float)node.score * game.timeBonus));
			node.score = 0;

			game.movesLeft.Dec (1);

			if (game.state == GameModel.STATE_INITED || game.state == GameModel.STATE_STUCK) {
				game.state = GameModel.STATE_MOVING;	
				game.score.Freeze();
				game.timeBonus.Freeze();
			}

			if (node.HasFlag (NodeVO.SPECIALS_EXIT)) {
				game.state = GameModel.STATE_ENDED;
				MazePaceNotifications.EXIT_REACHED.Dispatch ();
			} else {
				if (node.HasFlag (NodeVO.SPECIALS_HIDE_WALLS)) {
					MazePaceNotifications.TOGGLE_WALLS_VISIBILITY.Dispatch (false);
				}
				if (node.HasFlag (NodeVO.SPECIALS_SHOW_WALLS)) {
					MazePaceNotifications.TOGGLE_WALLS_VISIBILITY.Dispatch (true);
				}
				bool shouldRotate = node.HasWall (directionIdx) || player.moved;
				if (node.HasFlag (NodeVO.SPECIALS_ROTATOR_CW | NodeVO.SPECIALS_ROTATOR_CCW) && shouldRotate) {
					MazePaceNotifications.ROTATE_AT_NODE.Dispatch (node);
					player.moved = false;
				} else if (!node.HasWall (directionIdx)) {
					player.cellPosition.x += NodeVO.DIRECTIONS [player.directionIdx, 0];
					player.cellPosition.y += NodeVO.DIRECTIONS [player.directionIdx, 1];
					player.moved = true;
					MazePaceNotifications.PROCEED_FROM_NODE.Dispatch (node);
				} else {
					game.state = GameModel.STATE_STUCK;
					game.score.SetValue (game.score, 0, DifficultyModel.Instance ().scoreDrainTime);
					MazePaceNotifications.PLAYER_STUCK.Dispatch ();
				}
			}

			MazePaceNotifications.GAME_UPDATED.Dispatch ();
			return PrefromResult.COMPLETED;
		}
Example #9
0
        public override PrefromResult Perform(float delta)
        {
            var difficultyModel = DifficultyModel.Instance();
            var cellPosition    = PlayerModel.Instance().cellPosition;

            MazeModel.Instance().Recreate(difficultyModel.size, cellPosition.x, cellPosition.y);
            ExitDecorator.Apply(MazeModel.Instance());
            ScoreDecorator.Apply(MazeModel.Instance());
            HiderDecorator.Apply(MazeModel.Instance());
            SpeedUpDecorator.Apply(MazeModel.Instance());
            RotatorDecorator.Apply(MazeModel.Instance());

            MazePaceNotifications.MAZE_RECREATED.Dispatch();

            return(PrefromResult.COMPLETED);
        }
Example #10
0
        public static void Apply(MazeModel mazeData)
        {
            if (DifficultyModel.Instance().hidersCount == 0)
            {
                return;
            }

            for (int i = 0; i < mazeData.deadEnds.Count; i++)
            {
                if (i >= DifficultyModel.Instance().hidersCount)
                {
                    break;
                }

                int distance = (int)mazeData.deadEnds [i].GetDistance();

                if (distance < 4)
                {
                    return;
                }

                int showIndex = _rnd.Next((int)distance / 4, (int)distance / 2);
                int hideIndex = _rnd.Next(showIndex + 2, showIndex + (int)Math.Min((int)(distance / 2), 8));

                NodeVO node  = mazeData.deadEnds [i].previousNode;
                int    index = 0;
                while (node != null)
                {
                    index++;

                    if (index == showIndex)
                    {
                        node.AddFlag(NodeVO.SPECIALS_SHOW_WALLS);
                    }


                    if (index == hideIndex)
                    {
                        node.AddFlag(NodeVO.SPECIALS_HIDE_WALLS);
                    }

                    node = node.previousNode;
                }
            }
        }
Example #11
0
        override public PrefromResult Perform(float delta)
        {
            var game = GameModel.Instance();

            game.movesLeft.SetValue(game.movesLeft, 0u, 1.8f);
            var avgScore = (DifficultyModel.Instance().minScore + DifficultyModel.Instance().maxScore) / 2;
            var newScore = (int)(game.score + game.movesLeft * game.timeBonus * avgScore);

            game.score.SetValue(game.score, newScore, 1.8f);
            if (game.maxScore < newScore)
            {
                game.maxScore.SetValue(game.maxScore, newScore, 1.8f);
            }
            DifficultyModel.Instance().number++;
            MazePaceNotifications.GAME_UPDATED.Dispatch();

            return(PrefromResult.COMPLETED);
        }
Example #12
0
        override public PrefromResult Perform(float delta)
        {
            var game = GameModel.Instance();

            if (game.GetIsLost())
            {
                if (game.maxScore > PlayerPrefs.GetInt("highscore", 0))
                {
                    PlayerPrefs.SetInt("highscore", game.maxScore);
                }

                AnalyticsWrapper.ReportGameLost(DifficultyModel.Instance().number, game);
                LivesModel.Instance().DecLives();
                SceneManager.LoadScene("MenuScene");
            }

            return(PrefromResult.PROCEED);
        }
Example #13
0
        public static void Apply(MazeModel mazeData)
        {
            if (DifficultyModel.Instance().speedUpsCount == 0)
            {
                return;
            }

            List <SpeedUpChain> chains = new List <SpeedUpChain> ();

            foreach (NodeVO deadEnd in mazeData.deadEnds)
            {
                NodeVO       node             = deadEnd;
                int          currentDirection = -1;
                SpeedUpChain currentChain     = new SpeedUpChain();

                do
                {
                    NodeVO previousNode = node.previousNode;

                    bool nodeHasSpeedUp = false;
                    foreach (SpeedUpChain chain in chains)
                    {
                        if (chain.nodes.Contains(node))
                        {
                            nodeHasSpeedUp = true;
                            break;
                        }
                    }

                    if (nodeHasSpeedUp)                     //branch reached a point of another branch that has already been processed
                    {
                        break;
                    }

                    if (previousNode != null)
                    {
                        currentChain.nodes.Add(node);

                        bool hasSpecial = previousNode.HasFlag(
                            NodeVO.SPECIALS_ROTATOR_CW |
                            NodeVO.SPECIALS_ROTATOR_CCW |
                            NodeVO.SPECIALS_HIDE_WALLS |
                            NodeVO.SPECIALS_SHOW_WALLS);

                        int direction = previousNode.GetDirectionTowards(node);

                        if ((currentDirection != direction) || hasSpecial)
                        {
                            if (currentChain != null && currentChain.nodes.Count > 1)
                            {
                                chains.Add(currentChain);
                            }

                            currentChain           = new SpeedUpChain();
                            currentChain.direction = direction;
                        }

                        currentDirection = hasSpecial ? -1 : direction;
                    }
                    node = previousNode;
                } while (node != null);
            }

            chains.Sort();

            for (int i = 0; i < chains.Count; i++)
            {
                if (i >= DifficultyModel.Instance().speedUpsCount)
                {
                    break;
                }

                //mark nodes to contain according speedup flags
                foreach (NodeVO nodeData in chains[i].nodes)
                {
                    switch (chains [i].direction)
                    {
                    case (NodeVO.DIRECTION_UP_IDX):
                        nodeData.AddFlag(NodeVO.SPECIALS_SPEEDUP_UP);
                        break;

                    case (NodeVO.DIRECTION_RIGHT_IDX):
                        nodeData.AddFlag(NodeVO.SPECIALS_SPEEDUP_RIGHT);
                        break;

                    case (NodeVO.DIRECTION_DOWN_IDX):
                        nodeData.AddFlag(NodeVO.SPECIALS_SPEEDUP_DOWN);
                        break;

                    case (NodeVO.DIRECTION_LEFT_IDX):
                        nodeData.AddFlag(NodeVO.SPECIALS_SPEEDUP_LEFT);
                        break;
                    }
                }
            }
        }
Example #14
0
 void OnApplicationPause(bool paused)
 {
     AnalyticsWrapper.ReportGamePaused(DifficultyModel.Instance().number, GameModel.Instance());
     InvokeAction(MazePaceActions.AppendMaxScore);
 }
Example #15
0
 //设置AI游戏难度
 public void SetChessModel(DifficultyModel level)
 {
     ChessControl._instance.SetChessModel(level);
 }
Example #16
0
 public void OnExitClick()
 {
     AnalyticsWrapper.ReportReturnToMenu(DifficultyModel.Instance().number, GameModel.Instance());
     InvokeAction(MazePaceActions.NavigateToMenu);
 }
Example #17
0
        public static void Apply(MazeModel mazeData)
        {
            if (DifficultyModel.Instance().rotatorsCount == 0)
            {
                return;
            }

            List <NodeVO> candidates = new List <NodeVO> ();

            foreach (NodeVO node in mazeData.crossRoads)
            {
                //make sure there are no special flags yet
                if (node.HasFlag(
                        NodeVO.SPECIALS_SPEEDUP_UP |
                        NodeVO.SPECIALS_SPEEDUP_RIGHT |
                        NodeVO.SPECIALS_SPEEDUP_DOWN |
                        NodeVO.SPECIALS_SPEEDUP_LEFT |
                        NodeVO.SPECIALS_HIDE_WALLS |
                        NodeVO.SPECIALS_SHOW_WALLS))
                {
                    continue;
                }

                //make sure its not the start node
                if (node.previousNode == null)
                {
                    continue;
                }

                candidates.Add(node);
            }

            Shuffle(candidates);
            for (int i = 0; i < candidates.Count; i++)
            {
                if (i >= DifficultyModel.Instance().rotatorsCount)
                {
                    break;
                }

                uint type = 0;

                //entering direction to this node
                int prevDirection = candidates [i].previousNode.GetDirectionTowards(candidates [i]);

                //calculate the delta direction towards exit
                int delta = candidates [i].directionToExit - prevDirection;
                if (delta > 2)
                {
                    delta -= 4;
                }
                if (delta < -2)
                {
                    delta += 4;
                }

                if (delta == -1)
                {
                    type = NodeVO.SPECIALS_ROTATOR_CCW;
                }
                else if (delta == 1)
                {
                    type = NodeVO.SPECIALS_ROTATOR_CW;
                }

                candidates [i].AddFlag(type);
            }
        }
Example #18
0
        private void Redraw()
        {
            var difficultyModel = DifficultyModel.Instance();
            var maze            = MazeModel.Instance();

            transform.parent.localPosition = new Vector2(
                -(maze.size - 1) * DifficultyModel.NODE_SIZE / 2,
                -(maze.size - 1) * DifficultyModel.NODE_SIZE / 2
                );

            //set of base colors
            ColorComponentVO[] colorComponents = ColorComponentVO.GetArray();

            int index = 0;

            for (int cellX = 0; cellX < maze.size; cellX++)
            {
                for (int cellY = 0; cellY < maze.size; cellY++)
                {
                    NodeVO node = maze.GetNode(cellX, cellY);

                    float[] tileRelativePos = new float[2] {
                        (float)cellX / maze.size,
                        (float)cellY / maze.size
                    };

                    float tint   = 0.6f + 0.4f * (float)(node.score - difficultyModel.minScore) / (difficultyModel.maxScore - difficultyModel.minScore);
                    float zOrder = 10 - (float)(cellY + cellX) / (maze.size + maze.size);

                    GameObject nodeInstance;
                    if (_nodeInstances.Count > index)
                    {
                        nodeInstance = _nodeInstances [index];
                    }
                    else
                    {
                        //create a tile
                        nodeInstance = (GameObject)Instantiate(PrefabLib.NODE);
                        nodeInstance.transform.parent = transform;
                        int value     = Random.Range(0, 3);
                        int randompos = (Random.Range(0, 2) == 1 ? value + maze.size : -(value + 1));
                        if (Random.Range(0, 2) == 1)
                        {
                            nodeInstance.transform.localPosition = new Vector3(cellX * DifficultyModel.NODE_SIZE, randompos * DifficultyModel.NODE_SIZE, zOrder);
                        }
                        else
                        {
                            nodeInstance.transform.localPosition = new Vector3(randompos * DifficultyModel.NODE_SIZE, cellY * DifficultyModel.NODE_SIZE, zOrder);
                        }
                        _nodeInstances.Add(nodeInstance);
                    }

                    nodeInstance.transform.DOLocalMove(new Vector3(
                                                           cellX * DifficultyModel.NODE_SIZE,
                                                           cellY * DifficultyModel.NODE_SIZE,
                                                           zOrder
                                                           ), TRANSITION_TIME);

                    nodeInstance.GetComponent <NodeMediator> ().Redraw(node, ColorComponentVO.GetColorAt(tileRelativePos, colorComponents, tint));

                    index++;
                }
            }
        }