Skip to content
This repository was archived by the owner on Jan 10, 2022. It is now read-only.

Commit

Permalink
Implemenation of Square and Tee + Rotation of those
Browse files Browse the repository at this point in the history
Collission works perfect, nothing to do there anymore
When you loose, everything will reset
  • Loading branch information
Gallimathias committed Aug 6, 2017
1 parent aeea93a commit b8cc24d
Show file tree
Hide file tree
Showing 11 changed files with 304 additions and 47 deletions.
8 changes: 8 additions & 0 deletions MusicBox/MusicBox.csproj
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
<Project Sdk="Microsoft.NET.Sdk">

<PropertyGroup>
<OutputType>Exe</OutputType>
<TargetFramework>netcoreapp1.1</TargetFramework>
</PropertyGroup>

</Project>
130 changes: 130 additions & 0 deletions MusicBox/Program.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,130 @@
using System;
using System.Threading;

/// <summary>
/// By XeeX from https://gist.github.com/XeeX/6220067
/// </summary>
namespace MusicBox
{
class Program
{
static void Main(string[] args)
{
Console.Beep(658, 125);
Console.Beep(1320, 500);
Console.Beep(990, 250);
Console.Beep(1056, 250);
Console.Beep(1188, 250);
Console.Beep(1320, 125);
Console.Beep(1188, 125);
Console.Beep(1056, 250);
Console.Beep(990, 250);
Console.Beep(880, 500);
Console.Beep(880, 250);
Console.Beep(1056, 250);
Console.Beep(1320, 500);
Console.Beep(1188, 250);
Console.Beep(1056, 250);
Console.Beep(990, 750);
Console.Beep(1056, 250);
Console.Beep(1188, 500);
Console.Beep(1320, 500);
Console.Beep(1056, 500);
Console.Beep(880, 500);
Console.Beep(880, 500);
Thread.Sleep(250);
Console.Beep(1188, 500);
Console.Beep(1408, 250);
Console.Beep(1760, 500);
Console.Beep(1584, 250);
Console.Beep(1408, 250);
Console.Beep(1320, 750);
Console.Beep(1056, 250);
Console.Beep(1320, 500);
Console.Beep(1188, 250);
Console.Beep(1056, 250);
Console.Beep(990, 500);
Console.Beep(990, 250);
Console.Beep(1056, 250);
Console.Beep(1188, 500);
Console.Beep(1320, 500);
Console.Beep(1056, 500);
Console.Beep(880, 500);
Console.Beep(880, 500);
Thread.Sleep(500);
Console.Beep(1320, 500);
Console.Beep(990, 250);
Console.Beep(1056, 250);
Console.Beep(1188, 250);
Console.Beep(1320, 125);
Console.Beep(1188, 125);
Console.Beep(1056, 250);
Console.Beep(990, 250);
Console.Beep(880, 500);
Console.Beep(880, 250);
Console.Beep(1056, 250);
Console.Beep(1320, 500);
Console.Beep(1188, 250);
Console.Beep(1056, 250);
Console.Beep(990, 750);
Console.Beep(1056, 250);
Console.Beep(1188, 500);
Console.Beep(1320, 500);
Console.Beep(1056, 500);
Console.Beep(880, 500);
Console.Beep(880, 500);
Thread.Sleep(250);
Console.Beep(1188, 500);
Console.Beep(1408, 250);
Console.Beep(1760, 500);
Console.Beep(1584, 250);
Console.Beep(1408, 250);
Console.Beep(1320, 750);
Console.Beep(1056, 250);
Console.Beep(1320, 500);
Console.Beep(1188, 250);
Console.Beep(1056, 250);
Console.Beep(990, 500);
Console.Beep(990, 250);
Console.Beep(1056, 250);
Console.Beep(1188, 500);
Console.Beep(1320, 500);
Console.Beep(1056, 500);
Console.Beep(880, 500);
Console.Beep(880, 500);
Thread.Sleep(500);
Console.Beep(660, 1000);
Console.Beep(528, 1000);
Console.Beep(594, 1000);
Console.Beep(495, 1000);
Console.Beep(528, 1000);
Console.Beep(440, 1000);
Console.Beep(419, 1000);
Console.Beep(495, 1000);
Console.Beep(660, 1000);
Console.Beep(528, 1000);
Console.Beep(594, 1000);
Console.Beep(495, 1000);
Console.Beep(528, 500);
Console.Beep(660, 500);
Console.Beep(880, 1000);
Console.Beep(838, 2000);
Console.Beep(660, 1000);
Console.Beep(528, 1000);
Console.Beep(594, 1000);
Console.Beep(495, 1000);
Console.Beep(528, 1000);
Console.Beep(440, 1000);
Console.Beep(419, 1000);
Console.Beep(495, 1000);
Console.Beep(660, 1000);
Console.Beep(528, 1000);
Console.Beep(594, 1000);
Console.Beep(495, 1000);
Console.Beep(528, 500);
Console.Beep(660, 500);
Console.Beep(880, 1000);
Console.Beep(838, 2000);
}
}
}
2 changes: 2 additions & 0 deletions Tetris.Core/Brick.cs
Original file line number Diff line number Diff line change
Expand Up @@ -38,5 +38,7 @@ public void Draw(Graphics graphics, int cellWidth, int cellHeight)
}

