Skip to content

Commit

Permalink
Refactor
Browse files Browse the repository at this point in the history
  • Loading branch information
kubagdynia committed Feb 14, 2024
1 parent 0439756 commit cbb3c93
Show file tree
Hide file tree
Showing 10 changed files with 393 additions and 413 deletions.
12 changes: 6 additions & 6 deletions Spacetris/BackgroundEffects/Starfield.cs
Original file line number Diff line number Diff line change
Expand Up @@ -14,9 +14,9 @@ public class Starfield : Transformable, Drawable
private readonly uint _maxMediumStars;
private readonly uint _maxLargeStars;

private readonly List<Point2> _smallStars = new();
private readonly List<Point2> _mediumStars = new();
private readonly List<Point2> _largeStars = new();
private readonly List<Point2> _smallStars = [];
private readonly List<Point2> _mediumStars = [];
private readonly List<Point2> _largeStars = [];

private readonly Random _randomX;

Expand Down Expand Up @@ -86,7 +86,7 @@ public void UpdateStarfield(float deltaTime)
_totalStarsMoveTimer = 0;

// Move the stars down and remove them if they cross the bottom line
for (int i = 0; i < _smallStars.Count; i++)
for (var i = 0; i < _smallStars.Count; i++)
{
if (_smallStars[i].Y > _height)
{
Expand All @@ -97,7 +97,7 @@ public void UpdateStarfield(float deltaTime)
_smallStars[i] += new Point2(0, 1);
}

for (int i = 0; i < _mediumStars.Count; i++)
for (var i = 0; i < _mediumStars.Count; i++)
{
if (_mediumStars[i].Y > _height)
{
Expand All @@ -108,7 +108,7 @@ public void UpdateStarfield(float deltaTime)
_mediumStars[i] += new Point2(0, 2);
}

for (int i = 0; i < _largeStars.Count; i++)
for (var i = 0; i < _largeStars.Count; i++)
{
if (_largeStars[i].Y > _height)
{
Expand Down
4 changes: 2 additions & 2 deletions Spacetris/Extensions/SfmlGraphicsExtension.cs
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ public static class SfmlGraphicsExtension
{
public static Vector2f Center(this Text text, float x, float y)
{
FloatRect textRect = text.GetLocalBounds();
var textRect = text.GetLocalBounds();

text.Origin = new Vector2f(
textRect.Left + textRect.Width / 2.0f,
Expand All @@ -20,7 +20,7 @@ public static Vector2f Center(this Text text, float x, float y)

public static Text Shadow(this Text text, int offset = 2, bool center = true)
{
Text shadowText = new Text
var shadowText = new Text
{
DisplayedString = text.DisplayedString,
Font = text.Font,
Expand Down
360 changes: 188 additions & 172 deletions Spacetris/GameStates/Menu/Menu.cs

Large diffs are not rendered by default.

39 changes: 17 additions & 22 deletions Spacetris/GameStates/Menu/MenuItem.cs
Original file line number Diff line number Diff line change
@@ -1,29 +1,24 @@
namespace Spacetris.GameStates.Menu;

public class MenuItem
public class MenuItem(
string name,
MenuItemType item,
int y,
int position,
bool enable = true,
MenuItemType parent = MenuItemType.None,
MenuItemFunctionType functionType = MenuItemFunctionType.None,
Func<object, object, object> functionObject = null)
{
public string Name { get; }
public int Y { get; set; }
public int Position { get; }
public MenuItemType Item { get; }
public bool Enable { get; set; }
public string Name { get; } = name;
public int Y { get; set; } = y;
public int Position { get; } = position;
public MenuItemType Item { get; } = item;
public bool Enable { get; set; } = enable;
public MenuItem[] SubMenuItems { get; set; }
public MenuItemType Parent { get; }
public MenuItemFunctionType FunctionType { get; }
public readonly Func<object, object, object> FunctionObject;

public MenuItem(string name, MenuItemType item, int y, int position, bool enable = true,
MenuItemType parent = MenuItemType.None, MenuItemFunctionType functionType = MenuItemFunctionType.None, Func<object, object, object> functionObject = null)
{
Name = name;
Item = item;
Y = y;
Position = position;
Enable = enable;
Parent = parent;
FunctionType = functionType;
FunctionObject = functionObject;
}
public MenuItemType Parent { get; } = parent;
public MenuItemFunctionType FunctionType { get; } = functionType;
public readonly Func<object, object, object> FunctionObject = functionObject;

public MenuItem(MenuItemType item, int y, int position, bool enable = true, MenuItemType parent = MenuItemType.None)
: this(item.ToString(), item, y, position, enable, parent)
Expand Down
Loading

0 comments on commit cbb3c93

Please sign in to comment.