Пример #1
0
        public frmGame()
        {
            InitializeComponent();

            _board          = new GameBoard(300);
            _board.Position = new Point(25, 25);

            _tiles = new List <Tile>();

            _currentShape          = Shapes.ShapeFactory.GenerateShape(Shapes.ShapeTypeEnum.I);
            _currentShape.Position = new Point(5, 12);

            tickTimer.Enabled = true;
            //tickTimer.Interval = 5;
        }
Пример #2
0
        private void tickTimer_Tick(object sender, EventArgs e)
        {
            _board.LightHerUpBoyo = false;
            // Can we move down?
            bool isItFucked = false;

            foreach (var tile in _currentShape.Tiles)
            {
                Point newTilePos = new Point(tile.X + _currentShape.Position.X, tile.Y + _currentShape.Position.Y + 1);

                if (newTilePos.Y >= Settings.BOARD_TILE_HEIGHT)
                {
                    isItFucked = true;
                }

                var existingTile = _tiles.Where(x => x.X == newTilePos.X && x.Y == newTilePos.Y).FirstOrDefault();

                if (existingTile != null)
                {
                    isItFucked = true;
                }
            }

            if (isItFucked)
            {
                foreach (var tile in _currentShape.Tiles)
                {
                    tile.X += _currentShape.Position.X;
                    tile.Y += _currentShape.Position.Y;

                    _tiles.Add(tile);
                }

                _currentShape = Shapes.ShapeFactory.GenerateShape(Shapes.ShapeTypeEnum.I);
            }

            // move the urrent chsape the so dasd mdfgalkdjg lkasdg lkasjdglk dielfield
            this._currentShape.Position = new Point(this._currentShape.Position.X, this._currentShape.Position.Y + 1);


            // Check for lines that have been completed
            for (int y = 0; y < Settings.BOARD_TILE_HEIGHT; y++)
            {
                var tiles = _tiles.Where(x => x.Y == y).ToArray();

                if (tiles.Length == Settings.BOARD_TILE_WIDTH)
                {
                    foreach (var tile in tiles)
                    {
                        _tiles.Remove(tile);
                    }

                    var subTiles = _tiles.Where(x => x.Y <= y).ToArray();
                    foreach (var subTile in subTiles)
                    {
                        subTile.Y += 1;
                    }

                    _score++;
                    _board.LightHerUpBoyo = true;
                }
            }

            // Find a tile too far above
            var northFaceTile = _tiles.Where(x => x.Y <= 1).FirstOrDefault();

            if (northFaceTile != null)
            {
                tickTimer.Enabled = false;
                _board.GameOver   = true;
            }


            this.Text = _score.ToString();

            this.Invalidate();
        }
Пример #3
0
 public void DrawShape(Graphics gobj, Shapes.Shape shape)
 {
     DrawPieces(gobj, shape.Tiles, shape.Position);
 }