protected override Object SpecialInputs(ConsoleKey cki, EDirection currentDirection, EGameState gameState) {
            switch (cki) {
                case ConsoleKey.Escape:
                    if (gameState == EGameState.Running)
                        return gameState == EGameState.Running ? EGameState.Over : EGameState.Running;
                    if (gameState == EGameState.Over || gameState == EGameState.Init)
                        Environment.Exit(0);
                    break;
                case ConsoleKey.Spacebar:
                    return gameState == EGameState.Running ? EGameState.Paused : EGameState.Running;
                case ConsoleKey.Q:
                    if (gameState == EGameState.Init)
                        Environment.Exit(0);
                    if (gameState == EGameState.Over)
                        StartupManager.Reset();
                    break;
                case ConsoleKey.P:
                    if (gameState == EGameState.Init)
                        return EGameState.Running;
                    break;
            }

            if (cki == ConsoleKey.UpArrow && currentDirection != EDirection.South)
                return EDirection.North;
            if (cki == ConsoleKey.RightArrow && currentDirection != EDirection.West)
                return EDirection.East;
            if (cki == ConsoleKey.DownArrow && currentDirection != EDirection.North)
                return EDirection.South;
            if (cki == ConsoleKey.LeftArrow && currentDirection != EDirection.East)
                return EDirection.West;
            return cki;
        }
Beispiel #2
0
    public void Initialize()
    {
        _states = new Dictionary <EGameState, AGameState>();

        InitializeState initializeState = new InitializeState();

        initializeState.Initialize(EGameState.INITIALIZE);
        _states.Add(EGameState.INITIALIZE, initializeState);

        LoadingState loadingState = new LoadingState();

        loadingState.Initialize(EGameState.LOADING);
        _states.Add(EGameState.LOADING, loadingState);

        MainMenuState mainMenuState = new MainMenuState();

        mainMenuState.Initialize(EGameState.MAINMENU);
        _states.Add(EGameState.MAINMENU, mainMenuState);

        GameState gameState = new GameState();

        gameState.Initialize(EGameState.GAME);
        _states.Add(EGameState.GAME, gameState);

        _currentStateType = EGameState.INITIALIZE;
        CurrentState.EnterState();
    }
Beispiel #3
0
 /// <summary>
 /// play game
 /// </summary>
 public void PlayGame()
 {
     if (_gameState == EGameState.EGS_Start || _gameState == EGameState.EGS_WaitStart)
     {
         _gameState = EGameState.EGS_Playing;
     }
 }
    public void StartPlayerMovement(float lenght)
    {
        currentGameState = EGameState.Movement;
        StickHeroPlatform nextPlatform = m_Platforms[counter + 1];
        //находим минимальную длину стика для успешного перехода
        float targetLenght = nextPlatform.transform.position.x - m_Stick.transform.position.x;
        float platformSize = nextPlatform.GetPlatformSize();
        float min          = targetLenght - platformSize * 0.5f;

        min -= m_Player.transform.localScale.x * 0.9f;

        //находим максимальную длину стика для успешного перехода
        float max = targetLenght + platformSize * 0.5f;

        //при успехе переходим в центр платформы, иначе падаем
        if (lenght < min || lenght > max)
        {
            float targetPosition = m_Stick.transform.position.x + lenght + m_Player.transform.localScale.x;
            m_Player.StartMovement(targetPosition, true);
        }
        else
        {
            float targetPosition = nextPlatform.transform.position.x;
            m_Player.StartMovement(targetPosition, false);
            GenerateBlock();
            ShowScore();
        }
    }
Beispiel #5
0
    public void StartPlayerMovement(float length)
    {
        currentGameState = EGameState.Movement;

        StickHeroPlatform nextPlatform = m_Platforms[counter + 1];

        // находим min длину стика
        float targetLength = nextPlatform.transform.position.x - m_Stick.transform.position.x;

        float platformSize = nextPlatform.GetPlatformSize();

        float min = targetLength - platformSize * 0.5f;

        min -= m_Player.transform.localScale.x * 0.9f;

        // находим мах длину стика
        float max = targetLength + platformSize * 0.5f;


        //при успехе переходим в центр следующей платформы
        if (length < min || length > max)
        {
            // будем падать
            float targetPosition = m_Stick.transform.position.x + length + m_Player.transform.localScale.x;

            m_Player.StartMovement(targetPosition, true);
        }
        else
        {
            float targetPosition = nextPlatform.transform.position.x;
            m_Player.StartMovement(targetPosition, false);
            SpawnNext();
        }
    }
Beispiel #6
0
        public override void LoadContent()
        {
            CurrGame     = (PathDefenceGame)ScreenManager.Game;
            LevelManager = new LevelManager(CurrGame, this, levelName);
            LevelManager.Initialize();
            WaveManager = new WaveManager(CurrGame, this, levelName);
            WaveManager.Initialize();
            Background = new BackgroundGamePlayScreen(CurrGame, levelName);
            Background.Initialize();
            TowerManager = new TowerManager(CurrGame, this);
            TowerManager.Initialize();
            MoneyManager = new MoneyManager(CurrGame, this);
            MoneyManager.Initialize();
            LiveManager = new LiveManager(CurrGame, this);
            LiveManager.Initialize();
            PointsManager = new PointsManager();
            PointsManager.Initialize();

            GuiManager = new GuiManager(CurrGame, this);
            GuiManager.Initialize();
            CreepDeleteList.AddRange(CreepList);

            AddCreepList.Clear();

            CreepTimer.Start();

            gameState = EGameState.Running;
            CurrGame.IsMouseVisible = true;
            base.LoadContent();
        }
Beispiel #7
0
        void RemovePlayer(Player player)
        {
            if (Players[player.LocalId] == null)
            {
                return;
            }
            Players[player.LocalId] = null;
            var peer = player.PeerTcp;

            peer?.Dispose();

            player.PeerTcp = null;
            peer           = player.PeerUdp;
            peer?.Dispose();

            player.PeerUdp = null;

            var curCount = CurPlayerCount;

            if (curCount == 0)
            {
                Log("All players left, stopping current simulation...");
                IsRunning = false;
                State     = EGameState.Idle;
                //_gameServer.OnGameEmpty(this);
            }
            else
            {
                Log(curCount + " players remaining.");
            }
        }
