コード例 #1
0
        static void Main(string[] args)
        {
            Console.WindowHeight = 21;
            Console.WindowWidth  = 40;
            Console.BufferHeight = Console.WindowHeight;
            Console.BufferWidth  = Console.WindowWidth;

            while (true)
            {
                switch (currentState)
                {
                case GameState.Menu:
                    GameMenu();
                    currentState = GameState.PlayGame;
                    break;

                case GameState.PlayGame:
                    TetrisEngine.RunEngine();
                    currentState = GameState.GameOver;
                    break;

                case GameState.GameOver:
                    GameOverScreen();
                    return;

                default:
                    break;
                }
            }
        }
コード例 #2
0
    private void Start()
    {
        palettes   = FindObjectOfType <ColourPalettes>().GetComponent <ColourPalettes>();
        appearance = GetComponent <MeshRenderer>();
        engine     = FindObjectOfType <TetrisEngine>().GetComponent <TetrisEngine>();
        //engine.newLevel += UpdateColour;
        if (!isNext)
        {
            engine = GetComponentInParent <TetrisEngine>();

            engine.updateField += UpdateAppearance;
        }
        else
        {
            switch (engine.nextTetrominoIndex)
            {
            case 1:
            case 2:
            case 6:
                appearance.material.color = palettes.palette[0][engine.score.level % palettes.palette[0].Length];
                break;

            case 3:
            case 5:
                appearance.material.color = palettes.palette[1][engine.score.level % palettes.palette[0].Length];
                break;

            default:
                appearance.material.color = palettes.palette[2][engine.score.level % palettes.palette[0].Length];
                break;
            }
        }
    }
コード例 #3
0
 public TetrisConsoleUI(TetrisEngine engine, GameMode mode)
 {
     Engine        = engine;
     Mode          = mode;
     BoardRenderer = new TetrisBoardRenderer(engine, BoardWindowOrigin);
     TextRenderer  = new TetrisTextRenderer();
     Solver        = new TetrisSolver(Engine.Settings.Rows, Engine.Settings.Columns);
     WireEventHandlers();
 }
コード例 #4
0
 public TetrisBoardRenderer(TetrisEngine engine, Coordinates topLeft)
 {
     Rows              = engine.Settings.Rows;
     Columns           = engine.Settings.Columns;
     BoardWindowOrigin = topLeft;
     BorderWidth       = 1;
     PieceRenderer     = new TetrisPieceRenderer();
     StateDifferences  = new TetrisStateDifferences(Rows, Columns);
 }
コード例 #5
0
ファイル: Main.cs プロジェクト: root-stas/OwnTetris
    // Use this for initialization
    void Start()
    {
        //Load saved score:
        BestScore         = PlayerPrefs.GetInt("BestScore", 0);
        BestScoreTxT.text = "BEST SCORE: " + BestScore.ToString();
        Grid = new Renderer[20, 10];
        //Init graphics object:
        NextBlock   = new Renderer[4, 4];
        ScoreNumber = new Renderer[5];
        LevelNumber = new Renderer[2];
        GameObject _block;

        for (int _number = 0; _number < ScoreNumber.Length; _number++)
        {
            _block = (GameObject)Instantiate(BlockSample, new Vector3(7 - _number * 2, 22.75f, 0), Quaternion.identity);
            _block.transform.localScale   = Vector3.one * 1.8f;
            ScoreNumber[_number]          = _block.GetComponent <Renderer>();
            ScoreNumber[_number].material = Numbers[0];
            _block.transform.SetParent(transform);
        }
        for (int _number = 0; _number < LevelNumber.Length; _number++)
        {
            _block = (GameObject)Instantiate(BlockSample, new Vector3(-2 - _number, 13.4f, 0), Quaternion.identity);
            LevelNumber[_number]          = _block.GetComponent <Renderer>();
            LevelNumber[_number].material = Numbers[0];
            _block.transform.SetParent(transform);
        }
        for (int _v = 0; _v < Grid.GetLength(0); _v++)
        {
            for (int _h = 0; _h < Grid.GetLength(1); _h++)
            {
                _block = (GameObject)Instantiate(BlockSample, new Vector3(_h, 20 - _v, 0), Quaternion.identity);
                _block.transform.SetParent(transform);
                Grid[_v, _h] = _block.GetComponent <Renderer>();
                if (_v < 4 && _h < 4)
                {
                    _block = (GameObject)Instantiate(BlockSample, new Vector3(_h - 4, 19 - _v, 0), Quaternion.identity);
                    _block.transform.SetParent(transform);
                    NextBlock[_v, _h] = _block.GetComponent <Renderer>();
                }
            }
        }
        //Init tetris game:
        Tetris = new TetrisEngine();
        Tetris.InitGame();
        Tetris.GameFigure.BlocksCount = (byte)(Colors.Length - 1);

        StartCoroutine(UpdateScreen());
        //StartCoroutine(FPS());
    }
