예제 #1
0
    void handleGameOver()
    {
        // Game over
        timeRemaining = 0.0f;
        int winnerNum   = 1;
        int winnerScore = 0;

        if (playerAdded1 && p1controller.getScore() > winnerScore)
        {
            winnerScore = p1controller.getScore();
            winnerNum   = 1;
        }
        if (playerAdded2 && p2controller.getScore() > winnerScore)
        {
            winnerScore = p2controller.getScore();
            winnerNum   = 2;
        }
        if (playerAdded3 && p3controller.getScore() > winnerScore)
        {
            winnerScore = p3controller.getScore();
            winnerNum   = 3;
        }
        if (playerAdded4 && p4controller.getScore() > winnerScore)
        {
            winnerScore = p4controller.getScore();
            winnerNum   = 4;
        }

        gameUI.DisplayEndOverlay(winnerNum, winnerScore);
        gameState = GAME_STATES.END;
    }
예제 #2
0
        void Update()
        {
            if (Time.time >= nextTime)
            {
                interval = 10;
                if (oldRoom != currentRoom)
                {
                    if (currentRoom == GAME_STATES.FIRST_ROOM)
                    {
                        oldRoom = currentRoom;
                    }
                    else if (currentRoom == GAME_STATES.SECOND_ROOM)
                    {
                        oldRoom = currentRoom;
                    }
                    else if (currentRoom == GAME_STATES.NORMAL_GAME)
                    {
                        //UpdateRandomRoomConfig();
                        RandomTags(out List <SamTags> tags, random.Next(5, 10));
                        TriggerManager._instance.UpdateRoomConfig(tags, Fear.Nyctophobia, (float)random.NextDouble());
                        oldRoom = currentRoom;
                    }
                }
                if (oldTriggeredEvent != triggeredEvent)
                {
                    TriggerManager._instance.UpdateTriggerEvents();
                    oldTriggeredEvent = triggeredEvent;
                }
                player.ComputeFearLevel();

                int fearLevel = player.GetCurrentFearLevel();
                TriggerManager._instance.UpdateFear((float)fearLevel);
                nextTime += interval;
            }
        }
예제 #3
0
 public static void changeState(GAME_STATES i)
 {
     if (i == GAME_STATES.SCORE)
     {
     }
     else
     {
         actualState = states[(int)i];
     }
 }
예제 #4
0
        public GRID_SHOT TakeShot(string playerName, Coordinate shotLocation)
        {
            Player    shooter  = GetActivePlayer();
            Player    opponent = GetOpponent(shooter.Name);
            GRID_SHOT shotResult;

            if (shooter.Name == playerName)
            {
                //If There is no shot here already
                if (opponent.PlayerBoard.playerGrid[shotLocation.BoardX, shotLocation.BoardY].shot == GRID_SHOT.CLEAR)
                {
                    //If there's a ship here - mark a hit
                    if (opponent.PlayerBoard.playerGrid[shotLocation.BoardX, shotLocation.BoardY].ship != null)
                    {
                        opponent.PlayerBoard.playerGrid[shotLocation.BoardX, shotLocation.BoardY].ship.hits.Add(shotLocation);
                        opponent.PlayerBoard.playerGrid[shotLocation.BoardX, shotLocation.BoardY].shot = GRID_SHOT.HIT;
                        shotResult = GRID_SHOT.HIT;

                        //Check if ship is sunk
                        if (opponent.PlayerBoard.playerGrid[shotLocation.BoardX, shotLocation.BoardY].ship.hits.Count ==
                            opponent.PlayerBoard.playerGrid[shotLocation.BoardX, shotLocation.BoardY].ship.length)
                        {
                            opponent.SunkShips.Add(opponent.PlayerBoard.playerGrid[shotLocation.BoardX, shotLocation.BoardY].ship);

                            winner = CheckGameOver();

                            if (winner != null)
                            {
                                System.Threading.Thread.Sleep(30000);
                                player1   = null;
                                player2   = null;
                                gameState = GAME_STATES.WAITING_FOR_PLAYERS;
                                winner    = null;
                            }
                        }
                    }
                    else //No ship, mark it a miss
                    {
                        opponent.PlayerBoard.playerGrid[shotLocation.BoardX, shotLocation.BoardY].shot = GRID_SHOT.MISS;
                        shotResult = GRID_SHOT.MISS;
                    }

                    TogglePlayerTurn();
                    return(shotResult);
                }
                else //Already a shot here.
                {
                    return(GRID_SHOT.ALREADY_FIRED);
                }
            }
            else //Not your turn
            {
                return(GRID_SHOT.NOT_YOUR_TURN);
            }
        }
 void CheckGamePace()
 {
     if(Application.loadedLevel == 0)
     {
         currentState = GAME_STATES.menu;
     }
     else if(Application.loadedLevel == 3)
     {
         currentState = GAME_STATES.game;
     }
 }
