This repository was archived by the owner on Jan 10, 2022. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 1
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
und Karrrrrrrrrrrrrrrrrrrrrrrrmarrrrrrrrrrrrrrrrrrrrrr wollte irgendwas mit slack
- Loading branch information
1 parent
b9c3a8d
commit aeea93a
Showing
6 changed files
with
190 additions
and
17 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,40 @@ | ||
using System; | ||
using System.Collections.Generic; | ||
using System.Drawing; | ||
using System.IO; | ||
using System.Linq; | ||
using System.Text; | ||
|
||
namespace Tetris.Core.Figures | ||
{ | ||
public abstract class BaseFigure | ||
{ | ||
public int Width => Bricks.Max(b => b.X) - Bricks.Min(b => b.X); | ||
public int Height => Bricks.Max(b => b.Y) - Bricks.Min(b => b.Y); | ||
public bool IsActive { get; set; } | ||
|
||
protected Brick RotationBrick; | ||
|
||
protected List<Brick> Bricks; | ||
|
||
public BaseFigure() | ||
{ | ||
Bricks = new List<Brick>(); | ||
IsActive = true; | ||
} | ||
|
||
public abstract void Rotate(); | ||
|
||
public void Draw(Graphics graphics, int cellWidth, int cellHeight) => | ||
Bricks.ForEach(b => b.Draw(graphics, cellWidth, cellHeight)); | ||
|
||
public void SetRelativePosition(int x, int y) => | ||
Bricks.ForEach(b => b.SetRelativePosition(x, y)); | ||
|
||
public virtual bool Intersect(int x, int y) => !Bricks.TrueForAll(b => !b.Intersect(x, y)); | ||
public virtual bool Intersect(Brick brick) => !Bricks.TrueForAll(b => !b.Intersect(brick.X, brick.Y)); | ||
|
||
public virtual bool Intersect(BaseFigure figure) => !figure.Bricks.TrueForAll(b => !Intersect(b)); | ||
|
||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,28 @@ | ||
using System; | ||
using System.Collections.Generic; | ||
using System.Drawing; | ||
using System.Linq; | ||
using System.Text; | ||
using System.Threading.Tasks; | ||
|
||
namespace Tetris.Core.Figures | ||
{ | ||
public class Border : BaseFigure | ||
{ | ||
public Border(int x, int y, int width, int height) | ||
{ | ||
IsActive = false; | ||
for (int i = x; i < x + width; i++) | ||
for (int o = y; o < y + height; o++) | ||
Bricks.Add(new Brick { X = i, Y = o }); | ||
} | ||
|
||
public override void Rotate() | ||
{ | ||
} | ||
public new void Draw(Graphics graphics, int cellWidth, int cellHeight) | ||
{ | ||
|
||
} | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,42 @@ | ||
using System; | ||
using System.Collections.Generic; | ||
using System.Linq; | ||
using System.Text; | ||
using System.Threading.Tasks; | ||
|
||
namespace Tetris.Core.Figures | ||
{ | ||
public class Stab : BaseFigure | ||
{ | ||
public Stab() | ||
{ | ||
for (int i = 0; i < 4; i++) | ||
{ | ||
var b = new Brick { X = 0, Y = i }; | ||
Bricks.Add(b); | ||
if (i == 1) | ||
RotationBrick = b; | ||
} | ||
} | ||
|
||
public override void Rotate() | ||
{ | ||
if(Bricks.GroupBy(x=>x.Y).ToList().Count > 1) | ||
{ | ||
for (int i = -1; i < 3; i++) | ||
{ | ||
Bricks[i+1].Y = RotationBrick.Y; | ||
Bricks[i+1].X = RotationBrick.X + i; | ||
} | ||
} | ||
else | ||
{ | ||
for (int i = -1; i < 3; i++) | ||
{ | ||
Bricks[i + 1].Y = RotationBrick.Y + i; | ||
Bricks[i + 1].X = RotationBrick.X; | ||
} | ||
} | ||
} | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters