Example #1
0
 public void StartGame(GamePattern pattern)
 {
     Debug.Log($"start game,level:{CurrLevel}");
     //CurrLevel = PlayerPrefs.GetInt("CurrLevel",1);
     IsGameOver    = false;
     CurrPattern   = pattern;
     CurrLevelData = GetCurrLevelData();
     if (pattern == GamePattern.Challenge)
     {
         if (CurrLevelData != null)
         {
             MoveSpeed = CurrLevelData.Movespeed;
             CreatePathBySpriteShape();
             MainPanel._Ins.BeginGame();
             Player._Ins.InitPlayer();
         }
         else
         {
             Debug.Log($"已到达最后一关,没有更高的关卡了");
             MainPanel._Ins.Close();
             StartPanel._Ins.Show();
         }
     }
     else
     {
         // 时间模式
         MoveSpeed = float.Parse(timeSpeedGroup[0]);
         CreatePathBySpriteShape();
         MainPanel._Ins.BeginGame();
         Player._Ins.InitPlayer();
     }
 }
Example #2
0
 private void OnGameOver(GamePattern currPattern, bool isWin)
 {
     Debug.Log($"{currPattern}模式结束,是否获胜:{isWin}");
     IsGameOver = true;
     ResetGame();
     MainPanel._Ins.ResetData();
     MainPanel._Ins.Close();
     GameOverPanel._Ins.Show();
     Player._Ins.ResetPlayer();
     EC.OnResetGameData?.Invoke();
 }
Example #3
0
    // Use this for initialization
    void Awake()
    {
        boostEnabled = true;

        playerRB = GetComponent <Rigidbody2D>();
        player   = GetComponent <Player>();

        cooldownDoneTime = Time.time;            //player immediately has boost
        boostReady       = false;

        gameMasterPattern = gameMaster.GetComponent <GamePattern>();
    }
Example #4
0
    // Use this for initialization
    void Awake()
    {
        playerCollider = GetComponent <Collider2D>();
        playerRenderer = GetComponent <SpriteRenderer>();
        playerRB       = GetComponent <Rigidbody2D>();

        //killLineCollider = killLine.GetComponent<Collider2D>(); // killLine has multiple colliders; don't use this.

        exploded = false;

        gameMasterPattern = gameMaster.GetComponent <GamePattern>();
    }
Example #5
0
    // Use this for initialization
    void Awake()
    {
        onGroundCanJump       = false;
        jumpNotReleased       = false;
        jumpResetBlockedUntil = Time.time;

        maxContJumpForce = continuousJumpForce;
        playerRB         = GetComponent <Rigidbody2D>();
        playerAnim       = GetComponent <Animator>();

        gameMasterPattern = gameMaster.GetComponent <GamePattern>();
    }
Example #6
0
    public void ShowPanel(GamePattern pattern)
    {
        ui_ChallengePattern.gameObject.SetActive(false);
        ui_TimePattern.gameObject.SetActive(false);
        if (pattern == GamePattern.Challenge)
        {
            ui_ChallengePattern.gameObject.SetActive(true);
        }
        else
        {
            ui_TimePattern.gameObject.SetActive(true);
        }

        base.Show();
    }
        public IActionResult Index(GameViewModel model)
        {
            Game game = null;

            try
            {
                game = _context.Games.AsNoTracking().Include(p => p.Patterns).Where(g => g.Guid == model.guid).FirstOrDefault();
                int currlevel = game.Patterns.Count();
                if (game.IsCompleted || model.level < currlevel)
                {
                    return(View(game));
                }
                var            basePatern = game.Patterns.Where(p => p.Level == 0).FirstOrDefault();
                List <CodePeg> code       = new List <CodePeg>
                {
                    basePatern.CodePeg1,
                    basePatern.CodePeg2,
                    basePatern.CodePeg3,
                    basePatern.CodePeg4
                };
                List <CodePeg> guess = new List <CodePeg>
                {
                    (CodePeg)Enum.Parse(typeof(CodePeg), model.codepeg1),
                    (CodePeg)Enum.Parse(typeof(CodePeg), model.codepeg2),
                    (CodePeg)Enum.Parse(typeof(CodePeg), model.codepeg3),
                    (CodePeg)Enum.Parse(typeof(CodePeg), model.codepeg4)
                };
                List <KeyPeg> keys  = _codeAnalyzer.EvaluateGuess(guess, code).ToList();
                List <KeyPeg> _keys = new List <KeyPeg>();
                foreach (var key in keys)
                {
                    _keys.Add(key);
                }
                while (_keys.Count < 4)
                {
                    _keys.Add(KeyPeg.None);
                }

                var pattern = new GamePattern
                {
                    Level    = currlevel,
                    CodePeg1 = guess[0],
                    CodePeg2 = guess[1],
                    CodePeg3 = guess[2],
                    CodePeg4 = guess[3],
                    KeyPeg1  = _keys[0],
                    KeyPeg2  = _keys[1],
                    KeyPeg3  = _keys[2],
                    KeyPeg4  = _keys[3],
                    Game     = game
                };
                game.Patterns.Add(pattern);
                game.IsCompleted = pattern.IsCompleted() || model.level == 8;
                _context.Games.Update(game);
                _context.GamePatterns.Add(pattern);
                _context.SaveChanges();
            }
            catch (Exception)
            {
                if (game == null)
                {
                    RedirectToAction(nameof(HomeController.Index), "Home");
                }
                return
                    (View(game));
            }
            return(View(game));
        }