예제 #6
0
        public void ChangeState(GAME_STATES newState)
        {
            //Finalizando o estado atual:
            _loadedStates[(int)_activeState].Stop();

            //Definindo o novo estado:
            _activeState = newState;

            //Inicializando o novo estado:
            _loadedStates[(int)_activeState].Init(_game, this);
        }
예제 #7
0
 void CheckGamePace()
 {
     if (Application.loadedLevel == 0)
     {
         currentState = GAME_STATES.menu;
     }
     else if (Application.loadedLevel == 3)
     {
         currentState = GAME_STATES.game;
     }
 }
예제 #8
0
    }
	// Use this for initialization
	void Start () {
        camera.target = hero.transform;
        initialMap = currentMap;
	}
	
	// Update is called once per frame
	void Update () {
        
	}
예제 #9
0
 /// <summary>
 /// ステージ選択ボタン押下時の処理(UI系)
 /// </summary>
 public void StartGame()
 {
     // タイムカウンターUIを表示
     timeText.enabled = true;
     // 宝船カウンターUIを表示
     treasureShipCounterObj.SetActive(true);
     // ゲーム開始可能フラグをtrueに
     // isSetUp = true;
     // ゲームステータスをPLAYINGに
     gameStates = GAME_STATES.PLAYING;
 }
예제 #10
0
        public GAME_STATES TogglePlayerTurn()
        {
            if (gameState == GAME_STATES.PLAYER1_TURN)
            {
                gameState = GAME_STATES.PLAYER2_TURN;
            }
            else if (gameState == GAME_STATES.PLAYER2_TURN)
            {
                gameState = GAME_STATES.PLAYER1_TURN;
            }

            return(gameState);
        }
예제 #11
0
        public StateMachine(MainGame game)
        {
            //Salvando as variáveis:
            _game = game;

            //Instanciando TODOS os estados do jogo:
            _loadedStates = new List<IGameState>();

            _loadedStates.Add(new MainMenuState(GAME_STATES.MAIN_MENU));
            _loadedStates.Add(new StageChooserState(GAME_STATES.STAGE_SELECT));
            _loadedStates.Add(new GamePlayState(GAME_STATES.GAME_PLAY));
            _loadedStates.Add(new StageWonState(GAME_STATES.STAGE_WON));
            _loadedStates.Add(new StageLostState(GAME_STATES.STAGE_LOST));
            _loadedStates.Add(new OptionsState(GAME_STATES.OPTIONS));

            //O primeiro estado é sempre a INTRO:
            _activeState = GAME_STATES.MAIN_MENU;
            ChangeState(GAME_STATES.MAIN_MENU);
        }
예제 #12
0
        public Player JoinGame(string name)
        {
            if (player1 == null)
            {
                player1 = new Player(name);

                return(player1);
            }
            else if (player2 == null)
            {
                player2 = new Player(name);

                gameState = GAME_STATES.PLACING_SHIPS;

                return(player2);
            }

            return(null);
        }
예제 #13
0
        public Player CheckGameOver()
        {
            //ALL PLAYER 1 SHIPS SUNK, PLAYER 2 WINS
            if (player1.SunkShips.Count == 5)
            {
                gameState = GAME_STATES.GAME_OVER;
                return(player2);
            }

            //ALL PLAYER 2 SHIPS SUNK, PLAYER 1 WINS
            if (player2.SunkShips.Count == 5)
            {
                gameState = GAME_STATES.GAME_OVER;
                return(player1);
            }

            //No Winner Yet
            return(null);
        }
