private bool IsValideMove(TraversalDirection dir) { currentNode = gridManager.GetNextNode(currentNode, dir); if (currentNode == null) { return(false); } if (currentNode.isFilled) { return(false); } snakeController.SetPosition(currentNode); if (fruitNode == currentNode) { SoundManager.AudioPlayEvent(ConstantsList.Sfx_Collect); Score++; snakeIntialSpeed -= Time.deltaTime * snakespeedIncreaserate; snakeController.GenerateTail(); gridManager.SetCollectObject(fruitObj, PoolManager.GetInstance().GetPoolContainer(false), false, out fruitNode); } return(true); }
public void Restart() { SoundManager.AudioPlayEvent(ConstantsList.Sfx_Click); SceneManager.UnloadSceneAsync(SceneManager.GetActiveScene().buildIndex); SceneManager.LoadScene(SceneManager.GetActiveScene().buildIndex); }
public void ChangeState(int state) { SoundManager.AudioPlayEvent(ConstantsList.Sfx_Click); GameManager.OnGameStateChangeByOther((GAMESTATE)state); }
private void ChangeState(GAMESTATE state) { switch (_gameState) { case GAMESTATE.INITILIZE: break; case GAMESTATE.GAMEPLAY: break; case GAMESTATE.PAUSE: if (state == GAMESTATE.GAMEPLAY) { StartCoroutine(StartGame()); } break; case GAMESTATE.GAMEOVER: break; } _gameState = state; switch (state) { case GAMESTATE.INITILIZE: gridManager.Initilize(GridSize); goto default; case GAMESTATE.INITILIZECOMPLETE: fruitObj = gridManager.SetCollectObject(CollectPrefab, PoolManager.GetInstance().GetPoolContainer(false), true, out fruitNode); currentNode = gridManager.GetRandomPosition(10, 10); currentDirection = (TraversalDirection)(Random.Range(1, 4)); SetInitilialPositions(currentNode, currentDirection); if (currentDirection == TraversalDirection.LEFT) { currentDirection = TraversalDirection.RIGHT; } else if (currentDirection == TraversalDirection.RIGHT) { currentDirection = TraversalDirection.LEFT; } else if (currentDirection == TraversalDirection.BOTTOM) { currentDirection = TraversalDirection.TOP; } else if (currentDirection == TraversalDirection.TOP) { currentDirection = TraversalDirection.BOTTOM; } goto default; case GAMESTATE.GAMEPLAY: StartCoroutine(StartGame()); goto default; case GAMESTATE.PAUSE: goto default; case GAMESTATE.GAMEEND: StartCoroutine(ChangeState(GAMESTATE.GAMEOVER, 1.0f)); goto default; case GAMESTATE.GAMEOVER: if (OnGameStateChangeEvent != null) { OnGameStateChangeEvent(_gameState); } SoundManager.AudioPlayEvent(ConstantsList.Sfx_GameOver); Score = _score; break; default: if (OnGameStateChangeEvent != null) { OnGameStateChangeEvent(_gameState); } break; } }