Ejemplo n.º 1
0
        public void Draw(Renderer renderer, TetrisView view, int row, int column, out TetrisPoint[] alloc)
        {
            IPiece piece = view.Model[row, column];

            if (piece == null)
            {
                alloc = new TetrisPoint[0];
                return;
            }
            List <TetrisPoint> list = new List <TetrisPoint>();

            for (int i = 0; i < piece.Width; i++)
            {
                for (int j = 0; j < piece.Height; j++)
                {
                    int realRow    = row + j;
                    int realColumn = column + i;
                    if (!piece.IsVisible(row, column, realRow, realColumn))
                    {
                        continue;
                    }
                    Vector2 pos = view.ModelToView(realRow, realColumn);
                    list.Add(new TetrisPoint(realRow, realColumn));
                    TetrisColorEnum?colorE = piece.RenderingSource as TetrisColorEnum?;
                    if (!colorE.HasValue)
                    {
                        throw new ArgumentException();
                    }
                    DrawAt(renderer, pos, colorE.Value);
                }
            }
            alloc = list.ToArray();
        }
Ejemplo n.º 2
0
        /// <summary>
        /// 指定の位置に指定のピースが存在出来るか同課を返します.
        /// </summary>
        /// <param name="row"></param>
        /// <param name="column"></param>
        /// <param name="piece"></param>
        /// <returns></returns>
        private bool IsSafeLocation(int row, int column, IPiece piece)
        {
            List <TetrisPoint> list = GetPointList(row, column, piece);

            //壁を越えているか検査
            if (IsOverRange(list))
            {
                return(false);
            }
            //全てのマスに対して
            for (int i = 0; i < RowCount; i++)
            {
                for (int j = 0; j < ColumnCount; j++)
                {
                    //そのマスが空or今検査しているピース自身なら無視
                    IPiece at = this[i, j];
                    if (at == null || at.Equals(piece))
                    {
                        continue;
                    }
                    //そのマスがもともと今検査しているピースの占有範囲内なら無視
                    bool self = false;
                    foreach (TetrisPoint elem in list)
                    {
                        if (elem.Row == i && elem.Column == j)
                        {
                            self = true;
                            break;
                        }
                    }
                    if (self)
                    {
                        continue;
                    }
                    //そのピースの全ての占有範囲に対して
                    for (int otherWidth = 0; otherWidth < at.Width; otherWidth++)
                    {
                        for (int otherHeight = 0; otherHeight < at.Height; otherHeight++)
                        {
                            int otherRealRow    = otherHeight + i;
                            int otherRealColumn = otherWidth + j;
                            if (!at.IsVisible(i, j, otherRealRow, otherRealColumn))
                            {
                                continue;
                            }
                            //他のピースの占有範囲と重複するなら
                            foreach (TetrisPoint elem in list)
                            {
                                if (elem.Row == otherRealRow &&
                                    elem.Column == otherRealColumn)
                                {
                                    return(false);
                                }
                            }
                        }
                    }
                }
            }
            return(true);
        }
Ejemplo n.º 3
0
        public bool IsPlaceable(int row, int column, IPiece piece)
        {
            List <TetrisPoint> list = GetPointList(row, column, piece);

            //壁を越えているか検査
            if (IsOverRange(list))
            {
                return(false);
            }
            //全てのマスに対して
            for (int i = 0; i < RowCount; i++)
            {
                for (int j = 0; j < ColumnCount; j++)
                {
                    //そのマスが空or今検査しているピース自身なら無視
                    IPiece at = this[i, j];
                    if (at == null || at.Equals(piece))
                    {
                        continue;
                    }
                    //そこにピースがあるので無理
                    if (i == row && j == column)
                    {
                        return(false);
                    }
                    //そのピースの全ての占有範囲に対して
                    for (int otherWidth = 0; otherWidth < at.Width; otherWidth++)
                    {
                        for (int otherHeight = 0; otherHeight < at.Height; otherHeight++)
                        {
                            int otherRealRow    = otherHeight + i;
                            int otherRealColumn = otherWidth + j;
                            if (!at.IsVisible(i, j, otherRealRow, otherRealColumn))
                            {
                                continue;
                            }
                            if (IsOverRange(otherRealRow, otherRealColumn))
                            {
                                return(false);
                            }
                            if (list.Contains(new TetrisPoint(otherRealRow, otherRealColumn)))
                            {
                                return(false);
                            }
                        }
                    }
                }
            }
            return(true);
        }