Beispiel #8
0
        public void DoStart(int gameId, int gameType, int mapId, Player[] playerInfos, string gameHash)
        {
            State                = EGameState.Loading;
            Seed                 = LRandom.Range(1, 100000);
            Tick                 = 0;
            _timeSinceLoaded     = 0;
            _firstFrameTimeStamp = 0;
            RegisterMsgHandlers();
            Debug = new DebugInstance("Room" + GameId + ": ");
            var count = playerInfos.Length;

            GameType = gameType;
            GameHash = gameHash;
            GameId   = gameId;
            Name     = gameId.ToString();
            MapId    = mapId;
            Players  = playerInfos;
            _userId2LocalId.Clear();
            TimeSinceCreate = LTime.timeSinceLevelLoad;
            for (byte i = 0; i < count; i++)
            {
                var player = Players[i];
                _userId2LocalId.Add(player.UserId, player.LocalId);
            }

            //Temp code
            for (byte i = 0; i < count; i++)
            {
                var player = Players[i];
                player.GameData = new GameData();
                OnRecvPlayerGameData(player);
            }
        }
Beispiel #9
0
 public void ConnectToGameServer(Msg_C2G_Hello helloBody, IPEndInfo _gameTcpEnd, bool isReconnect)
 {
     Log("ConnectToGameServer  " + helloBody + " isReconnect=" + isReconnect);
     IsReconnecting = isReconnect;
     ResetStatus();
     this.helloBody = helloBody.Hello;
     InitNetClient(ref _netTcp, _gameTcpEnd.Ip, _gameTcpEnd.Port, () => {
         HasConnGameTcp = true;
         CurGameState   = EGameState.Loading;
         _netTcp.SendMessage(EMsgSC.C2G_Hello, helloBody, (status, respond) => {
             if (status != EResponseStatus.Failed)
             {
                 var rMsg    = respond.Parse <Msg_G2C_Hello>();
                 _curMapId   = rMsg.MapId;
                 _localId    = rMsg.LocalId;
                 _gameUdpEnd = rMsg.UdpEnd;
                 _handler.OnTcpHello(rMsg);
                 ConnectUdp();
             }
             else
             {
                 _handler.OnGameStartFailed();
             }
         }
                             );
     });
 }
Beispiel #10
0
 public void ChangeState(EGameState newState)
 {
     Debug.Log("Transition from " + _currentStateType + " to " + newState);
     CurrentState.ExitState();
     _currentStateType = newState;
     CurrentState.EnterState();
 }
Beispiel #11
0
 private void StartCountDown()
 {
     this.DisableMenus();
     gameState      = EGameState.Countdown;
     Time.timeScale = 1;
     timerScript.Restart();
 }
Beispiel #12
0
        /// <summary>
        /// Найти ячейку в массиве и выставить ей значение
        /// </summary>
        /// <param name="iX"></param>
        /// <param name="iY"></param>
        /// <param name="eValue"></param>
        public bool SetValue(int iX, int iY)
        {
            if (State != EGameState.Game)
            {
                return(false);
            }
            Cell pFoundCell = h_GetCell(iX, iY);

            if (pFoundCell != null)
            {
                if (pFoundCell.Value == EValue.Empty)
                {
                    pFoundCell.Value = CurrentTurn;

                    if (h_IsGameOver())
                    {
                        State = EGameState.GameOver;
                        return(true);
                    }

                    h_NextTurn();

                    if (CurrentTurn == EValue.O)
                    {
                        h_AITurn();
                        return(true);
                    }

                    return(true);
                }
            }
            return(false);
        }
    // Update is called once per frame
    void Update()
    {
        if (_player.IsDead)
        {
            _state = EGameState.Lost;
            StartCoroutine("StartEndScene");
        }

        if (_cells.Count == 0 || _state != EGameState.None)
        {
            return;
        }

        bool isWon = true;

        foreach (CellController cell in _cells)
        {
            if (cell.HealNeeded > 0)
            {
                isWon = false;
                break;
            }
        }

        if (isWon)
        {
            _state = EGameState.Won;
            StartCoroutine("StartEndScene");
        }
    }
Beispiel #14
0
 /// <summary>
 /// resume game
 /// </summary>
 public void ResumeGame()
 {
     if (_gameState == EGameState.EGS_Paused)
     {
         _gameState = EGameState.EGS_Playing;
     }
 }
Beispiel #15
0
    void OnInTimelineReachEnd()
    {
        nextState = EGameState.GlyphTable;

        runningTrackManager.onReachEnd -= OnInTimelineReachEnd;
        hitManager.onHit -= OnInTimelineObstacleHit;
    }
Beispiel #16
0
    protected override void DidEnterGameState(EGameState gameState, EGameState fromState)
    {
        base.DidEnterGameState(gameState, fromState);

        switch (gameState)
        {
        case EGameState.Intro:
            cameraController.SwitchToCamera("Intro");
            break;

        case EGameState.Play:
            cameraController.CopyPositionFromActive(gameCam);
            float camLerpTime = fromState == EGameState.Intro ? 2f : 0.5f;
            cameraController.LerpToCamera("Game", camLerpTime);
            if (fromState != EGameState.Paused && fromState != EGameState.Map)
            {
                ResetKobotos();
            }
            MusicPlayer.Instance.PlayTrack(musicTrack, true);
            break;

        case EGameState.Map:
            mapCam.SetFocus(gameCam.target.position, 30f);
            cameraController.LerpToCamera("Map", 0.5f);
            MusicPlayer.Instance.PlayTrack(MusicTrack.Pause, false);
            break;

        case EGameState.Won:
            cameraController.LerpToCamera("Win", 0.5f);
            MusicPlayer.Instance.PlayTrack(MusicTrack.WinLevel, true);
            break;
        }
    }
