Beispiel #1
0
        public Scene(int width, int height)
        {
            _height       = height;
            _width        = width;
            _pointsEarned = 0;

            _gameField = new Field(width, height);
            _ground    = new Ground(width, height);
            _figure    = new ActiveFigure(width, height);
            _rnd       = new Random();

            _levelsToKill = new List <int>();
        }
Beispiel #2
0
 private bool CanMoveRight(ActiveFigure figure, Ground ground, int step)
 {
     foreach (Cell figureCell in figure.Cells)
     {
         foreach (Cell groundCell in ground.Cells)
         {
             if (figureCell.Value != " " &&
                 groundCell.Value != " " &&
                 groundCell.Y == figureCell.Y &&
                 figureCell.X + step == groundCell.X)
             {
                 return(false);
             }
         }
     }
     return(true);
 }
Beispiel #3
0
        private bool IsTouchdown(ActiveFigure figure, Ground ground)
        {
            foreach (Cell figureCell in figure.Cells)
            {
                foreach (Cell groundCell in ground.Cells)
                {
                    if (figureCell.Value != " " &&
                        groundCell.Value != " " &&
                        groundCell.X == figureCell.X &&
                        groundCell.Y + 1 == figureCell.Y)
                    {
                        return(true);
                    }
                }
            }

            if (figure.BottomY <= 0)
            {
                return(true);
            }

            return(false);
        }
Beispiel #4
0
        private Cell[] CalculateRawCells(List <Cell> groundCells, List <Cell> gameFieldCells, ActiveFigure figure)
        {
            // Form a frame buffer by projecting Ground and Active Figure to Game Field.
            Cell[] frame = new Cell[_width * _height];
            gameFieldCells.CopyTo(frame);

            List <Cell> toMerge = new List <Cell>(groundCells);

            toMerge.AddRange(figure.Cells);

            // TODO Replace with matrix
            for (int i = 0; i < toMerge.Count; i++)
            {
                Cell cell = toMerge[i];

                for (int j = 0; j < frame.Length; j++)
                {
                    if (frame[j].X == cell.X && frame[j].Y == cell.Y)
                    {
                        // A-la z-buffering:
                        string oldValue = frame[j].Value;
                        frame[j] = cell;

                        if (cell.Value == " ") // Do not replace existing filled cell with empty on by mistake.
                        {
                            frame[j].Value = oldValue;
                        }
                        break;
                    }
                }
            }

            Array.Sort(frame);

            return(frame);
        }