예제 #14
0
    /// <summary>
    /// ゲーム再開始
    /// </summary>
    public void Restart()
    {
        // 再スタート
        // Debug.Log("ゲームを再スタートします");

        // ゲームステータスをOPENINGに
        gameStates = GAME_STATES.OPENING;

        // インスタンシエイトしたクローゼットを初期化
        closetGenerator.CleanClosetList();

        // 「もう一回する」ボタン非表示
        RestartButton.SetActive(false);

        // GameOverPanel非表示
        gameOverPanel.SetActive(false);

        // タイムカウンター非表示
        // timeText.gameObject.SetActive(false);
        timeText.enabled = false;

        // 宝船カウンター非表示
        treasureShipCounterObj.SetActive(false);

        // タイトルとボタン表示
        titleWithButtons.SetActive(true);

        // 宝船カウンター初期化
        treasureShipCounter = 0;

        // 宝船獲得数表示テキスト初期化
        treasureShipCounterText.text = "× 0";

        // BGM再開
        // bgm.UnPause();
        bgm.Play();

        // タイトル画面の船の位置を初期化
        treasureShipImage.rectTransform.localPosition
            = new Vector2(treasureShipImage.GetComponent <TreasureShipImageBehavor>().posXInitial
                          , treasureShipImage.GetComponent <TreasureShipImageBehavor>().posYInitial);
    }
예제 #15
0
    /// <summary>
    /// 制限時間をカウントするメソッド
    /// </summary>
    public void TimeCount()
    {
        // 制限時間更新
        // limitTime -= Time.deltaTime;    // フレーム分だけ時間減らす
        if ((limitTime - Time.deltaTime) < 0)
        {
            // limitTimeを0に
            limitTime = 0.0f;

            // ゲームステータスをENDINGに
            gameStates = GAME_STATES.ENDING;
        }
        else
        {
            // フレームの差分だけ時間を減らして更新
            limitTime -= Time.deltaTime;
        }

        // text更新
        timeText.text = limitTime.ToString("F2");
    }
예제 #16
0
    public static void SwitchState(GAME_STATES newState)
    {
        if (_currentGameState == newState)
        {
            Debug.Log("Cannot switch the state to " + newState + " because it is already in this state.");
            return;
        }

        Debug.Log("GameStateLoader.cs Attempting to load new scene.");
        switch (newState)
        {
        case GAME_STATES.MAIN_MENU:
            _sceneLoader.LoadScene(GameSceneSwitcher.SCENE_POSITION.MAIN_MENU);
            break;

        case GAME_STATES.INSTRUCTIONS:
            _sceneLoader.LoadScene(GameSceneSwitcher.SCENE_POSITION.INSTRUCTIONS);
            break;

        case GAME_STATES.GAMEPLAY:
            _sceneLoader.LoadScene(GameSceneSwitcher.SCENE_POSITION.GAMEPLAY);
            break;

        case GAME_STATES.WIN_MENU:
            _sceneLoader.LoadScene(GameSceneSwitcher.SCENE_POSITION.WIN_MENU);
            break;

        case GAME_STATES.LOSE_MENU:
            _sceneLoader.LoadScene(GameSceneSwitcher.SCENE_POSITION.LOSE_MENU);
            break;

        case GAME_STATES.SCOREBOARD:
            _sceneLoader.LoadScene(GameSceneSwitcher.SCENE_POSITION.SCOREBOARD);
            break;

        default:
            Debug.Log("State cannot be undefined.");
            break;
        }
    }