Beispiel #17
0
    public void RestartGame()
    {
        var enemiesLeft = GameObject.FindGameObjectsWithTag("Enemy");

        foreach (var enemy in enemiesLeft)
        {
            Destroy(enemy.gameObject);
        }

        LevelFailedMenu.SetActive(false);

        PlayerObject.MaxHealth = 100;

        CurrentLevel = 1;

        ActiveGameState = EGameState.LevelComplete;

        CurrentScore = 0;

        previousScore = -1;

        PlayerObject.GetComponent <PlayerController>().OnPlayerDied();

        var spawnedCoins = GameObject.FindGameObjectsWithTag("Props");

        foreach (GameObject coin in spawnedCoins)
        {
            Destroy(coin.gameObject);
        }
    }
Beispiel #18
0
 void OnGameOverBottomTrigger()
 {
     runningTrackManager.Reset();
     runningTrackManager.gameObject.SetActive(true);
     nextState = EGameState.Preparation;
     inputManager.onTrigger -= OnGameOverBottomTrigger;
 }
Beispiel #19
0
    private void SetState(EGameState state)
    {
        CurrentState = state;

        if (m_CurrentState)
        {
            m_CurrentState.OnExit();
        }

        switch (state)
        {
        case EGameState.EnterNameState:
            m_CurrentState = m_enterNameState;
            break;

        case EGameState.ChatRoomState:
            m_CurrentState = m_chatRoomState;
            break;
        }

        if (m_CurrentState)
        {
            m_CurrentState.OnEnter();
        }

        if (OnStateChange != null)
        {
            OnStateChange(CurrentState);
        }
    }
Beispiel #20
0
 protected override void WillExitGameState(EGameState gameState, EGameState toState)
 {
     if ((gameState & stateMask) == gameState && (gameState & stateMask) != toState)
     {
         SetActive(false);
     }
 }
Beispiel #21
0
    protected override void DidEnterGameState(EGameState gameState, EGameState fromState)
    {
        base.DidEnterGameState(gameState, fromState);
        if (gameState == EGameState.Intro || (gameState == EGameState.Play && fromState == EGameState.Lost))
        {
            if (defaultMaterial == null)
            {
                defaultMaterial = Resources.Load <Material>("Materials/tokenDefault");
            }
            if (ghostMaterial == null)
            {
                ghostMaterial = Resources.Load <Material>("Materials/tokenFade");
            }
            if (renderers == null)
            {
                renderers = GetComponentsInChildren <MeshRenderer>();
            }

            LoadCollectedState();
        }
        else if (gameState == EGameState.Won)
        {
            if (collected && !alreadyCollected)
            {
                GameEvents.Trigger <BonusTokenData>(EGameEvent.CollectedBonusToken, new BonusTokenData {
                    worldNumber = worldNumber, levelNumber = levelNumber, index = index
                });
            }
        }
    }
    /// <summary>
    /// ゲームの準備ステートを開始する
    /// </summery>
    private void mSetGameReady()
    {
        // カード配布アニメーションが終了した後のコールバック処理を実装する
        this.CardCreate.OnCardCreateComp = null;
        this.CardCreate.OnCardCreateComp = () => {
            // ゲームステートをGAME状態にする
            this.mEGameState = EGameState.GAME;
            this.mSetGameState();
        };

        // 一致したカードIDリストを初期化
        this.mContainCardInfoList.Clear();

        // カードリストを生成する
        this.CardCreate.CreateCard();

        // 現在のターンを初期化
        currentTurn = FIRST;

        // ポイント初期化
        // 先攻
        firstTurnPoint = 0;
        // 後攻
        secondTurnPoint = 0;
    }
Beispiel #23
0
        /// <summary>
        /// Handles the GameStateChange, pretty basic
        /// </summary>
        public void handleGameState()
        {
            Console.Out.Write("GameState change! \n");

            switch (currentGameState)
            {
                case EGameState.MainMenu:
                    gameState = new GameStates.MainMenu();
                    break;
                case EGameState.InGame:
                    gameState = new GameStates.InGame();
                    break;
                case EGameState.Credits:
                    gameState = new GameStates.Credits();
                    break;
                case EGameState.Options:
                    gameState = new GameStates.Options();
                    break;
            }

            gameState.loadContent();

            gameState.initialize();

            prevGameState = currentGameState;
        }
    public void Reset()
    {
        _movesToNextPipe    = Consts.TURNS_TO_NEXT_PIPE;
        _allTurns           = 0; // for leveled too
        _pipesAdded         = 0;
        _pipesToNextBlocker = Consts.PIPES_TO_NEXT_BLOCKER;
        _pointsForSequences = 0;
        for (int i = 0; i < _resources.Count; ++i)
        {
            _resources[i] = 0;
        }
        GameState  = EGameState.Pause;
        TimePlayed = 0;
        DragSlot   = null;
        AddsViewed = false;

//		// leveled
//		StarsGained = 0;
//		MovesLeft = 0;
//		//

//        // powerups
//        EventData eventData = new EventData("OnPowerUpsResetNeededEvent");
//        //eventData.Data["isforce"] = true;
//        GameManager.Instance.EventManager.CallOnPowerUpsResetNeededEvent(eventData);
    }
    //

    public GameBoardData()
    {
        _movesToNextPipe = 0;
        if (GameBoard.AddingType != EAddingType.OnNoMatch)
        {
            _movesToNextPipe = Consts.TURNS_TO_NEXT_PIPE;
        }
        _allTurns           = 0;
        _pipesAdded         = 0;
        _pipesToNextBlocker = Consts.PIPES_TO_NEXT_BLOCKER;
        _pointsForSequences = 0;
        _resources          = new List <long>();
        for (int i = 0; i < Consts.CLASSIC_GAME_COLORS; ++i)
        {
            _resources.Add(0);
            //SetResourceForce(0, i);
        }
        AddsViewed = false;
        GameState  = EGameState.Pause;
        TimePlayed = 0;
        DragSlot   = null;
        PowerUps   = new Dictionary <GameData.PowerUpType, int>();
        foreach (GameData.PowerUpType powerUp in Enum.GetValues(typeof(GameData.PowerUpType)))
        {
            PowerUps.Add(powerUp, 0);
        }
    }
        private void Awake()
        {
            DontDestroyOnLoad(this);
#if !BOLT_CLOUD
            m_GameState = EGameState.Menu;
#endif
        }