Example #8
0
    /* This function is called once upon game scene loading, and upon menu scene loading.
     *  It's not efficient and is pretty bulky, but it's only called once per game load
     *  Note: "GameObject.Find" calls are necessary since scene references can't be set before scene exists
     *
     *  Game load sets all settings.
     *  Menu load tells menu to go to unlocks screen, but only if the menu has been visited once already (game start).
     */
    void ApplyGameModeSettings(Scene scene, LoadSceneMode mode)
    {
        //music obj is same in both scenes


        if (scene.name.Equals("Game"))
        {
            Debug.Log("Persistent settings are applying to the current scene...");

            GameObject gameMaster = GameObject.Find("GameMaster");

            GamePattern gamePattern = gameMaster.GetComponent <GamePattern>();

            gamePattern.fireMode          = fireMode;           // firemode
            gamePattern.rotateBy45Degrees = rotate45;           // roation
            gamePattern.minWaitTime       = minWaitTime;        // min time between block throws
            gamePattern.maxWaitTime       = maxWaitTime;        // max time between block throws

            //apply a palette - based on player options or gamemode
            if (optionOverridePalette != null && !impossibleMode)
            {
                gamePattern.currentPalette = optionOverridePalette; //use player selection instead if there is one (only exception is impossible mode!)
            }
            else
            {
                gamePattern.currentPalette = settingPalette;        // the colour palette object to pull from - passes through Pattern into throw()
            }
            ScoreData scoreData = gameMaster.GetComponent <ScoreData>();
            scoreData.makeScoreNegative = makeScoreNegative;
            scoreData.currentMode       = currentModeName;

            GameObject cameraMain     = GameObject.Find("Main Camera");
            GameObject cameraKillLine = GameObject.Find("KillLine Camera");
            if (flipCamera)
            {
                cameraMain.transform.eulerAngles = new Vector3(0, 0, 180);
            }
            else
            {
                cameraMain.transform.eulerAngles = new Vector3(0, 0, 0);    //need this line to reset when changing between gamemodes in same session
            }
            if (flipCamera)
            {
                cameraKillLine.transform.eulerAngles = new Vector3(0, 0, 180);
            }
            else
            {
                cameraKillLine.transform.eulerAngles = new Vector3(0, 0, 0);    //need this line to reset when changing between gamemodes in same session
            }
            Player player = GameObject.Find("Player").GetComponent <Player>();
            player.slipperyJumpAllowed = slipperyJumpAllowed;
            Boost boost = GameObject.Find("Player").GetComponent <Boost>();
            boost.cooldownLength = boostCooldown;
            Exploder exploder = GameObject.Find("Player").GetComponent <Exploder>();
            exploder.immuneToCrush = immuneToCrush;

            AudioSource sceneMusic = GameObject.Find("Music").GetComponent <AudioSource>();
            sceneMusic.mute = musicMuted;

            Debug.Log("Persistent settings application complete.");
        }

        //ensures menu loads into the unlocks screen
        else if (scene.name.Equals("MainMenu"))
        {
            MainMenu menuNav = GameObject.Find("MenuNavigator").GetComponent <MainMenu>();

            if (mainMenuVisitedOnGameStartFlag && unlockMessageQueue.Count > 0)
            {
                Debug.Log("PersistentSettings is notifying MenuNavigator that a game has been played. Menu should load into unlock screen.");
                menuNav.userHasPlayedARound = true;
                //there's no need to set the unlock messages; they are collected automatically then wiped by the UnlockCanvas
            }

            if (musicMuted)
            {
                Debug.Log("Attempting to mute music on main menu");
                menuNav.needToApplyPersistentMusicMute = true;
            }
        }

        mainMenuVisitedOnGameStartFlag = true; //flag to mark that the main menu has been visited
    }