예제 #17
0
    // Update is called once per frame
    void Update()
    {
        f_GAME_TIMER += Time.deltaTime;

        if (f_tapTimer > 0)
        {
            f_tapTimer -= f_pausedDT;
        }

        switch (GAME_STATE)
        {
            case GAME_STATES.INTRO:
                {
                    if (!b_isGameReady)
                    {
                        GameObject.Find("ScreenText").GetComponent<GameScreenText>().Display(2, "Double tap to pause");
                    }
                    else
                    {
                        if (GameObject.Find("ScreenText").GetComponent<GameScreenText>().isDoneDisplaying())
                        {
                            GameObject.Find("ScreenText").GetComponent<GameScreenText>().Display(2, "Get ready!");
                        }
                    }
                }
                break;
            case GAME_STATES.PLAYING:
                {
                    if (f_EnemySpawnRate < f_EnemySpawner)
                    {
                        f_EnemySpawner = 0f;
                        GameObject temp = (GameObject)Instantiate(Enemy2, new Vector3(Random.Range(-350, 350), Random.Range(750, 850), 0), this.transform.rotation);
                        temp.SetActive(true);
                        temp.GetComponent<Enemies>().i_Health = i_enemyHealth;
                    }
                    else
                    {
                        f_EnemySpawner += Time.deltaTime;
                    }

                    if (Input.GetMouseButtonDown(0))
                    {
                        if (f_tapTimer > 0)
                        {
                            if (i_tapCount == 1)
                            {
                                GameObject.Find("ScreenText").GetComponent<GameScreenText>().DisplayPernament("Double tap to resume");
                                i_exitCount = 0;
                                Time.timeScale = 0;
                                GAME_STATE = GAME_STATES.PAUSED;
                                i_tapCount = 0;
                            }
                        }
                        else
                        {
                            f_tapTimer = 0.2f;
                            i_tapCount = 1;
                        }
                    }
                    if (Input.GetMouseButtonUp(0))
                    {
                        if (f_tapTimer <= 0)
                        {
                            i_tapCount = 0;
                        }
                    }
                }
                break;
            case GAME_STATES.PAUSED:
                {
                    if (Input.GetMouseButtonUp(0))
                    {
                        if (i_exitCount != 0 && i_exitCount == i_prevExitCount)
                        {
                            GameObject.Find("ScreenText").GetComponent<GameScreenText>().DisplayPernament("Double tap to resume");
                            i_exitCount = 0;
                            i_prevExitCount = 0;
                        }
                    }

                    if (i_exitCount >= 1)
                    {
                        i_prevExitCount = i_exitCount;

                        if (i_exitCount == 2)
                        {
                            GameObject.Find("ScreenText").GetComponent<GameScreenText>().DisplayPernament("Press quit 1 more time to quit");
                        }
                        else if (i_exitCount >= 3)
                        {
                            GameObject.Find("ScreenText").GetComponent<GameScreenText>().unDisplayPernament();
                            Time.timeScale = 1;
                            GAME_STATE = GAME_STATES.DEATH;
                        }
                        else
                        {
                            GameObject.Find("ScreenText").GetComponent<GameScreenText>().DisplayPernament("Press quit 2 more times to quit");
                        }
                    }

                    if (Input.GetMouseButtonDown(0))
                    {
                        if (f_tapTimer > 0)
                        {
                            if (i_tapCount == 1)
                            {
                                GameObject.Find("ScreenText").GetComponent<GameScreenText>().unDisplayPernament();
                                GAME_STATE = GAME_STATES.PLAYING;
                                Time.timeScale = 1;
                                i_tapCount = 0;
                            }
                        }
                        else
                        {
                            f_tapTimer = 0.2f;
                            i_tapCount = 1;
                        }
                    }
                    if (Input.GetMouseButtonUp(0))
                    {
                        if (f_tapTimer <= 0)
                        {
                            i_tapCount = 0;
                        }
                    }
                }
                break;
            case GAME_STATES.DEATH:
                {
                    f_waittoexit += Time.deltaTime;
                    if (f_waittoexit > 1.5)
                    {
                        changetoEndScreen();
                    }
                }
                break;
        }

        f_pausedDT = Time.realtimeSinceStartup - f_prevTime;
        f_prevTime = Time.realtimeSinceStartup;
    }
예제 #18
0
    void SwitchClient()
    {
        if (Input.anyKeyDown)
        {
            GameObject rig = getRig();
            if (rig == null)
            {
                return;
            }
            print("Activated Rig:" + rig.name);
            CmdLastRig();
            if (currentRig == null)
            {
                currentRig = rig;
            }
            CmdAssignRig(rig.name); mainPanel.SetActive(false); sidePanel.SetActive(true); loadPrefabs(); currentState = GAME_STATES.GAME; rearrangeWorld();

            if (rig.activeInHierarchy == false)
            {
                currentRig.SetActive(false);
                currentRig = rig;
                rearrangeWorld();
                CmdAssignRig(rig.name);
                updateLabel();
            }
        }
    }
