/// <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); }
public IPiece Take() { IPiece head = pieceList[0]; pieceList.RemoveAt(0); pieceList.Add(CreateRandom(CreateRandom())); return(head); }
protected void ClearPiece() { if (_currentPiece == null) { return; } Remove(_currentPiece); AddRange(_currentPiece); _currentPiece = null; }
public bool CanTurnRight(int row, int column, IPiece piece) { piece.RightRotate(); try { return(IsSafeLocation(row, column, piece)); } finally { piece.LeftRotate(); } }
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); }
private void Control() { int sRow = SelectionModel.Row; int sCol = SelectionModel.Column; bool move = false; IPiece sPiece = SelectionModel.Piece; Detector detector = Detector.GetInstance(); //キー入力で移動 if (detector.IsDetect(Handle.LEFT)) { move = true; SelectionModel.Column--; } else if (detector.IsDetect(Handle.RIGHT)) { move = true; SelectionModel.Column++; } else if (detector.IsDetect(Handle.DOWN)) { if (Model.IsPlaceable(SelectionModel.Row + 1, SelectionModel.Column, sPiece)) { move = true; SelectionModel.Row++; } } else if (detector.IsDetect(Keys.Enter)) { sPiece.RightRotate(); } //移動を適用 if (!move) { return; } SelectionModel.Row = Math.Min(Model.RowCount - sPiece.Height, Math.Max(0, SelectionModel.Row)); SelectionModel.Column = Math.Min(Model.ColumnCount - sPiece.Width, Math.Max(0, SelectionModel.Column)); if (Model.IsPlaceable(SelectionModel.Row, SelectionModel.Column, SelectionModel.Piece)) { Model[sRow, sCol] = null; Model[SelectionModel.Row, SelectionModel.Column] = SelectionModel.Piece; } else { SelectionModel.Row = sRow; SelectionModel.Column = sCol; } }
public PieceFactory(AbstractBlockFactory <ITetrisBlock> factory) : base(factory) { LPiece = GetPiece(2, new PointF(0.0f, 1.0f), Brushes.Gold, "101011"); JPiece = GetPiece(2, new PointF(1.0f, 1.0f), Brushes.OrangeRed, "010111"); OPiece = GetPiece(2, new PointF(0.5f, 0.5f), Brushes.Gray, "1111"); IPiece = GetPiece(4, new PointF(1.5f, 0.5f), Brushes.SandyBrown, "1111"); TPiece = GetPiece(3, new PointF(1.0f, 1.0f), Brushes.Indigo, "010111"); SPiece = GetPiece(2, new PointF(0.0f, 1.0f), Brushes.ForestGreen, "101101"); ZPiece = GetPiece(2, new PointF(0.0f, 1.0f), Brushes.DodgerBlue, "011110"); Pieces = new List <IPiece> { OPiece, IPiece, TPiece, ZPiece, SPiece, LPiece, JPiece }; }
private void New() { IPiece piece = Queue.Take(); SelectionModel.Row = piece.Height; SelectionModel.Column = (Model.ColumnCount - piece.Width) / 2; SelectionModel.Piece = piece; if (Model.IsPlaceable(SelectionModel.Row, SelectionModel.Column, piece)) { Model[SelectionModel.Row, SelectionModel.Column] = SelectionModel.Piece; } else { SelectionModel.Clear(); } }
/// <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); }
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); } } }
/// <summary> /// 盤面を描画します. /// </summary> /// <param name="gameTime"></param> /// <param name="renderer"></param> public virtual void Draw(GameTime gameTime, Renderer renderer) { renderer.Draw("Frame", Vector2.Zero, Color.White); List <TetrisPoint> list = new List <TetrisPoint>(); for (int i = 0; i < Model.RowCount; i++) { for (int j = 0; j < Model.ColumnCount; j++) { //指定位置に何もないor既にバッファされているなら次へ IPiece piece = Model[i, j]; if (piece == null || list.Contains(new TetrisPoint(i, j))) { continue; } //指定位置を描画して描画された範囲をバッファ TetrisPoint[] alloc; Renderer.Draw(renderer, this, i, j, out alloc); list.AddRange(alloc); } } }
/// <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); }
private void PutMiniature(Type tetriminos, int[][] positions) { if (tetriminos == typeof(IPiece)) { IPiece.MiniaturePiece(positions); return; } if (tetriminos == typeof(JPiece)) { JPiece.MiniaturePiece(positions); return; } if (tetriminos == typeof(LPiece)) { LPiece.MiniaturePiece(positions); return; } if (tetriminos == typeof(OPiece)) { OPiece.MiniaturePiece(positions); return; } if (tetriminos == typeof(SPiece)) { SPiece.MiniaturePiece(positions); return; } if (tetriminos == typeof(TPiece)) { TPiece.MiniaturePiece(positions); return; } if (tetriminos == typeof(ZPiece)) { ZPiece.MiniaturePiece(positions); } }
public PieceRenderer(IPiece piece, int blockSize) : base(piece, blockSize) { }
public bool Equals(IPiece other) { return(other != null && GetHashCode().Equals(other.GetHashCode())); }
protected bool IsEdge(IPiece piece) { return(piece.Any(b => !b.Position.IsIn(Size))); }
protected bool IsCollision(IPiece piece) { return(this.Except(new [] { CurrentPiece }).Intersect(piece).Any()); }
public void Clear() { this.Row = -1; this.Column = -1; this.Piece = null; }
public void Selection(int row, int column, IPiece piece) { this.Row = row; this.Column = column; this.Piece = piece; }