Beispiel #27
0
 /// <summary>
 /// pause game
 /// </summary>
 public void PauseGame()
 {
     if (_gameState == EGameState.EGS_Playing)
     {
         _gameState = EGameState.EGS_Paused;
     }
 }
Beispiel #28
0
        public void DoStart(IGameServer server, int gameId, int gameType, int mapId, GamePlayerInfo[] playerInfos,
                            string gameHash)
        {
            State               = EGameState.Loading;
            _gameServer         = server;
            Seed                = LRandom.Range(1, 100000);
            Tick                = 0;
            timeSinceLoaded     = 0;
            firstFrameTimeStamp = 0;
            RegisterMsgHandlers();
            Debug = new DebugInstance("Room" + GameId + ": ");
            var count = playerInfos.Length;

            GameType       = gameType;
            GameHash       = gameHash;
            GameId         = gameId;
            MaxPlayerCount = (byte)count;
            Name           = gameId.ToString();
            MapId          = mapId;
            Players        = new Player[count];
            for (byte i = 0; i < count; i++)
            {
                var user   = playerInfos[i];
                var player = CreatePlayer(user, i);
                Players[i] = player;
            }

            _userId2LocalId.Clear();
            TimeSinceCreate = LTime.timeSinceLevelLoad;
            for (byte i = 0; i < count; i++)
            {
                var player = Players[i];
                _userId2LocalId.Add(player.UserId, player.LocalId);
            }
        }
    public EGameState ProcessTurn(EGameState whoseTurn)
    {
        EGameState whoseNextTurn = whoseTurn;

        switch (whoseTurn)
        {
        case EGameState.PlayerTurn:
            this.playerController.TakeTurn();
            if (this.playerController.IsTurnFinished())
            {
                whoseNextTurn = EGameState.AITurn;
            }
            break;

        case EGameState.AITurn:
            this.aiController.TakeTurn();
            if (this.aiController.IsTurnFinished())
            {
                whoseNextTurn = EGameState.PlayerTurn;
            }
            break;

        default:
            break;
        }
        return(whoseNextTurn);
    }
Beispiel #30
0
 public override void StateListener(EGameState state){
     if (state == EGameState.Running) {
         _t2.Start();
     } else if (state == EGameState.Paused && _t2.ElapsedMilliseconds <= 300) {
         _t2.Stop();
     }
 }
Beispiel #31
0
    protected override void Init(EGameState gameState)
    {
        levelObjects = new List <LevelObjectBase>(GetComponentsInChildren <LevelObjectBase>());

        levelZones = new List <LevelZone>();
        var cameraZones = new List <LevelZoneCameraForbidden>();

        LevelZoneWorld worldZone = null;


        foreach (var zone in GetComponentsInChildren <LevelZone>())
        {
            if (zone is LevelZoneWorld)
            {
                worldZone = zone as LevelZoneWorld;
            }
            else if (zone is LevelZoneCameraForbidden)
            {
                cameraZones.Add(zone as LevelZoneCameraForbidden);
            }
            else
            {
                levelZones.Add(zone);
            }
        }
        levelBounds = worldZone.GetBounds();
        cameraController.SetCameraForbiddenZones(worldZone, cameraZones);
    }
Beispiel #32
0
    void ResetPlayerState()
    {
        CurrentBuildingIndex = 0;
        CurrentFloorIndex    = 0 - CurrentBuilding.BaseLevel;

        CameraManager.currentFloor = CurrentBuilding.Floors[CurrentFloorIndex];
        CameraManager.Snap();

        TimeLeft   = TIME_LEFT;
        TimePlayed = 0f;
        Score      = 0;

        CurrentGameState      = EGameState.GamePlay;
        CameraManager.enabled = true;
        CameraManager.UpdateArrows();

        if (!IsFirstGame)
        {
            timerContainer.SetActive(true);
        }

        RemoveObjectOfHand();
        CurrentFloor.Reveal(true);

        CurrentFloor.LightsOff();

        GameOverText.gameObject.SetActive(false);
        gameOverPanel.gameObject.SetActive(false);
    }
    public void SetTheResultText(EGameState state)
    {
        string text = "";

        switch (state)
        {
        case EGameState.NONE:
            text = "RESULT";
            break;

        case EGameState.PUSH:
            text = "Push!";
            break;

        case EGameState.BUST:
            text = "Bust!";
            break;

        case EGameState.WON:
            text = "Won!";
            break;
        }
        _resultText.text = text;
        _resultPanel.gameObject.SetActive(true);
        GameOver();
    }
Beispiel #34
0
        void Update()
        {
            if (prev != curr)
            {
                HandleGameState();
                prev = curr;
            }

            curr = state.Update(gTime);
        }
    ////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
    public void OnPlayerDetected()
    {
        _currentState = EGameState.E_END_GAME_PLAYER_DETECTED;
        guiController.OnEndGame(_currentState);

        //Not necessary because now all enemies are subscribed to the OnPlayerDetectedEvent
        //Disable all enemies
        //foreach(EnemyController enemy in getEnemies()){
        //	enemy.OnEndGame();
        //}
    }
    public void StartTheRun(CardElement card)
    {
        m_curentHero = card;

        GameObject.FindObjectOfType<PlayableCharacter>().LoadPlayerFromCard(m_curentHero);
        m_curentState = EGameState.GAME;
        Time.timeScale = 1;
        GameObject[] objs = GameObject.FindGameObjectsWithTag("Ennemies");
        foreach(GameObject obj in objs)
        {
            obj.GetComponent<Rigidbody2D>().isKinematic = false;
        }
        //load un hero avec ces infos
        //play le game
    }
