Scoring system
This commit is contained in:
parent
daae59c580
commit
9ccb7eb71d
45
Program.cs
45
Program.cs
@ -11,7 +11,7 @@ namespace Tetris
|
|||||||
{
|
{
|
||||||
Matrix matrix = new Matrix();
|
Matrix matrix = new Matrix();
|
||||||
Shape shape = new Shape(matrix);
|
Shape shape = new Shape(matrix);
|
||||||
|
matrix.IncreaseScore(10);
|
||||||
while (true)
|
while (true)
|
||||||
{
|
{
|
||||||
matrix.Print();
|
matrix.Print();
|
||||||
@ -21,7 +21,10 @@ namespace Tetris
|
|||||||
|
|
||||||
if (!shape.MoveDown())
|
if (!shape.MoveDown())
|
||||||
{
|
{
|
||||||
|
matrix.IncreaseScore(10);
|
||||||
shape = new Shape(matrix); // Create a new shape if current one can't move down
|
shape = new Shape(matrix); // Create a new shape if current one can't move down
|
||||||
|
matrix.CheckForCompleteLines();
|
||||||
|
// Check for game over
|
||||||
}
|
}
|
||||||
|
|
||||||
System.Threading.Thread.Sleep(400);
|
System.Threading.Thread.Sleep(400);
|
||||||
@ -166,6 +169,7 @@ namespace Tetris
|
|||||||
public const int HEIGHT = 22;
|
public const int HEIGHT = 22;
|
||||||
public const int WIDTH = 20;
|
public const int WIDTH = 20;
|
||||||
private char[,] matrix;
|
private char[,] matrix;
|
||||||
|
private int score = 0;
|
||||||
|
|
||||||
public Matrix()
|
public Matrix()
|
||||||
{
|
{
|
||||||
@ -209,6 +213,45 @@ namespace Tetris
|
|||||||
Console.WriteLine(" │");
|
Console.WriteLine(" │");
|
||||||
}
|
}
|
||||||
Console.WriteLine(" ──────────────────────");
|
Console.WriteLine(" ──────────────────────");
|
||||||
|
|
||||||
|
Console.WriteLine("Score: " + score);
|
||||||
|
}
|
||||||
|
|
||||||
|
public void IncreaseScore(int score)
|
||||||
|
{
|
||||||
|
this.score += score;
|
||||||
|
}
|
||||||
|
|
||||||
|
public void CheckForCompleteLines() {
|
||||||
|
for (int i = 0; i < HEIGHT; i++)
|
||||||
|
{
|
||||||
|
bool isComplete = true;
|
||||||
|
for (int j = 0; j < WIDTH; j++)
|
||||||
|
{
|
||||||
|
if (matrix[i, j] == ' ')
|
||||||
|
{
|
||||||
|
isComplete = false;
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
if (isComplete)
|
||||||
|
{
|
||||||
|
// Remove line
|
||||||
|
IncreaseScore(100);
|
||||||
|
for (int j = 0; j < WIDTH; j++)
|
||||||
|
{
|
||||||
|
matrix[i, j] = ' ';
|
||||||
|
}
|
||||||
|
// Move all lines above one down
|
||||||
|
for (int k = i; k > 0; k--)
|
||||||
|
{
|
||||||
|
for (int j = 0; j < WIDTH; j++)
|
||||||
|
{
|
||||||
|
matrix[k, j] = matrix[k - 1, j];
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
public void Clear()
|
public void Clear()
|
||||||
|
|||||||
Loading…
Reference in New Issue
Block a user