コード例 #6
0
ファイル: Program.cs プロジェクト: cosminiv/CosminMisc
        private static void RunTetris()
        {
            TetrisEngineSettings settings = new TetrisEngineSettings
            {
                Columns             = 16,
                Logger              = new DebugLogger(),
                Rows                = 15,
                Speed               = 4,
                RowsWithFixedBricks = 0,
                EnableTimer         = true
            };

            TetrisEngine    tetrisEngine = new TetrisEngine(settings);
            TetrisConsoleUI tetrisUI     = new TetrisConsoleUI(tetrisEngine, GameMode.Interactive);

            tetrisUI.Start();
        }
コード例 #7
0
    private void Start()
    {
        // Obtain reference to the game engine
        engine = GetComponent <TetrisEngine>();
        obj    = FindObjectOfType <Objects>().GetComponent <Objects>();

        obj.scoreText = GameObject.Find("Score").GetComponent <Text>();
        GenerateTilemap();

        if (Manager.gameType == Manager.GameType.Human || Manager.gameType == Manager.GameType.Display)
        {
            engine.death += OnDeath;
        }

        engine.nextAnimFrame    += Flash;
        engine.tetrominoSpawned += UpdateTetrominoHolder;
        UpdateTetrominoHolder();

        unselectedCol = obj.nesController.transform.Find("MID").GetComponent <Image>().color;
        //obj.humanHIText.text = "Human HI: " + Manager.humanHiScoreVal.ToString("000000");
    }
コード例 #8
0
    protected override void Initialize()
    {
        Viewport viewport = GraphicsDevice.Viewport;

        // Create input helper
        input = new InputHelper(100);

        // Create scene
        scene = new Scene(this);


        // MARK: Menu elements

        // Create container for the menu elements
        menuContainer = new Node(this);
        scene.rootNode.AddChild(menuContainer);

        // Create background
        Sprite menuBackground = new Sprite(this, 0, 0, viewport.Width, viewport.Height)
        {
            texture = CreateLinearGradient(
                new Color(6, 36, 55),
                new Color(20, 12, 51),
                new Color(4, 2, 22),
                new Color(14, 2, 22))
        };

        menuContainer.AddChild(menuBackground);

        // Create menu pointer graphic
        menuHighlight = new Sprite(this, 3 * grid.cell.Width, 7 * grid.cell.Height, 6 * grid.cell.Width, 3 * grid.cell.Height)
        {
            Opacity = 0.1f
        };
        menuContainer.AddChild(menuHighlight);

        // Create menu items
        Text start = new Text(this, "monospace", "START", viewport.Width / 2, 8 * grid.cell.Height, "Center");

        menuContainer.AddChild(start);

        Text mode = new Text(this, "monospace", "MODE", viewport.Width / 2, 11 * grid.cell.Height, "Center");

        menuContainer.AddChild(mode);

        Text quit = new Text(this, "monospace", "QUIT", viewport.Width / 2, 14 * grid.cell.Height, "Center");

        menuContainer.AddChild(quit);


        // MARK: Tetris elements

        // Create container for the game elements
        tetrisContainer        = new Node(this);
        tetrisContainer.active = false;
        scene.rootNode.AddChild(tetrisContainer);

        // Create backgrounds
        Sprite tetrisBackground = new Sprite(this, 0, 0, viewport.Width, viewport.Height)
        {
            texture = CreateLinearGradient(
                new Color(6, 36, 55),
                new Color(20, 12, 51),
                new Color(4, 2, 22),
                new Color(14, 2, 22))
        };

        tetrisContainer.AddChild(tetrisBackground);

        Sprite tetrisHeaderBackground = new Sprite(this, 0, 0, viewport.Width, 4 * grid.cell.Height)
        {
            Opacity = 0.1f
        };

        tetrisContainer.AddChild(tetrisHeaderBackground);

        // Create score section
        Text scoreLabel = new Text(this, "regular", "Score", 6 * grid.cell.Width, grid.cell.Height);

        tetrisContainer.AddChild(scoreLabel);

        Text score = new Text(this, "monospace", "0000000", 6 * grid.cell.Width, 2 * grid.cell.Height);

        tetrisContainer.AddChild(score);

        // Create preview well
        TetrisWell preview = new TetrisWell(this, new TetrisGrid(4, 3, grid.cell.Width, grid.cell.Height));

        tetrisContainer.AddChild(preview);

        // Create playing field well
        TetrisWell playfield = new TetrisWell(this, 0, 4 * grid.cell.Width, grid);

        tetrisContainer.AddChild(playfield);

        // Create tetris game engine
        tetrisEngine = new TetrisEngine(this, input, preview, playfield, grid, score);
        tetrisContainer.AddChild(tetrisEngine);


        base.Initialize();
    }
コード例 #9
0
 private void Start()
 {
     engine        = GetComponent <TetrisEngine>();
     requiredLines = Mathf.Min(engine.startLevel * 10 + 10, Mathf.Max(100, engine.startLevel * 10 - 50));
 }
コード例 #10
0
 private void Start()
 {
     // Obtain reference to the game engine
     engine = GetComponent <TetrisEngine>();
 }
コード例 #11
0
 private void Awake()
 {
     engine = GetComponent <TetrisEngine>();
 }