Beispiel #37
0
        /// <summary>
        /// Changes to the input state.
        /// </summary>
        /// <param name="a_state">State to change to.</param>
        public void ChangeToState(EGameState a_state)
        {
            // Switch on and off game components to match state
            switch (a_state)
            {
                case EGameState.PREGAME:
                    {
                        beginText.SetActive(true);
                        gameOverText.SetActive(false);

                        break;
                    }
                case EGameState.PLAY:
                    {
                        beginText.SetActive(false);

                        // Resume time during game
                        Time.timeScale = 1.0f;

                        break;
                    }
                case EGameState.GAMEOVER:
                    {
                        gameOverText.SetActive(true);

                        // Short wait before replaying
                        m_replayWait = 1.0f;

                        // Freeze time during game over
                        Time.timeScale = 0.0f;

                        break;
                    }
                case EGameState.NONE:
                    {
                        Debug.LogWarning("Changing to NONE gameplay state!");
                        break;
                    }
                default:
                    {
                        break;
                    }
            }

            // Apply state change
            m_prevState = m_currState;
            m_currState = a_state;
        }
    ////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
    public void OnEnemyKilled()
    {
        _remainingEnemies--;

        //All enemies are dead
        if(_remainingEnemies <= 0){
            _currentState = EGameState.E_END_GAME_WIN;
            guiController.OnEndGame(_currentState);

            //Not necessary because all coroutines are disabled when an enemy has been killed
            //Disable all enemies
            //foreach(EnemyController enemy in getEnemies()){
            //	enemy.OnEndGame();
            //}
        }
    }
Beispiel #39
0
 public GameManager(EGameState state,IServiceProvider ServiceProvider)
 {
     cur_state = state;
     options = new Options();
     options.DisplayModeChanged += new DisplayModeChangedEventHandler(options_DisplayModeChanged);
     options.ResolutionChanged += new ResolutionChangedEventHandler(options_ResolutionChanged);
     game = new SGame(ServiceProvider);
     inputhandler = new Inputhandler(Vector2.Zero,options);
     menu = new SMenu(ServiceProvider);
     serviceprovider = ServiceProvider;
     content = new ContentManager(serviceprovider, "Data");
     music = new Music();
     credits = new SCredits(serviceprovider);
     pthreadManager = new ParticleThreadManager();
     gameTimes = new TimeSpan[numberOfTimes];
     for (int i = 0; i < numberOfTimes; i++)
     {
         gameTimes[i] = new TimeSpan(0, 0, 0, 0, 16);
     }
 }
        /**
         * Set game state
         */
        public static void SetState(EGameState newState)
        {
            GameStateManager instance = GetInstance();

            instance.currentState = newState;

            foreach(StateConfig config in instance.stateConfigs)
            {
                bool isMatch = config.state == newState;

                if(config.ui != null)
                {
                    config.ui.SetActive(isMatch);
                }

                if(isMatch)
                {
                    TimeManager.SetTime(config.timeScale);
                    InputManager.ToggleSceneInput(config.sceneInput);
                }
            }
        }
Beispiel #41
0
        public Game1()
        {
            Content.RootDirectory = "Content";
            content = Content;

            sounds = new SoundCollection();
            sounds.menuSound.Play();

            ownTime = new ownGameTime();

            currentGameState = EGameState.MainMenu; //tells GameState where so start //change back to main menu
            handleGameState();

            //graphicsDevice = GraphicsDevice;
            graphics = new GraphicsDeviceManager(this);
            //fullscreen
            graphics.IsFullScreen = Settings.isFullscreen();
            //fenstergröße
            Settings.setResolutionX(1280);// 1366, 1280, 1920
            graphics.PreferredBackBufferHeight = Settings.getResolutionY();
            graphics.PreferredBackBufferWidth = Settings.getResolutionX();
        }
Beispiel #42
0
    public void RestartLevel(int size)
    {
        GridSize = size;
        Menu.SetActive(false);

        GameState = EGameState.Game;

        foreach(GridCellComp cellComp in CellCompList)
        {
            GameObject.Destroy(cellComp.gameObject);
        }
        CellCompList.Clear();

        if (DragChess)
        {
            GameObject.Destroy(DragChess.gameObject);
        }

        GridData = new int[GridSize, GridSize];

        float beginX = -(GridSize - 1) / 2 * CellOffset;
        float beginY = -(GridSize - 1) / 2 * CellOffset;

        for (int i = 0; i < GridSize; i++)
        {
            for (int j = 0; j < GridSize; j++)
            {
                GameObject gridPrefab = Resources.Load<GameObject>("GridCell");
                GameObject newGrid = (GameObject)GameObject.Instantiate(gridPrefab);
                newGrid.transform.position = new Vector3(j * CellOffset + beginX, i * CellOffset + beginY);
                GridCellComp gridCellComp = newGrid.GetComponent<GridCellComp>();
                gridCellComp.gridX = j;
                gridCellComp.gridY = i;
                CellCompList.Add(gridCellComp);
            }
        }
        ShowDrawChess();
    }
    public void SetCurLevel()
    {
        string levelName = Application.loadedLevelName;
        Debug.Log(Application.loadedLevelName);

        m_curentHero = null;
        m_idDeads = new List<int>();

        Debug.LogError("SetLevel");

        if (levelName.Contains(m_menuScene))
        {
            m_currentSceneId = -1;
            m_curentState = EGameState.MENU;
        }
        else
        {
            m_currentSceneId = int.Parse(levelName.Split(new char[] { '_', '.' })[1]);
            m_curentState = EGameState.SELECTION;
            StartCoroutine(DisplayDeckOrder(1));
        }
        Debug.Log(this.GetInstanceID());
    }