예제 #19
0
 public BattleshipGame()
 {
     gameState = GAME_STATES.WAITING_FOR_PLAYERS;
 }
예제 #20
0
 public StageChooserState(GAME_STATES id)
 {
     //Salvando o id do estado:
     _id = id;
 }
예제 #21
0
 // Use this for initialization
 void Start()
 {
     Debug.Log(currentState);
     timer        = 0;
     currentState = GAME_STATES.menu;
 }
예제 #22
0
 public OptionsState(GAME_STATES id)
 {
     //Salvando o id do estado:
     _id = id;
 }
 public void EndScreen()
 {
     currentState = GAME_STATES.end;
     Destroy(GameObject.Find("GAME_MANAGER"));
     Debug.Log(currentState);
 }
예제 #24
0
 public void StartGame()
 {
     currentState = GAME_STATES.game;
     Debug.Log(currentState);
 }
예제 #25
0
 public void EndScreen()
 {
     currentState = GAME_STATES.end;
     Destroy(GameObject.Find("GAME_MANAGER"));
     Debug.Log(currentState);
 }
예제 #26
0
        public void ResumeState()
        {
            //Finalizando o estado atual:
            _loadedStates[(int)_activeState].Stop();

            //Definindo o novo estado:
            _activeState = _pausedState;

            //Resumindo o estado anterior:
            _loadedStates[(int)_activeState].Resume();
        }
예제 #27
0
 void goToStartState()
 {
     gameState = GAME_STATES.START;
     gameUI.DisplayStartOverlay("PACKET PIRATES\nCurrent Map:" + mapNum + "\nPress Options Key to Add Controller.\nHold 'A' to add Keyboard.\nHold Num Key to Select Map.\nHold 'S' key to start.");
 }
예제 #28
0
 public MainMenuState(GAME_STATES id)
 {
     //Salvando o id do estado:
     _id = id;
 }
예제 #29
0
    void StartGame()
    {
        resetLighting();
        int numPlayers = 0;

        if (playerAdded1)
        {
            numPlayers++;
        }
        if (playerAdded2)
        {
            numPlayers++;
        }
        if (playerAdded3)
        {
            numPlayers++;
        }
        if (playerAdded4)
        {
            numPlayers++;
        }
        if (numPlayers < 1)
        {
            return;             // need two players to start
        }


        if (playerAdded1)
        {
            currentMap.p1Towers.ForEach(t => {
                AddPlayerTower((int)t.x, (int)t.y, TILE_TYPE.PLAYER_ONE_GOAL, p1_receiver_mat);
            });
        }
        if (playerAdded2)
        {
            currentMap.p2Towers.ForEach(t => {
                AddPlayerTower((int)t.x, (int)t.y, TILE_TYPE.PLAYER_TWO_GOAL, p2_receiver_mat);
            });
        }
        if (playerAdded3)
        {
            currentMap.p3Towers.ForEach(t => {
                AddPlayerTower((int)t.x, (int)t.y, TILE_TYPE.PLAYER_THREE_GOAL, p3_receiver_mat);
            });
        }
        if (playerAdded4)
        {
            currentMap.p4Towers.ForEach(t => {
                AddPlayerTower((int)t.x, (int)t.y, TILE_TYPE.PLAYER_FOUR_GOAL, p4_receiver_mat);
            });
        }
        currentMap.emitterLocations.ForEach(t => {
            AddEmitter((int)t.x, (int)t.y);
        });
        currentMap.pipeLocations.ForEach(t => {
            AddPipe((int)t.x, (int)t.y, (int)t.z);
        });
        timeRemaining = TOTAL_GAME_TIME;
        gameUI.DestroyOverlay();
        gameUI.CreateTimer();
        gameState = GAME_STATES.PLAYING;
    }
예제 #30
0
 // Use this for initialization
 void Start()
 {
     global_variables.STATE = global_variables.GAME_STATES.NONE;
 }
예제 #31
0
 public GamePlayState(GAME_STATES id)
 {
     //Salvando o id do estado:
     _id = id;
 }
