blocks in external file images srs

This commit is contained in:
foglar 2024-10-09 11:40:02 +02:00
parent 1659c25ee9
commit 47afe2c0f9
8 changed files with 446 additions and 300 deletions

BIN
ARS-pieces.png Normal file

Binary file not shown.

After

Width:  |  Height:  |  Size: 642 B

View File

@ -1,4 +1,6 @@
using System;
using System.Media;
using System.Threading;
namespace Tetris
{
@ -9,6 +11,23 @@ namespace Tetris
public static void Main(string[] args)
{
// Music player
#if _WINDOWS
SoundPlayer player = new SoundPlayer("song.wav");
player.PlayLooping();
#endif
//using (var audioFile = new AudioFileReader(audioFile)) using (
//var outputDevice = new WaveOutEvent())
//{
// outputDevice.Init(audioFile);
// outputDevice.Play();
// while (outputDevice.PlaybackState == PlaybackState.Playing)
// {
// Thread.Sleep(1000);
// }
//}
Matrix matrix = new Matrix();
Shape shape = new Shape(matrix);
int previousScore = 0;
@ -39,6 +58,9 @@ namespace Tetris
}
System.Threading.Thread.Sleep(Speed.ShowSpeed());
#if _WINDOWS
player.Stop();
#endif
}
}
@ -64,21 +86,15 @@ namespace Tetris
}
}
public class Speed()
public class Speed
()
{
private static int speed = 400;
public static int ShowSpeed()
{
return speed;
}
public static int ShowSpeed() { return speed; }
public static void SpeedUp()
{
speed -= 50;
public static void SpeedUp() { speed -= 50; }
}
}
public class Shape
{
@ -160,7 +176,8 @@ namespace Tetris
{
for (int i = 0; i < current_shape.GetLength(0); i++)
{
if (x + current_shape[i, 0] == matrixX && y + current_shape[i, 1] == matrixY)
if (x + current_shape[i, 0] == matrixX &&
y + current_shape[i, 1] == matrixY)
{
return true;
}
@ -168,7 +185,6 @@ namespace Tetris
return false;
}
private bool CanMove(int newX, int newY)
{
for (int i = 0; i < current_shape.GetLength(0); i++)
@ -176,11 +192,13 @@ namespace Tetris
int newBlockX = newX + current_shape[i, 0];
int newBlockY = newY + current_shape[i, 1];
if (newBlockX >= Matrix.HEIGHT || newBlockX < 0 || newBlockY < 0 || newBlockY >= Matrix.WIDTH)
if (newBlockX >= Matrix.HEIGHT || newBlockX < 0 || newBlockY < 0 ||
newBlockY >= Matrix.WIDTH)
{
return false;
}
if (matrix.GetBlock(newBlockX, newBlockY) != ' ' && !IsPartOfShape(newBlockX, newBlockY))
if (matrix.GetBlock(newBlockX, newBlockY) != ' ' &&
!IsPartOfShape(newBlockX, newBlockY))
{
return false;
}
@ -239,7 +257,8 @@ namespace Tetris
Console.Write("│ ");
for (int j = 0; j < WIDTH; j++)
{
Console.ForegroundColor = matrix[i, j] == ' ' ? ConsoleColor.DarkBlue : ConsoleColor.DarkBlue;
Console.ForegroundColor =
matrix[i, j] == ' ' ? ConsoleColor.DarkBlue : ConsoleColor.DarkBlue;
Console.Write(matrix[i, j]);
}
Console.ResetColor();
@ -250,14 +269,8 @@ namespace Tetris
Console.WriteLine("Score: " + score);
}
public int GetScore()
{
return score;
}
public void IncreaseScore(int score)
{
this.score += score;
}
public int GetScore() { return score; }
public void IncreaseScore(int score) { this.score += score; }
public void CheckForCompleteLines()
{

View File

@ -1,3 +1,5 @@
# Tetris
## Simple tetris game
- [SRS specifications](./TetrominoSRS.md)

119
ShapesData.cs Normal file
View File

@ -0,0 +1,119 @@
namespace Tetris;
public static class ShapesData
{
public static readonly List<List<int[,]>> shapes = new List<List<int[,]>>
{
// Square block (only one rotation)
new List<int[,]>
{
new int[,]
{
{0, 0}, {0, 1}, {0, 2}, {0, 3}, {1, 0}, {1, 1}, {1, 2}, {1, 3}
}
},
// Long block (two rotations)
new List<int[,]>
{
new int[,]
{
{1, 0}, {1, 1}, {1, 2}, {1, 3}, {1, -1}, {1, -2}, {1, 4}, {1, 5} // Horizontal rotation
},
new int[,]
{
{0, 0}, {1, 0}, {2, 0}, {3, 0}, {0, 1}, {1, 1}, {2, 1}, {3, 1} // Vertical rotation
}
},
// L block right (four rotations)
new List<int[,]>
{
new int[,]
{
{0, -2}, {0, -1}, {0, 0}, {0, 1}, {0, 2}, {0, 3}, {1, 2}, {1, 3} // Rotation 180 degrees
},
new int[,]
{
{1, -2}, {1, -1}, {1, 0}, {1, 1}, {0, 0}, {0, 1}, {-1, 0}, {-1, 1} // Rotation 90 degrees
},
new int[,]
{
{1, -2}, {1, -1}, {1, 0}, {1, 1}, {1, 2}, {1, 3}, {0, -2}, {0, -1} // Rotation 0 degrees
},
new int[,]
{
{-1, 0}, {-1, 1}, {1, 0}, {1, 1}, {0, 0}, {0, 1}, {-1, 2}, {-1, 3} // Rotation 270 degrees
}
},
// L block left (four rotations)
new List<int[,]>
{
new int[,]
{
{0, -2}, {0, -1}, {0, 0}, {0, 1}, {0, 2}, {0, 3}, {1, -2}, {1, -1} // Rotation 0 degrees
},
new int[,]
{
{-1, 0}, {-1, 1}, {1, 0}, {1, 1}, {0, 0}, {0, 1}, {-1, -1}, {-1, -2} // Rotation 270 degrees
},
new int[,]
{
{1, -2}, {1, -1}, {1, 0}, {1, 1}, {1, 2}, {1, 3}, {0, 2}, {0, 3} // Rotation 90 degrees
},
new int[,]
{
{-1, 0}, {-1, 1}, {1, 0}, {1, 1}, {0, 0}, {0, 1}, {1, 2}, {1, 3} // Rotation 180 degrees
}
},
// Z block left (two rotations)
new List<int[,]>
{
new int[,]
{
{1, -2}, {1, -1}, {0, 0}, {0, 1}, {1, 0}, {1, 1}, {0, 2}, {0, 3}
},
new int[,]
{
{0, 0}, {0, 1}, {1, 0}, {1, 1}, {0, -1}, {0, -2}, {-1, -1}, {-1, -2}
}
},
// T block (four rotations)
new List<int[,]>
{
new int[,]
{
{0, -2}, {0, -1}, {0, 0}, {0, 1}, {0, 2}, {0, 3}, {1, 0}, {1, 1}
},
new int[,]
{
{-1, 0}, {-1, 1}, {0, 0}, {0, 1}, {1, 0}, {1, 1}, {0, -1}, {0, -2}
},
new int[,]
{
{1,-2}, {1,-1}, {1,0}, {1,1}, {1, 2}, {1, 3}, {0, 0}, {0, 1}
},
new int[,]
{
{-1, 0}, {-1, 1}, {0, 0}, {0, 1}, {1, 0}, {1, 1}, {0, 2}, {0, 3}
}
},
// Z block right (two rotations)
new List<int[,]>
{
new int[,]
{
{0, -2}, {0, -1}, {0, 0}, {0, 1}, {1, 0}, {1, 1}, {1, 2}, {1, 3}
},
new int[,]
{
{0, 0}, {0, 1}, {1, 0}, {1, 1}, {0, 2}, {0, 3}, {-1 , 2}, {-1, 3}
}
}
};
}

View File

@ -7,4 +7,13 @@
<Nullable>enable</Nullable>
</PropertyGroup>
<PropertyGroup Condition=" '$(OS)' == 'Windows_NT' ">
<DefineConstants>_WINDOWS</DefineConstants>
</PropertyGroup>
<ItemGroup>
<PackageReference Include="NAudio" Version="2.2.1" />
<PackageReference Include="System.Windows.Extensions" Version="8.0.0" />
</ItemGroup>
</Project>

BIN
Tetris.png Normal file

Binary file not shown.

After

Width:  |  Height:  |  Size: 209 KiB

View File

@ -69,6 +69,7 @@ The game will rely on simple keyboard input for interaction and console output f
The primary purpose of this project is to create a minimalist version of Tetris that can run in any terminal or command-line interface. This game is designed for users who enjoy retro-style gaming experiences without needing a graphical environment. It also provides a fun way to practice logical thinking and quick decision-making, as the game increases in difficulty with every level.
Key purposes:
- Provide an engaging and simple game for retro gamers or users with minimal system resources.
- Offer an accessible gaming option that works on most operating systems.
- Allow players to compete for high scores in a lightweight, resource-efficient environment.
@ -86,9 +87,11 @@ Functional requirements define the core behavior and features of the Tetris game
- The grid should be displayed using characters or symbols for blocks.
2. **Tetromino Types**
- The game must include all seven standard tetromino shapes: I, O, T, L, J, S, Z.
- The game must include all seven standard tetromino shapes: I, O, T, L, J, S, Z (shapes are specified in the image below)
- Tetrominoes should be represented using characters.
![tetris block images](./ARS-pieces.png)
3. **Tetromino Movement**
- Players must be able to move tetrominoes left and right using keyboard inputs.
- The tetromino should fall automatically at a predefined speed.

0
image.png Normal file
View File