예제 #1
0
    public override void Write(Stream stream)
    {
        print("Writing autosave");

        Dupe7.GameStateMachine game = GetComponent <GameplayView> ().Game;
        new BinaryFormatter().Serialize(stream, game);
    }
예제 #2
0
    public override void Read(Stream stream)
    {
        print("Reading autosave");
#if false
        try {
            Dupe7.GameStateMachine game = (Dupe7.GameStateMachine)(new BinaryFormatter().Deserialize(stream));
            ((GameplayView)Instantiate(GetComponent <MainMenuView> ().gameplayPrefab)).Game = game;
            Destroy(gameObject);
        } catch (Exception e) {
            print(e);
        }
#endif
    }
예제 #3
0
    IEnumerator Start()
    {
        // Start with a default game if one isn't set up already
        if (null == Game)
        {
            Game = new Dupe7.GameStateMachine(5, 5, 1337);
        }

        InitComponents();
        InitMeshes();

        for (int c = 0; c < Dupe7.GameStateMachine.COLS; c++)
        {
            for (int r = 0; r < Game.columnCounts[c]; r++)
            {
                meshColumns[c].AddLast(CreateDisc(Game.Discs[c, r].num, Game.Discs[c, r].state, new Vector2(c, r)));
            }
        }

        bool levelUp = false, playerDrop = false, gameOver = false;

        while (!gameOver && Game.MoveNext())
        {
            // Debug dump
            print(Game.Current);

            var boardDump = "";
            for (int r = Dupe7.GameStateMachine.ROWS - 1; r >= 0; r--)
            {
                for (int c = 0; c < Dupe7.GameStateMachine.COLS; c++)
                {
                    boardDump += (r < Game.ColumnCounts[c] ? Game.Discs[c, r].num + ", " : "0, ");
                }
                boardDump += ": ";
                for (int c = 0; c < Dupe7.GameStateMachine.COLS; c++)
                {
                    boardDump += (int)Game.DiscMarkedStates[c, r] + ", ";
                }
                boardDump += "\n";
            }
            print(boardDump);

            // Pause after level up
            if (levelUp)
            {
                yield return(new WaitForSeconds(1.0f));

                levelUp = false;
            }

            switch (Game.Current)
            {
            case Dupe7.TurnState.WaitingForPlayer:
                yield return(StartCoroutine(SetDropColumn()));

                break;

            case Dupe7.TurnState.TurnStarted:
                playerDrop = true;
                meshColumns[Game.DropColumn].AddLast(nextDiscMesh);
                break;

            case Dupe7.TurnState.Dropped:
                yield return(StartCoroutine(Drop()));

                if (Game.NumTurnsThisLevel > 1)
                {
                    gameOver = Game.TestGameOver();
                }

                // Update drops just once each turn
                if (playerDrop)
                {
                    dropGauge.SetDrops(Game.NumTurnsThisLevel, Game.MaxTurnsThisLevel);
                    playerDrop = false;
                }
                break;

            case Dupe7.TurnState.Marked:
                tiles.Wink(Game.DiscMarkedStates);
                UpdateMeshesAndRemoveMarked();
                SetChain(Game.Chain + 1);
                yield return(new WaitForSeconds(1.0f));

                SetScore(Game.Score);
                break;

            case Dupe7.TurnState.LevelUp:
                yield return(new WaitForSeconds(1.0f));

                HideLevelAndDrops();
                SetScore(Game.Score);
                LevelUp();
                levelUp  = true;
                gameOver = Game.TestGameOver();
                break;

            case Dupe7.TurnState.TurnEnded:
                nextDiscMesh = CreateDisc(Game.NextDisc.num, Game.NextDisc.state, new Vector2(3.0f, 7.0f));
                ShowLevelAndDrops(Game.NumTurnsThisLevel, Game.MaxTurnsThisLevel, Game.Level);
                break;
            }
        }

        yield return(new WaitForSeconds(1.0f));

        Instantiate(gameOverPrefab);
        Destroy(gameObject);
    }
예제 #4
0
    IEnumerator Start()
    {
        // Start with a default game if one isn't set up already
        if (null == Game)
            Game = new Dupe7.GameStateMachine (5, 5, 1337);

        InitComponents ();
        InitMeshes ();

        for (int c = 0; c < Dupe7.GameStateMachine.COLS; c++)
            for (int r = 0; r < Game.columnCounts[c]; r++)
                meshColumns[c].AddLast (CreateDisc (Game.Discs[c, r].num, Game.Discs[c, r].state, new Vector2 (c, r)));

        bool levelUp = false, playerDrop = false, gameOver = false;
        while (!gameOver && Game.MoveNext ()) {
            // Debug dump
            print (Game.Current);

            var boardDump = "";
            for (int r = Dupe7.GameStateMachine.ROWS - 1; r >= 0; r--) {
                for (int c = 0; c < Dupe7.GameStateMachine.COLS; c++)
                    boardDump += (r < Game.ColumnCounts[c] ? Game.Discs[c, r].num + ", " : "0, ");
                boardDump += ": ";
                for (int c = 0; c < Dupe7.GameStateMachine.COLS; c++)
                    boardDump += (int)Game.DiscMarkedStates[c, r] + ", ";
                boardDump += "\n";
            }
            print (boardDump);

            // Pause after level up
            if (levelUp) {
                yield return new WaitForSeconds (1.0f);
                levelUp = false;
            }

            switch (Game.Current) {
            case Dupe7.TurnState.WaitingForPlayer:
                yield return StartCoroutine (SetDropColumn ());
                break;

            case Dupe7.TurnState.TurnStarted:
                playerDrop = true;
                meshColumns[Game.DropColumn].AddLast (nextDiscMesh);
                break;

            case Dupe7.TurnState.Dropped:
                yield return StartCoroutine (Drop ());
                if (Game.NumTurnsThisLevel > 1)
                    gameOver = Game.TestGameOver ();

                // Update drops just once each turn
                if (playerDrop) {
                    dropGauge.SetDrops (Game.NumTurnsThisLevel, Game.MaxTurnsThisLevel);
                    playerDrop = false;
                }
                break;

            case Dupe7.TurnState.Marked:
                tiles.Wink (Game.DiscMarkedStates);
                UpdateMeshesAndRemoveMarked ();
                SetChain (Game.Chain + 1);
                yield return new WaitForSeconds (1.0f);
                SetScore (Game.Score);
                break;

            case Dupe7.TurnState.LevelUp:
                yield return new WaitForSeconds (1.0f);
                HideLevelAndDrops ();
                SetScore (Game.Score);
                LevelUp ();
                levelUp = true;
                gameOver = Game.TestGameOver ();
                break;

            case Dupe7.TurnState.TurnEnded:
                nextDiscMesh = CreateDisc (Game.NextDisc.num, Game.NextDisc.state, new Vector2 (3.0f, 7.0f));
                ShowLevelAndDrops (Game.NumTurnsThisLevel, Game.MaxTurnsThisLevel, Game.Level);
                break;
            }
        }

        yield return new WaitForSeconds (1.0f);

        Instantiate (gameOverPrefab);
        Destroy (gameObject);
    }