예제 #32
0
        public void PauseState(GAME_STATES newState)
        {
            //Finalizando o estado atual:
            _loadedStates[(int)_activeState].Pause();

            //Salvando o estado anterior:
            _pausedState = _activeState;

            //Definindo o novo estado:
            _activeState = newState;

            //Inicializando o novo estado:
            _loadedStates[(int)_activeState].Init(_game, this);
        }
 public void StartGame()
 {
     currentState = GAME_STATES.game;
     Debug.Log(currentState);
 }
예제 #34
0
    void Update()
    {
        if (quit.Update())
        {
            QuitGame();
            return;
        }

        if (gameState == GAME_STATES.PAUSED)
        {
            if (pause.Update())
            {
                gameState = GAME_STATES.PLAYING;
            }
            return;
        }

        if (gameState == GAME_STATES.START)
        {
            if (keyOne.Update())
            {
                Debug.unityLogger.Log("==Map1");
                mapNum     = 1;
                currentMap = map1;
                updateStartText();
            }
            if (keyTwo.Update())
            {
                Debug.unityLogger.Log("==Map2");
                mapNum     = 2;
                currentMap = map2;
                updateStartText();
            }
            if (keyThree.Update())
            {
                Debug.unityLogger.Log("==Map3");
                mapNum     = 3;
                currentMap = map3;
                updateStartText();
            }
            if (keyFour.Update())
            {
                Debug.unityLogger.Log("==Map4");
                mapNum     = 4;
                currentMap = map4;
                updateStartText();
            }
            if (start.Update())
            {
                StartGame();
            }
        }

        if (pause.Update())
        {
            gameState = GAME_STATES.PAUSED;
        }

        if (playerAdded1)
        {
            HandlePlayerInput(p1controller, KeyCode.Joystick1Button1, "Horizontal1", "Vertical1");
        }
        else
        {
            if (Input.GetKey(KeyCode.Joystick1Button9))
            {
                AddPlayer(1);
            }
        }
        if (playerAdded2)
        {
            HandlePlayerInput(p2controller, KeyCode.Joystick2Button1, "Horizontal2", "Vertical2");
        }
        else
        {
            if (Input.GetKey(KeyCode.Joystick2Button9))
            {
                AddPlayer(2);
            }
        }
        if (playerAdded3)
        {
            HandlePlayerInput(p3controller, KeyCode.Joystick3Button1, "Horizontal3", "Vertical3");
        }
        else
        {
            if (Input.GetKey(KeyCode.Joystick3Button9))
            {
                AddPlayer(3);
            }
        }
        if (playerAdded4)
        {
            HandlePlayerInput(p4controller, KeyCode.Joystick4Button1, "Horizontal4", "Vertical4");
        }
        else
        {
            if (Input.GetKey(KeyCode.Joystick4Button9))
            {
                AddPlayer(4);
            }
        }

        if (keyboardPlayerAdded)
        {
            HandleKeyboardInput();
        }

        if (addKeyboard.Update())
        {
            if (!keyboardPlayerAdded)
            {
                keyboardPlayerAdded = true;
                if (!playerAdded1)
                {
                    AddKeyboardPlayer(AddPlayer(1));
                }
                else if (!playerAdded2)
                {
                    AddKeyboardPlayer(AddPlayer(2));
                }
                else if (!playerAdded3)
                {
                    AddKeyboardPlayer(AddPlayer(3));
                }
                else if (!playerAdded4)
                {
                    AddKeyboardPlayer(AddPlayer(4));
                }
            }
        }

//		Debug.unityLogger.Log("==",Input.GetAxis (axisHName));
//		Debug.unityLogger.Log("y==",Input.GetAxis (axisVName));
        if (gameState == GAME_STATES.PLAYING)
        {
            updateLighting();
            handleGameTime();
            updateEmitters();
            updateEmissions();
        }

        if (playerAdded1)
        {
            p1controller.update();
        }
        if (playerAdded2)
        {
            p2controller.update();
        }
        if (playerAdded3)
        {
            p3controller.update();
        }
        if (playerAdded4)
        {
            p4controller.update();
        }
    }
 // Use this for initialization
 void Start()
 {
     Debug.Log(currentState);
     timer = 0;
     currentState = GAME_STATES.menu;
 }
예제 #36
0
 public StageLostState(GAME_STATES id)
 {
     //Salvando o id do estado:
     _id = id;
 }