Beispiel #44
0
        private void intelligentClick_DoWork(object sender, DoWorkEventArgs e)
        {
            if(useWugongPredict==null)
            {
                useWugongPredict = new Predicate<int>(x=>this._killed == this._killedOfNine);
            }
            this._state = EGameState.搜索;
            while (!this.intelligentClickCancelled)
            {
                if (!this._settings._noSkill && this._lanYao <= this._settings._runAwayLanYao && this._xueYao > this._settings._runAwayXueYao)
                {
                    this._settings._noSkill = true;
                    this.intelligentClick.ReportProgress(100);
                }
                if (this._xueYao <= this._settings._runAwayXueYao)
                {
                    this.RunAway();
                    this._state = EGameState.未知;
                    Thread.Sleep(3000);
                }
                else
                {
                    switch (this._state)
                    {
                        case EGameState.搜索:
                            while (!this.intelligentClickCancelled && this._settings._simulateMouse)
                            {
                                if (this._settings._back)
                                {
                                    this.GetBack();
                                }
                                this.FindTarget();
                                if (this._target.mouseShape == EMouseShape.Kill)
                                {
                                    if (!this.intelligentClickCancelled && this._settings._simulateMouse)
                                    {
                                        MouseSimulator.Position = this._target.location;
                                        if (this._settings._noSkill)
                                        {
                                            if (this._lanNow + this._lanNow >= this._lanFull)
                                            { MouseSimulator.Click(MouseButton.Right); }
                                            else
                                            { MouseSimulator.Click(MouseButton.Left); }
                                        }
                                        else
                                        {
                                            MouseSimulator.Click(MouseButton.Right);
                                        }
                                        this._state = EGameState.定位;
                                        break;
                                    }
                                    break;
                                }
                                else
                                {
                                    if (this._target.mouseShape == EMouseShape.Get)
                                    {
                                        if (this.intelligentClickCancelled || !this._settings._simulateMouse)
                                        {
                                            break;
                                        }
                                        MouseSimulator.Position = this._target.location;
                                        MouseSimulator.Click(MouseButton.Right);
                                        Thread.Sleep(2500);
                                    }
                                    else
                                    {
                                        if (!this._settings._simulateMouse)
                                        {
                                            break;
                                        }
                                    }
                                }
                            }
                            this._state = EGameState.定位;
                            break;
                        case EGameState.定位:
                            this._killed = this._killedOfNine;
                            if (this._settings._noSkill)
                            {
                                this._state = EGameState.打怪;
                            }
                            else
                            {
                                var current = DateTime.Now.Second;
                                while ((this._killed == this._killedOfNine) && ((DateTime.Now.Second + 60 - current) % 60 <= 2))
                                {
                                    Thread.Sleep(10);
                                }
                                if (this._killed != this._killedOfNine)
                                {
                                    this.FindWupin();
                                    if (this._target.mouseShape == EMouseShape.Get)
                                    {
                                        MouseSimulator.Position = this._target.location;
                                        MouseSimulator.Click(MouseButton.Right);
                                        Thread.Sleep(701);
                                    }
                                }
                                if (!this.intelligentClickCancelled && this.UseWugong(2000, useWugongPredict) && this._settings._simulateMouse)
                                {
                                    this._state = EGameState.打怪;
                                }
                                else
                                {
                                    this._state = EGameState.搜索;
                                }
                            }
                            break;
                        case EGameState.打怪:
                            if (this._settings._noSkill)
                            {
                                int num = 100;
                                this._usedTime = this._settings._noSkillInterval;
                                while (this._usedTime > 0)
                                {
                                    Thread.Sleep(num);
                                    if (this._killed != this._killedOfNine)
                                    {
                                        break;
                                    }
                                    this._usedTime -= num;
                                    if (this._lanNow * 20 <= this._lanFull)
                                    { break; /*MouseSimulator.Click(MouseButton.Left);*/ }
                                }
                            }
                            else
                            {
                                int minute = DateTime.Now.Minute;

                                while(true)
                                {
                                    if (this.intelligentClickCancelled) break;
                                    if (!(this._settings._simulateMouse)) break;
                                    if (!this.UseWugong(2000, useWugongPredict))
                                    {
                                        if (this._killed != this._killedOfNine)
                                        {
                                            this.FindWupin();
                                            if (this._target.mouseShape == EMouseShape.Get)
                                            {
                                                MouseSimulator.Position = this._target.location;
                                                MouseSimulator.Click(MouseButton.Right);
                                                Thread.Sleep(701);
                                            }
                                        }
                                        break;
                                    }
                                    if ((DateTime.Now.Minute + 60 - minute) % 60 > 5) break;
                                }
                            }
                            this._state = EGameState.搜索;
                            break;
                        case EGameState.未知:
                            this._state = EGameState.搜索;
                            break;
                        default:
                            this._state = EGameState.搜索;
                            break;
                    }
                }
            }
        }
Beispiel #45
0
        protected override void Update(GameTime gameTime)
        {
            #region Update of current GameState
            switch (this.gameState)
            {
                case EGameState.Nothing:
                    // do nothing
                    break;

                case EGameState.StartScreen:
                    currentState = this.startScreen.Update(gameTime);
                    if (currentState != EGameState.StartScreen)
                        this.GameState = currentState;
                    break;

                case EGameState.MainMenu:
                    currentState = this.menu.Update(gameTime);
                    if (currentState != EGameState.MainMenu)
                        this.GameState = currentState;
                    break;

                case EGameState.Singleplayer:
                    currentState = this.singlePlayer.Update(gameTime);
                    if (currentState != EGameState.Singleplayer)
                        this.GameState = currentState;
                    break;

                case EGameState.Arena:
                    currentState = this.arena.Update(gameTime);
                    if (currentState != EGameState.Arena)
                        this.GameState = currentState;
                    break;

                case EGameState.Multiplayer:
                    currentState = this.multiPlayer.Update(gameTime);
                    if (currentState != EGameState.Multiplayer)
                        this.GameState = currentState;
                    break;

                case EGameState.Continue:
                    currentState = this.cont.Update(gameTime);
                    if (currentState != EGameState.Continue)
                        this.GameState = currentState;
                    break;

                case EGameState.GameOver:
                    currentState = this.gameOver.Update(gameTime);
                    if (currentState != EGameState.GameOver)
                        this.GameState = currentState;
                    break;

                case EGameState.Credits:
                    currentState = this.credits.Update(gameTime);
                    if (currentState != EGameState.Credits)
                        this.GameState = currentState;
                    break;

            }
            #endregion

            base.Update(gameTime);
        }
Beispiel #46
0
        protected override void LoadContent()
        {
            //Create a new SpriteBatch, which can be used to draw textures.
            spriteBatch = new SpriteBatch(GraphicsDevice);

            // Gamestate am Anfang
            // zum Testen jeweiligen GameState einsetzen
            this.GameState = EGameState.MainMenu;
        }
