Skip to content

Commit

Permalink
feat: add L1/L2 and S1/S2 (#4)
Browse files Browse the repository at this point in the history
  • Loading branch information
dameng324 authored Jan 17, 2024
1 parent 5d82a30 commit fdafce4
Show file tree
Hide file tree
Showing 2 changed files with 46 additions and 10 deletions.
16 changes: 12 additions & 4 deletions src/AvaloniaTetris/Game.cs
Original file line number Diff line number Diff line change
Expand Up @@ -55,8 +55,16 @@ private void AddNewPiece()
1 => new Straight(),
2 => new Square(),
3 => new T(),
4 => new L(),
5 => new S(),
4 => randomPiece.Next(1,3) switch
{
1 => new L1(),
2=> new L2(),
} ,
5 => randomPiece.Next(1, 3) switch
{
1 => new S1(),
2 => new S2(),
},
_ => throw new Exception(),
};
activePiece = newPiece;
Expand All @@ -83,15 +91,15 @@ private void SetActivePiece(bool isActive = true)
{
shape = 2;
}
else if (activePiece is S)
else if (activePiece is S1 or S2)
{
shape = 3;
}
else if (activePiece is T)
{
shape = 4;
}
else if (activePiece is L)
else if (activePiece is L1 or L2)
{
shape = 5;
}
Expand Down
40 changes: 34 additions & 6 deletions src/AvaloniaTetris/Piece.cs
Original file line number Diff line number Diff line change
Expand Up @@ -115,23 +115,51 @@ public T()
}
}

internal class L : Piece
internal class L1 : Piece
{
public L()
public L1()
{
Shape = new int[,] { { 1, 1, 1 },
{ 0, 0, 1 }};
X = 4;
Y = 18;
}
}
internal class L2 : Piece
{
public L2()
{
Shape = new int[,] { { 0, 0, 1 },
{ 1, 1, 1 }};
X = 4;
Y = 18;
}
}


internal class S1 : Piece
{
public S1()
{
Shape = new int[,]
{
{ 1, 1, 0 },
{ 0, 1, 1 }
};
X = 4;
Y = 18;
}
}

internal class S : Piece
internal class S2 : Piece
{
public S()
public S2()
{
Shape = new int[,] { { 1, 1, 0 },
{ 0, 1, 1 }};
Shape = new int[,]
{
{ 0, 1, 1 },
{ 1, 1, 0 }
};
X = 4;
Y = 18;
}
Expand Down

0 comments on commit fdafce4

Please sign in to comment.