void Awake()
    {
        long rand;
        bool rev      = false;
        int  isOnline = PlayerPrefs.GetInt("network", 0);

        Debug.Log("isOnline" + isOnline);

        if (isOnline != 0 && NetworkStart.user != null)
        {
            this.netuser = NetworkStart.user;
            if (this.netuser.IsServer)
            {
                rev = true;
            }
            rand = this.netuser.Rand;
            Debug.Log("Seed:" + rand);
            this.level = 0;
        }
        else
        {
            this.level = PlayerPrefs.GetInt("level", 1);
            if (this.level == 0)
            {
                this.level = 1;
            }
            this.ai = new LilyAcolasia_AI.AI(this.level);

            this.demoAi           = null;  //new LilyAcolasia_AI.AI (4);
            this.currentGameState = GameState.AIAction;

            rand = new System.Random().Next();
        }
        Debug.Log("Level:" + level);
        this.observer     = new GameObserverImpl(this, this.netuser);
        this.gameOperator = new LilyAcolasia.GameOperator(this.observer, "AI", "You", rand, rev);

        LilyAcolasia.CardDeck.Handler = this.CardMove;
        FindObjects();
        CreateCards();
    }
    private void processEvent()
    {
        int turn = this.gameOperator.Round.Current.Turn;

        LilyAcolasia.CardGame  game  = this.gameOperator.Round.Current;
        LilyAcolasia.GameInput input = this.gameEnumerator.Current;

        this.frameCounter++;

        if (this.currentGameState == GameState.RoundEnd)
        {
            if (!GameEffect.IsRoundEnd)
            {
                if (this.gameOperator.Round.HasNextRound())
                {
                    StartRound();
                }
                else
                {
                    this.currentGameState = GameState.GameEnding;
                    var round = this.gameOperator.Round;
                    this.frameCounter = 0;
                    if (round.Point1 > round.Point2)
                    {
                        if (level == 4)
                        {
                            achievements.WarfareLost();
                        }
                        else if (level == 1)
                        {
                            achievements.MimicLost();
                        }
                        else if (level == 0)
                        {
                            achievements.HumanLost();
                        }
                        gameEndingState = 0;
                    }
                    else if (round.Point1 < round.Point2)
                    {
                        if (level == 4)
                        {
                            achievements.WarfareWin();
                        }
                        else if (level == 1)
                        {
                            achievements.MimicWin();
                        }
                        else if (level == 0)
                        {
                            achievements.HumanWin();
                        }

                        bool isPerfect = true;
                        foreach (LilyAcolasia.Field f in game.Fields)
                        {
                            if (f.Winner != USER_TURN)
                            {
                                isPerfect = false;
                                break;
                            }
                        }
                        if (isPerfect)
                        {
                            achievements.Perfect();
                        }

                        gameEndingState = 1;
                    }
                    else
                    {
                        if (level == 4)
                        {
                            achievements.WarfareDraw();
                        }
                        else if (level == 1)
                        {
                            achievements.MimicDraw();
                        }
                        else if (level == 0)
                        {
                            achievements.HumanDraw();
                        }

                        gameEndingState = 2;
                    }
                }
            }
        }
        else if (this.currentGameState == GameState.GameEnding)
        {
            this.bgmSource.volume *= 0.95f;
            if (frameCounter > GAME_ENDING_WAIT)
            {
                if (gameEndingState == 0)
                {
                    GameEffect.GameEnd(0);
                    audioSource.clip = soundGameLost;
                    audioSource.Play();
                }
                else if (gameEndingState == 1)
                {
                    GameEffect.GameEnd(1);
                    audioSource.clip = soundGameWin;
                    audioSource.Play();
                }
                else if (gameEndingState == 2)
                {
                    GameEffect.GameEnd(2);
                    audioSource.clip = soundGameDraw;
                    audioSource.Play();
                }
                this.currentGameState = GameState.GameEnd;
                this.frameCounter     = 0;
            }
        }
        else if (this.currentGameState == GameState.GameEnd)
        {
            if (!GameEffect.IsGameEnd)
            {
                if (Input.GetMouseButtonDown(0))
                {
                    CameraFade.StartAlphaFade(Color.black, false, 0.5f, 0.5f, () => {
                        if (this.netuser != null)
                        {
                            this.netuser.Close();
                            DestroyObject(this.netuser.gameObject);
                        }
                        SceneManager.LoadScene("Title");
                    });
                }
                else if (demoAi != null)
                {
                    demoAi = null;
                    CameraFade.StartAlphaFade(Color.black, false, 0.5f, 0.5f, () => {
                        if (this.netuser != null)
                        {
                            this.netuser.Close();
                            DestroyObject(this.netuser.gameObject);
                        }
                        SceneManager.LoadScene("Game");
                    });
                }
            }
        }
        else if (this.currentGameState == GameState.CutIn)
        {
            if (!GameEffect.IsCutIn)
            {
                int n = game.LastTrashed.Power;

                if (n == 5)
                {
                    if (demoAi == null && game.Turn == USER_TURN)
                    {
                        this.currentGameState = GameState.ColorChoice;
                        ColorChoice.Show((color) =>
                        {
                            LilyAcolasia.GameInput ipt = this.gameEnumerator.Current;
                            ipt.input(LilyAcolasia.Command.Special, color);
                            this.gameEnumerator.MoveNext();
                            this.currentGameState = GameState.UserAction;
                            audioSource.clip      = soundSkillColor;
                            audioSource.Play();
                        });
                    }
                    else
                    {
                        this.currentGameState = GameState.AIAction;
                    }
                }
                else if (n == 9)
                {
                    this.currentGameState = demoAi == null && turn == USER_TURN ? GameState.UserAction : GameState.AIAction;
                }
                else
                {
                    GameEffect.Special(n, game.Turn);
                    this.currentGameState = demoAi == null && turn == USER_TURN ? GameState.UserAction : GameState.AIAction;
                }
                this.frameCounter = 0;
            }
        }
        else if (this.currentGameState == GameState.RoundStart)
        {
            if (this.frameCounter >= TURN_WAIT)
            {
                this.frameCounter     = 0;
                this.currentGameState = GameState.TurnStart;
            }
        }
        else if (this.currentGameState == GameState.TurnStart)
        {
            if (this.frameCounter >= TURN_WAIT)
            {
                this.frameCounter     = 0;
                this.currentGameState = demoAi == null && turn == USER_TURN ? GameState.UserAction : GameState.AIAction;
            }
        }
        else if (this.currentGameState == GameState.CmdWait)
        {
            if (this.frameCounter >= CMD_WAIT)
            {
                this.frameCounter = 0;


                if (game.Status == LilyAcolasia.GameStatus.Status.End)
                {
                    input.input(LilyAcolasia.Command.Next);
                    this.gameEnumerator.MoveNext();

                    if (game.Status == LilyAcolasia.GameStatus.Status.RoundEnd)
                    {
                        this.currentGameState = GameState.RoundEnd;
                        GameEffect.RoundEnd(game.Winner);
                    }
                    else
                    {
                        this.currentGameState = GameState.TurnStart;
                    }
                }
                else if (game.Status == LilyAcolasia.GameStatus.Status.WaitSpecialInput)
                {
                    GameEffect.Special(-1, game.Turn);
                    input.input(LilyAcolasia.Command.Special);
                    this.gameEnumerator.MoveNext();
                }
                else
                {
                    this.currentGameState = demoAi == null && turn == USER_TURN ? GameState.UserAction : GameState.AIAction;
                }
            }
        }
        else if (this.currentGameState == GameState.UserAction)
        {
            if (this.demoAi != null)
            {
                if (game.Status != LilyAcolasia.GameStatus.Status.WaitSpecialInput || this.frameCounter >= AI_WAIT)
                {
                    this.frameCounter = 0;

                    var next = demoAi.next(game);
                    input.input(next.Item1, next.Item2, next.Item3.ToString());

                    this.gameEnumerator.MoveNext();
                    this.frameCounter     = 0;
                    this.currentGameState = GameState.CmdWait;
                    GameEffect.Special(-1, game.Turn);
                    if (game.Status == LilyAcolasia.GameStatus.Status.WaitSpecialInput)
                    {
                        GameEffect.CutIn(game.LastTrashed.Power);
                        audioSource.clip = soundCutIn;
                        audioSource.Play();
                        this.currentGameState = GameState.CutIn;
                    }
                }
            }
            else
            {
                if (game.Status == LilyAcolasia.GameStatus.Status.WaitSpecialInput && !game.LastTrashed.HasSpecialInput)
                {
                    this.currentGameState = GameState.CmdWait;
                    this.frameCounter     = 0;
                    GameEffect.Special(game.LastTrashed.Power, game.Turn);
                }
            }

            this.frameCounter = 0;
        }
        else if (this.currentGameState == GameState.AIAction)
        {
            if (game.Status != LilyAcolasia.GameStatus.Status.WaitSpecialInput || this.frameCounter >= AI_WAIT)
            {
                this.frameCounter = 0;

                if (this.level == 0)
                {
                    if (!netuser.IsConnected)
                    {
                        GameEffect.GameEnd(3);
                        this.netuser.Close();
                        DestroyObject(this.netuser.gameObject);
                        this.currentGameState = GameState.GameEnd;
                        return;
                    }
                    string next = netuser.message();

                    if (next == null)
                    {
                        GameEffect.GameEnd(3);
                        this.netuser.Close();
                        DestroyObject(this.netuser.gameObject);
                        this.currentGameState = GameState.GameEnd;
                        return;
                    }
                    else if (next == "")
                    {
                        return;
                    }
                    input.input(next);
                }
                else
                {
                    var next = ai.next(game);
                    input.input(next.Item1, next.Item2, next.Item3.ToString());
                }
                this.gameEnumerator.MoveNext();
                this.frameCounter     = 0;
                this.currentGameState = GameState.CmdWait;
                GameEffect.Special(-1, game.Turn);
                if (game.Status == LilyAcolasia.GameStatus.Status.WaitSpecialInput)
                {
                    GameEffect.CutIn(game.LastTrashed.Power);
                    audioSource.clip = soundCutIn;
                    audioSource.Play();
                    this.currentGameState = GameState.CutIn;
                }
            }
        }
    }