Beispiel #47
0
        public override void LoadContent()
        {
            CurrGame = (PathDefenceGame)ScreenManager.Game;
            LevelManager = new LevelManager(CurrGame, this, levelName);
            LevelManager.Initialize();
            WaveManager = new WaveManager(CurrGame, this, levelName);
            WaveManager.Initialize();
            Background = new BackgroundGamePlayScreen(CurrGame, levelName);
            Background.Initialize();
            TowerManager = new TowerManager(CurrGame, this);
            TowerManager.Initialize();
            MoneyManager = new MoneyManager(CurrGame, this);
            MoneyManager.Initialize();
            LiveManager = new LiveManager(CurrGame, this);
            LiveManager.Initialize();
            PointsManager = new PointsManager();
            PointsManager.Initialize();

            GuiManager = new GuiManager(CurrGame, this);
            GuiManager.Initialize();
            CreepDeleteList.AddRange(CreepList);

            AddCreepList.Clear();

            CreepTimer.Start();

            gameState = EGameState.Running;
            CurrGame.IsMouseVisible = true;
            base.LoadContent();
        }
Beispiel #48
0
    public void FillRandomGrid()
    {
        int gridX = 0;
        int gridY = 0;

        if(GridSize == 5)
        {
            List<int> freeAroundList = new List<int>();

            int x = 0;
            int y = 0;

            x = LastPlayerX + 1;
            y = LastPlayerY;
            if(x>=0 && x<GridSize && y>=0 && y<GridSize && GridData[y, x] == 0)
            {
                freeAroundList.Add(y*GridSize+x);
            }

            x = LastPlayerX;
            y = LastPlayerY + 1;
            if (x >= 0 && x < GridSize && y >= 0 && y < GridSize && GridData[y, x] == 0)
            {
                freeAroundList.Add(y * GridSize + x);
            }

            x = LastPlayerX;
            y = LastPlayerY - 1;
            if (x >= 0 && x < GridSize && y >= 0 && y < GridSize && GridData[y, x] == 0)
            {
                freeAroundList.Add(y * GridSize + x);
            }

            x = LastPlayerX - 1;
            y = LastPlayerY;
            if (x >= 0 && x < GridSize && y >= 0 && y < GridSize && GridData[y, x] == 0)
            {
                freeAroundList.Add(y * GridSize + x);
            }

            if(freeAroundList.Count > 0)
            {
                int index2 = freeAroundList[Random.Range(0, freeAroundList.Count - 1)];

                gridX = index2 % GridSize;
                gridY = index2 / GridSize;

                print("电脑填入: " + gridY + " " +  gridX);
                GridData[gridY, gridX] = 2;

                GridCellComp gridCellComp2 = CellCompList[index2];

                GameObject newChess2 = GameObject.Instantiate(OtherChessPrefab) as GameObject;
                newChess2.transform.parent = gridCellComp2.transform;
                newChess2.transform.localPosition = Vector3.zero;

                ShowDrawChess();

                if(CheckEnd())
                {
                    GameState = EGameState.End;
                    ShowWait();
                }
                return;
            }
        }


        List<int> freeIndexList = new List<int>();
        for (int i = 0; i < GridSize; i++)
        {
            for (int j=0; j<GridSize; j++)
            {
                if (GridData[i, j] == 0)
                {
                    freeIndexList.Add(i * GridSize + j); 
                }
            }
        }

        int index = freeIndexList[Random.Range(0, freeIndexList.Count - 1)];

        gridX = index % GridSize;
        gridY = index / GridSize;

        print("电脑填入: " + gridY + " " +  gridX);
        GridData[gridY, gridX] = 2;

        GridCellComp gridCellComp = CellCompList[index];

        GameObject newChess = GameObject.Instantiate(OtherChessPrefab) as GameObject;
        newChess.transform.parent = gridCellComp.transform;
        newChess.transform.localPosition = Vector3.zero;

        ShowDrawChess();

        if(CheckEnd())
        {
            GameState = EGameState.End;
            ShowWait();
        }
        
        
    }
Beispiel #49
0
    void Update()
    {
        switch(_CurGameState)
        {
        case EGameState.GameStart:
            CheckItemClick();
            break;
        case EGameState.GamePlaying:
        {
            if(curCDTime < cdTime)
            {
                curCDTime += Time.deltaTime;
            }
            else{
                CheckItemClick();
            }

            break;
        }
        case EGameState.GameResult:
            {
                if(Input.anyKeyDown)
                {
                    _CurItemGroupIndex = (_CurItemGroupIndex+1)%_TotalItemGroupIndex;
                    Init();

                    _CurGameState = EGameState.GamePlaying;

                    cdTime = 1.0f;
                    curCDTime = 0;
                }
                break;
            }
        }
    }
Beispiel #50
0
 public void StopGame()
 {
     ChangeInformation();
     gameState = EGameState.Paused;
     WaveManager.StopAutoWave();
 }
Beispiel #51
0
        public bool ChangeActivePlayer()
        {
            if (state == EGameState.StateFirstTown || state == EGameState.StateGame)
            {
                activePlayerIndex++;
                if (activePlayerIndex == players.Count)
                {
                    switch (state)
                    {
                        case EGameState.StateFirstTown :
                            activePlayerIndex--;
                            state = EGameState.StateSecondTown;
                            break;
                        case EGameState.StateGame :
                            activePlayerIndex = 0;
                            break;
                    }
                }
            } else {
                activePlayerIndex--;
                if (activePlayerIndex < 0)
                {
                    ChangeStateToStateGame();
                    activePlayerIndex = 0;
                }
            }

            activePlayer = players[activePlayerIndex];

            if (state == EGameState.StateGame && activePlayerIndex == 0)
                turnNumber++;

            if (!activePlayer.GetActive())
                return ChangeActivePlayer();

            return true;
        }