Ejemplo n.º 4
0
        /// <summary>
        /// This is called when the game should draw itself.
        /// </summary>
        /// <param name="gameTime">Provides a snapshot of timing values.</param>
        protected override void Draw(GameTime gameTime)
        {
            GraphicsDevice.Clear(Color.CornflowerBlue);

            // TODO: Add your drawing code here
            renderer.Begin();
            renderer.Draw("Frame", Vector2.Zero, Color.White);
            tetrisView.Draw(gameTime, renderer);
            //NEXT
            Vector2 nextScale         = new Vector2(1, 1);
            Vector2 nextImagePosition = new Vector2(352, 0);
            Vector2 nextPosition      = nextImagePosition + new Vector2(166 + 32, 31 + 20);
            IPiece  piece             = tetrisView.Queue.Peek(0);

            renderer.Draw("Next", nextImagePosition, Color.White);
            for (int i = 0; i < piece.Width; i++)
            {
                for (int j = 0; j < piece.Height; j++)
                {
                    Vector2 offset = new Vector2(i * 32, j * 32);
                    if (!piece.IsVisible(0, 0, j, i))
                    {
                        continue;
                    }
                    renderer.Draw(piece.RenderingSource.ToString(), nextPosition + offset, Color.White);
                }
            }
            //SCORE
            Vector2 scoreScale         = new Vector2(1, 1);
            Vector2 scoreImagePosition = new Vector2(352, 200);
            Vector2 scoreNumPosition   = scoreImagePosition + new Vector2(31, 91);

            renderer.Draw("Score", scoreImagePosition, Color.White);
            number.DrawHorizontal(renderer, scoreNumPosition, score);
            //PRES SPACE
            if (tetrisView.SelectionModel.Piece == null)
            {
                Vector2 size       = new Vector2(346, 60);
                Vector2 screenSize = new Vector2(800, 480);
                Vector2 position   = ((screenSize - size) / 2) + new Vector2(0, 100);
                renderer.Draw("Start", position, Color.White);
            }
            renderer.End();
            base.Draw(gameTime);
        }
Ejemplo n.º 5
0
        private void Decomposition()
        {
            int    row   = SelectionModel.Row;
            int    col   = SelectionModel.Column;
            IPiece piece = SelectionModel.Piece;

            Model[row, col] = null;
            for (int i = 0; i < piece.Width; i++)
            {
                for (int j = 0; j < piece.Height; j++)
                {
                    int realRow    = row + j;
                    int realColumn = col + i;
                    if (!piece.IsVisible(row, col, realRow, realColumn))
                    {
                        continue;
                    }
                    Model[realRow, realColumn] = new SinglePiece(piece.RenderingSource);
                }
            }
        }
Ejemplo n.º 6
0
        /// <summary>
        /// 指定のピースが指定の位置において占有している範囲を返します.
        /// </summary>
        /// <param name="row"></param>
        /// <param name="column"></param>
        /// <param name="piece"></param>
        /// <returns></returns>
        private List <TetrisPoint> GetPointList(int row, int column, IPiece piece)
        {
            List <TetrisPoint> list = new List <TetrisPoint>();

            if (piece == null)
            {
                return(list);
            }
            for (int i = 0; i < piece.Width; i++)
            {
                for (int j = 0; j < piece.Height; j++)
                {
                    int realRow    = row + j;
                    int realColumn = column + i;
                    if (!piece.IsVisible(row, column, realRow, realColumn))
                    {
                        continue;
                    }
                    list.Add(new TetrisPoint(realRow, realColumn));
                }
            }
            return(list);
        }