public bool Intersect(int x, int y) => x == X && y == Y;

public override string ToString() => $"X:{X} | Y:{Y}";
}
}
14 changes: 9 additions & 5 deletions Tetris.Core/Figures/BaseFigure.cs
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@ public abstract class BaseFigure
public bool IsActive { get; set; }

protected Brick RotationBrick;

protected List<Brick> Bricks;

public BaseFigure()
Expand All @@ -24,17 +24,21 @@ public BaseFigure()
}

public abstract void Rotate();
public abstract void CounterRotate();

public void Draw(Graphics graphics, int cellWidth, int cellHeight) =>
Bricks.ForEach(b => b.Draw(graphics, cellWidth, cellHeight));

public void SetRelativePosition(int x, int y) =>
public void Move(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(int x, int y) => Bricks.Any(b => b.Intersect(x, y));
public virtual bool Intersect(Brick brick) => Bricks.Any(b => b.Intersect(brick.X, brick.Y));

public virtual bool Intersect(BaseFigure figure) => !figure.Bricks.TrueForAll(b => !Intersect(b));
public virtual bool Intersect(BaseFigure figure) => figure.Bricks.Any(b => Intersect(b));

}
}
3 changes: 3 additions & 0 deletions Tetris.Core/Figures/Border.cs
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,9 @@ public Border(int x, int y, int width, int height)
public override void Rotate()
{
}

public override void CounterRotate() => Rotate();

public new void Draw(Graphics graphics, int cellWidth, int cellHeight)
{

Expand Down
24 changes: 24 additions & 0 deletions Tetris.Core/Figures/Square.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,24 @@
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;

namespace Tetris.Core.Figures
{
public class Square : BaseFigure
{
public Square()
{
for (int i = 0; i < 2; i++)
for (int o = 0; o < 2; o++)
Bricks.Add(new Brick { X = o, Y = i });
}

public override void Rotate()
{
}
public override void CounterRotate() => Rotate();

}
}
2 changes: 2 additions & 0 deletions Tetris.Core/Figures/Stab.cs
Original file line number Diff line number Diff line change
Expand Up @@ -38,5 +38,7 @@ public override void Rotate()
}
}
}
public override void CounterRotate() => Rotate();

}
}
69 changes: 69 additions & 0 deletions Tetris.Core/Figures/Tee.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,69 @@
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;

namespace Tetris.Core.Figures
{
public class Tee : BaseFigure
{
public Brick this[int x, int y]
{
get
{
var originX = RotationBrick.X - 1;
var originY = RotationBrick.Y - 1;

return Bricks.FirstOrDefault(o => o.X == x + originX && o.Y == y + originY);
}
}
Brick a;
Brick b;
Brick c;
Brick d;

public Tee()
{
var rotBrick = new Brick { X = 1, Y = 1 };

var b = new List<Brick> {
new Brick { X = 0, Y = 1 },
new Brick { X = 2, Y = 1 },
new Brick { X = 1, Y = 0 },
rotBrick, };
Bricks.AddRange(b);
RotationBrick = rotBrick;

}

public override void Rotate()
{
/*
[0,1] (x+1 y+1)=> [1,2]
[1,0] (x-1 y+1)=> [0,1]
[2,1] (x-1 y-1)=> [1,0]
[1,2] (x+1 y-1)=> [2,1]
*/
a = this[0, 1];
b = this[1, 0];
c = this[2, 1];
d = this[1, 2];
if (a != null)
a.SetRelativePosition(1, 1);
if (b != null)
b.SetRelativePosition(-1, 1);
if (c != null)
c.SetRelativePosition(-1, -1);
if (d != null)
d.SetRelativePosition(1, -1);
}

public override void CounterRotate()
{
for (int i = 0; i < 3; i++)
Rotate();
}

}
}
Loading

0 comments on commit b8cc24d

Please sign in to comment.