Beispiel #52
0
        public bool StartGame()
        {
            gameCount++;
            tutorial = false;
            PrepareCampaignScenario();

            playerCount = players.Count;

            medailOwner = new Player[(int) Building.Count];
            for (int loop1 = 0; loop1 < players.Count; loop1++)
            {
                medailOwner[loop1] = null;
            }

            IComponentAI AI;
            int[][] setArray;
            for(int loop1 = 0; loop1 < players.Count; loop1++)
            {
                setArray = players[loop1].GetPersonality();
                players[loop1] = new Player(players[loop1].GetName(), players[loop1].GetColor(), players[loop1].GetComponentAI(), loop1, setArray, players[loop1].GetGen());
                AI = players[loop1].GetComponentAI();

                if (AI != null) // its computer then
                {
#if GENETIC
                    // GENETICS ALG
                    if (players[loop1].GetGen() &&
                        (gameCount - 1) % geneticFitnessRound == 0)
                    {
                        chromozone = genetic.GetChromozone();
                        setArray = chromozone;

                        // uncomment next line for finding your fitness
                        //players[loop1] = new Player(players[loop1].GetName(), players[loop1].GetColor(), null, loop1, setArray, players[loop1].GetGen());
                    }

                    if (!players[loop1].GetGen())
                    {
                        if (bosses == null)
                            setArray = genetic.GetBestOnePersonality(); // reference AI is the best AI in all population
                        else
                            setArray = bosses[(gameCount - 1) % geneticFitnessRound]; // reference AI is contant
                    }
                    // GENETICS 
#endif

                    AI.InitAIComponent(map.GetMapController(), setArray);
                }
            }

            state = EGameState.BeforeGame;
            PrepareCampaignMap();
            
            activePlayerIndex = 0;
            activePlayer = players.ElementAt(activePlayerIndex);
            targetPlayer = activePlayer;

            pausedNew = false;
            paused = false;
            winnerNew = false;

            hasAIThreadStarted = false;

            if(players[0].GetBuildingCount(Building.Town) == 0)
                state = EGameState.StateFirstTown;
            else
                state = EGameState.StateGame;

            fortState = EFortState.Normal;

            randomNumber = new System.Random();
            hasBuiltTown = false;
            turnNumber = 1;

            if (playerCount == 1)
            {
                Settings.banFortStealSources = true;
                Settings.banFortCaptureHexa = true;
            }
            if (Settings.pointsFortParade == 0)
                Settings.banFortParade = true;
            if (Settings.banChangeSources)
                Settings.banMarket = true;

            PromptWindow.Inst().Deactive();
            Message.Inst().ClearMessages();
            MarketComponent.Inst().SetIsActive(false);
            PathNode.SetIsValid(false);

            if(tutorial)
                Tutorial.Inst().TurnOn();
            StartTurn();
            return true;
        }
Beispiel #53
0
 private void CheckGameStateChange(EGameState tempState)
 {
     if (tempState != cur_state)
     {
         oldState = cur_state;
         cur_state = tempState;
         drawnOldState = false;
         oldStateRectangle = new Rectangle(0, 0, options.ScreenWidth, options.ScreenHeight);
         curStateRectangle = new Rectangle(0, 0, options.ScreenWidth, options.ScreenHeight);
         curStateScale = .7f;
         oldStateScale = 1f;
         if (cur_state == EGameState.Game)
         {
             music.GraphXPackChanged(game.Level.LevelVariables.Dictionary[Game.Level.LV.GraphXPack]);
             music.StartCategoryTransition(true);
             inputhandler = new Inputhandler(game.Player.Pos, options);
         }
         else if (cur_state == EGameState.Menu && oldState == EGameState.Game)
         {
             music.StartCategoryTransition(false);
         }
         else if (cur_state == EGameState.Credits)
         {
             credits.ResetCredits(options.Resolution);
         }
     }
 }
Beispiel #54
0
    void Start()
    {
        _CurGameState = EGameState.GameStart;

        Init();
    }
 IEnumerator WaitToNextLvl(float time)
 {
     m_curentState = EGameState.ENDLEVEL;
     yield return new WaitForSeconds(time);
     if (m_currentSceneId < m_maxLevelId)
     {
         m_currentSceneId++;
         Debug.LogWarning("Loading scene : Level_" + m_currentSceneId);
         Application.LoadLevel("Level_" + m_currentSceneId);
     }
     else
     {
         Debug.LogError("Final Level, faire une fin");
     }
 }
Beispiel #56
0
 public bool IsInGameState(EGameState gameState)
 {
     return this.gameState == gameState;
 }
Beispiel #57
0
 public void StartGame()
 {
     ChangeInformation();
     gameState = EGameState.Running;
     WaveManager.StartAutoWave();
 }
Beispiel #58
0
        public void ChangeStateToStateGame()
        {
            state = EGameState.StateGame;

            Message.Inst().Show(Strings.GAME_ALERT_TITLE_GAME_STARTED, Strings.GAME_ALERT_DESCRIPTION_GAME_STARTED, GameResources.Inst().GetHudTexture(HUDTexture.IconRoad));
            foreach (Player player in players)
            {
                player.AddSources(Settings.startResources, TransactionState.TransactionStart);
            }
        }
Beispiel #59
0
    void SelectItem(GameObject o)
    {
        Debug.Log("_AnswerObject.name="+_AnswerObject.name+", SelectItem.name="+o.name+"!");

        //if(o.name.Equals(_AnswerObject.name) == true)
        if(_AnswerObject.name == o.name)
        {
            Debug.Log("Answer Is Right");
        }
        else
        {
            Debug.Log("Answer Is wrong");
        }

        //show all result
        foreach(GameObject item in _ItemList)
        {
            if(item.name == _AnswerObject.name)
            {
                GameObject result =  GameObject.Instantiate(_RightResult, item.transform.position, _RightResult.transform.rotation) as GameObject;

                result.transform.position = new Vector3(result.transform.position.x, result.transform.position.y, -14.7f);

                _ResultList.Add(result);
            }
            else
            {
                GameObject result =  GameObject.Instantiate(_WrongResult, item.transform.position, _WrongResult.transform.rotation) as GameObject;

                result.transform.position = new Vector3(result.transform.position.x, result.transform.position.y, -14.7f);

                _ResultList.Add(result);
            }
        }

        _CurGameState = EGameState.GameResult;
    }
Beispiel #60
0
 public override void StateListener(EGameState state){
     // extendability
 }