Пример #1
0
        /// <summary>
        /// Intro Constructor
        /// </summary>
        public TetrisGame()
        {
            // Set Graphics profile
            this.Graphics = new GraphicsDeviceManager(this);

            this.Graphics.PreferredBackBufferFormat = SurfaceFormat.Color;
            this.Graphics.PreferredBackBufferHeight = 768;
            this.Graphics.PreferredBackBufferWidth  = 1024;
            this.Graphics.SupportedOrientations     = DisplayOrientation.Default;

#if DEBUG
            // Unlimted FPS
            this.IsFixedTimeStep = false;
            this.Graphics.SynchronizeWithVerticalRetrace = false;

            // Windowed
            this.Graphics.IsFullScreen = false;
#else
            // Capped FPS
            this.IsFixedTimeStep = false;
            this.Graphics.SynchronizeWithVerticalRetrace = false;
            //this.TargetElapsedTime = TimeSpan.FromSeconds(1 / 60f);

            // Fullscreen
            this.Graphics.IsFullScreen = false;
#endif

            // Apply Graphics
            this.Graphics.ApplyChanges();
            this.Content.RootDirectory = "Content";

            // Set components
            this.InputManager  = new InputManager(this);
            this.ScreenManager = new ScreenManager(this);
            this.AudioManager  = new AudioManager(this);
            this.Timeline      = new Data.Timeline(this);
        }
Пример #2
0
        /// <summary>
        /// Initializes the screen
        /// </summary>
        public override void Initialize()
        {
            this.TransitionOnTime = TimeSpan.FromSeconds(.5f);
            this.TransitionOffTime = TimeSpan.FromSeconds(.5f);
            this.IsPopup = false;

            base.Initialize();

            // Get service
            _timeline = (Timeline)this.Game.Services.GetService(typeof(Timeline));

            // Create Field
            _field = new Data.Field(this.Game, _timeline, 10, 24);
            _field.Initialize();
            DummyField dummyField = new Data.DummyField(this.Game, 5, 5 + SpriteField.HiddenRows);

            // Create Sprites
            _spriteField = new SpriteField(this.Game, _field) { Position = Vector2.One * SpriteField.GridCellSize * 3 };
            _spriteGhostBlock = new SpriteGhostBlock(this.Game, _field.CurrentBlock) { Position = _spriteField.Position };
            _spriteFallingBlock = new SpriteFallingBlock(this.Game, _field.CurrentBlock) { Position = _spriteField.Position };

            // Next Block and HoldBlock Boundaries
            _spriteNextBlockBoundary = new SpriteField(this.Game, dummyField) { Position = _spriteField.Position + (Vector2.UnitX * (_field.Width + 2)) * SpriteField.GridCellSize, };
            _spriteHoldBlockBoundary = new SpriteField(this.Game, dummyField) { Position = _spriteField.Position + (Vector2.UnitX * (_field.Width + 2) + Vector2.UnitY * (6 + 1)) * SpriteField.GridCellSize, };

            // Next BLock
            _spriteNextBlock = new SpriteBlock(this.Game, _field.NextBlock) { Position = _spriteNextBlockBoundary.Position + Vector2.One * SpriteField.GridCellSize, };
            _field.NextBlock.OnTypeChanged += new BlockTypeDelegate(NextBlock_OnTypeChanged);
            _spriteHoldBlock = new SpriteNullableBlock(this.Game) { Position = _spriteHoldBlockBoundary.Position + Vector2.One * SpriteField.GridCellSize, };

            _spriteField.Initialize();
            _spriteGhostBlock.Initialize();
            _spriteFallingBlock.Initialize();
            _spriteNextBlockBoundary.Initialize();
            _spriteHoldBlockBoundary.Initialize();
            _spriteNextBlock.Initialize();
            _spriteHoldBlock.Initialize();

            _spriteScorePopups = new List<SpriteScorePopup>();

            // Player controller
            _controller = new KeyboardController(this.Game, Keys.S, Keys.A, Keys.D, Keys.W, Keys.Q, Keys.E, Keys.Space, Keys.Enter);
            _controller.Initialize();

            _field.OnGameEnded += new EventHandler(_field_OnGameEnded);
            _field.OnRowsCleared += new RowsDelegate(_field_OnRowsCleared);
            _field.OnPointsEarned += new PointsDelegate(_field_OnPointsEarned);

            // Start the level
            _timeline.Start();
        }
Пример #3
0
        /// <summary>
        /// Creates a new field
        /// </summary>
        /// <param name="game">Game to bind to</param>
        /// <param name="timeline">Timeline service</param>
        /// <param name="width">Field width</param>
        /// <param name="height">Field height</param>
        public Field(Game game, Timeline timeline, Int32 width, Int32 height)
            : base(game)
        {
            this.Timeline = timeline;
            this.LinesCleared = 0;

            this.Width = width;
            this.Height = height;
            
            this.Bottom = new Row(width);
            this.Top = new Row(width);
            this.Bottom.Next = Top;
            this.Top.Prev = Bottom;

            for (int i = 0; i < height; i++)
                this.Bottom.InsertAfter(new Row(width));
        }