blocks in external file images srs
This commit is contained in:
parent
1659c25ee9
commit
47afe2c0f9
BIN
ARS-pieces.png
Normal file
BIN
ARS-pieces.png
Normal file
Binary file not shown.
|
After Width: | Height: | Size: 642 B |
59
Program.cs
59
Program.cs
@ -1,4 +1,6 @@
|
|||||||
using System;
|
using System;
|
||||||
|
using System.Media;
|
||||||
|
using System.Threading;
|
||||||
|
|
||||||
namespace Tetris
|
namespace Tetris
|
||||||
{
|
{
|
||||||
@ -9,6 +11,23 @@ namespace Tetris
|
|||||||
|
|
||||||
public static void Main(string[] args)
|
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();
|
Matrix matrix = new Matrix();
|
||||||
Shape shape = new Shape(matrix);
|
Shape shape = new Shape(matrix);
|
||||||
int previousScore = 0;
|
int previousScore = 0;
|
||||||
@ -39,6 +58,9 @@ namespace Tetris
|
|||||||
}
|
}
|
||||||
|
|
||||||
System.Threading.Thread.Sleep(Speed.ShowSpeed());
|
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;
|
private static int speed = 400;
|
||||||
|
|
||||||
public static int ShowSpeed()
|
public static int ShowSpeed() { return speed; }
|
||||||
{
|
|
||||||
return speed;
|
|
||||||
}
|
|
||||||
|
|
||||||
public static void SpeedUp()
|
public static void SpeedUp() { speed -= 50; }
|
||||||
{
|
|
||||||
speed -= 50;
|
|
||||||
}
|
}
|
||||||
}
|
|
||||||
|
|
||||||
|
|
||||||
public class Shape
|
public class Shape
|
||||||
{
|
{
|
||||||
@ -160,7 +176,8 @@ namespace Tetris
|
|||||||
{
|
{
|
||||||
for (int i = 0; i < current_shape.GetLength(0); i++)
|
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;
|
return true;
|
||||||
}
|
}
|
||||||
@ -168,7 +185,6 @@ namespace Tetris
|
|||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
private bool CanMove(int newX, int newY)
|
private bool CanMove(int newX, int newY)
|
||||||
{
|
{
|
||||||
for (int i = 0; i < current_shape.GetLength(0); i++)
|
for (int i = 0; i < current_shape.GetLength(0); i++)
|
||||||
@ -176,11 +192,13 @@ namespace Tetris
|
|||||||
int newBlockX = newX + current_shape[i, 0];
|
int newBlockX = newX + current_shape[i, 0];
|
||||||
int newBlockY = newY + current_shape[i, 1];
|
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;
|
return false;
|
||||||
}
|
}
|
||||||
if (matrix.GetBlock(newBlockX, newBlockY) != ' ' && !IsPartOfShape(newBlockX, newBlockY))
|
if (matrix.GetBlock(newBlockX, newBlockY) != ' ' &&
|
||||||
|
!IsPartOfShape(newBlockX, newBlockY))
|
||||||
{
|
{
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
@ -239,7 +257,8 @@ namespace Tetris
|
|||||||
Console.Write("│ ");
|
Console.Write("│ ");
|
||||||
for (int j = 0; j < WIDTH; j++)
|
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.Write(matrix[i, j]);
|
||||||
}
|
}
|
||||||
Console.ResetColor();
|
Console.ResetColor();
|
||||||
@ -250,14 +269,8 @@ namespace Tetris
|
|||||||
Console.WriteLine("Score: " + score);
|
Console.WriteLine("Score: " + score);
|
||||||
}
|
}
|
||||||
|
|
||||||
public int GetScore()
|
public int GetScore() { return score; }
|
||||||
{
|
public void IncreaseScore(int score) { this.score += score; }
|
||||||
return score;
|
|
||||||
}
|
|
||||||
public void IncreaseScore(int score)
|
|
||||||
{
|
|
||||||
this.score += score;
|
|
||||||
}
|
|
||||||
|
|
||||||
public void CheckForCompleteLines()
|
public void CheckForCompleteLines()
|
||||||
{
|
{
|
||||||
|
|||||||
@ -1,3 +1,5 @@
|
|||||||
# Tetris
|
# Tetris
|
||||||
|
|
||||||
## Simple tetris game
|
## Simple tetris game
|
||||||
|
|
||||||
|
- [SRS specifications](./TetrominoSRS.md)
|
||||||
|
|||||||
119
ShapesData.cs
Normal file
119
ShapesData.cs
Normal 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}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
};
|
||||||
|
}
|
||||||
@ -7,4 +7,13 @@
|
|||||||
<Nullable>enable</Nullable>
|
<Nullable>enable</Nullable>
|
||||||
</PropertyGroup>
|
</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>
|
</Project>
|
||||||
|
|||||||
BIN
Tetris.png
Normal file
BIN
Tetris.png
Normal file
Binary file not shown.
|
After Width: | Height: | Size: 209 KiB |
@ -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.
|
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:
|
Key purposes:
|
||||||
|
|
||||||
- Provide an engaging and simple game for retro gamers or users with minimal system resources.
|
- 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.
|
- Offer an accessible gaming option that works on most operating systems.
|
||||||
- Allow players to compete for high scores in a lightweight, resource-efficient environment.
|
- 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.
|
- The grid should be displayed using characters or symbols for blocks.
|
||||||
|
|
||||||
2. **Tetromino Types**
|
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.
|
- Tetrominoes should be represented using characters.
|
||||||
|
|
||||||
|

|
||||||
|
|
||||||
3. **Tetromino Movement**
|
3. **Tetromino Movement**
|
||||||
- Players must be able to move tetrominoes left and right using keyboard inputs.
|
- Players must be able to move tetrominoes left and right using keyboard inputs.
|
||||||
- The tetromino should fall automatically at a predefined speed.
|
- The tetromino should fall automatically at a predefined speed.
|
||||||
Loading…
Reference in New Issue
Block a user