예제 #1
0
        public void TestCheckCollisions()
        {
            var piece = new Piece(new List<Point>()
            {
                new Point(0,0,3,0),
                new Point(0,1,3,1),
                new Point(0,2,3,2),
                new Point(1,2,4,2)
            }.ToImmutableArray());

            var field = new List<Point>()
            {
                new Point(0,0,2,0),
                new Point(0,0,2,1),
                new Point(0,0,4,2),
                new Point(0,0,3,2)
            }.ToImmutableHashSet();
            var field2 = new List<Point>()
            {
                new Point(0,0,2,0),
                new Point(0,0,2,1),
                new Point(0,0,4,0),
                new Point(0,0,3,3)
            }.ToImmutableHashSet();
            var t = new Tetris(@"C:\Users\Meow\Desktop\git\ShporaTetris\ShporaTetris\bin\Debug\tests\smallest.json");
            Assert.AreEqual(true, t.CheckCollisions(piece, field, 6, 5));
            Assert.AreEqual(false, t.CheckCollisions(piece, field2,6,5));
        }
예제 #2
0
		private static string PrintField(Piece currentPiece, ImmutableHashSet<Point> gameField, int width, int height)
		{
			var result = "";
			var formattedField = new string[width, height];
			foreach (var cell in gameField)
				formattedField[cell.AbsX, cell.AbsY] = "#";
			foreach (var cell in currentPiece.Coordinates)
				formattedField[cell.AbsX, cell.AbsY] = "*";
			for (var i = 0; i < height; i++)
			{
				for (var j = 0; j < width; j++)
					result += formattedField[j, i] ?? ".";
				result += "/n";
			}
			return result;
		}
예제 #3
0
		public bool CheckCollisions(Piece piece, ImmutableHashSet<Point> gameField, int width, int height)
		{
			return piece.Coordinates
				.Any(cell => cell.AbsX < 0 || cell.AbsY < 0 
			                                                 || cell.AbsX >= width || cell.AbsY >= height) || gameField.Overlaps(piece.Coordinates);
		}
예제 #4
0
		public ImmutableHashSet<Point> PlacePiece(Piece piece, ImmutableHashSet<Point> gameField)
		{
			return
				gameField.Union(piece.Coordinates);
		}
예제 #5
0
        public void TestPlacePiece()
        {
            var field = new List<Point>()
            {
                new Point(0,0,0,3),
                new Point(0,0,1,3),
                new Point(0,0,1,4),
                new Point(0,0,2,0),
                new Point(0,0,2,1),
                new Point(0,0,2,3),
                new Point(0,0,3,3),
                new Point(0,0,4,1),
                new Point(0,0,4,3),
                new Point(0,0,5,4),

            }.ToImmutableHashSet();
            var piece = new Piece(new List<Point>()
            {
                new Point(0,0,3,0),
                new Point(0,1,3,1),
                new Point(0,2,3,2),
                new Point(1,2,4,2)
            }.ToImmutableArray());
            var t = new Tetris(@"C:\Users\Meow\Desktop\git\ShporaTetris\ShporaTetris\bin\Debug\tests\smallest.json");
            var expected = new List<Point>()
            {
                new Point(0,0,0,3),
                new Point(0,0,1,3),
                new Point(0,0,1,4),
                new Point(0,0,2,0),
                new Point(0,0,2,1),
                new Point(0,0,2,3),
                new Point(0,0,3,3),
                new Point(0,0,4,1),
                new Point(0,0,4,3),
                new Point(0,0,5,4),
                new Point(0,0,3,0),
                new Point(0,1,3,1),
                new Point(0,2,3,2),
                new Point(1,2,4,2)

            }.ToImmutableHashSet();
            var isTrue = expected.SetEquals(t.PlacePiece(piece, field));
            Assert.AreEqual(true, isTrue);
        }
예제 #6
0
 public void TestPieceRotate2()
 {
     var piece = new Piece(new List<Point>()
     {
         new Point(0,0,3,0),
         new Point(0,1,3,1),
         new Point(0,2,3,2),
         new Point(1,2,4,2)
     }.ToImmutableArray());
     var p1 = piece.Rotate(DirectionOfRotation.Clockwise);
     var expected = new Piece(new List<Point>()
     {
         new Point(0,0,3,0),
         new Point(0,1,2,0),
         new Point(0,2,1,0),
         new Point(1,2,1,1)
     }.ToImmutableArray());
     Assert.AreEqual(p1, expected, p1.Coordinates[2].AbsX + " " + p1.Coordinates[2].AbsY);
 }
예제 #7
0
 public void TestPieceMove2()
 {
     var piece = new Piece(new List<Point>()
     {
         new Point(0,0,3,0),
         new Point(0,1,3,1),
         new Point(0,2,3,2),
         new Point(1,2,4,2)
     }.ToImmutableArray());
     var p1 = piece.Move(DirectionOfMovement.Left);
     var expected = new Piece(new List<Point>()
      {
         new Point(0,0,2,0),
         new Point(0,1,2,1),
         new Point(0,2,2,2),
         new Point(1,2,3,2)
     }.ToImmutableArray());
     Assert.AreEqual(p1, expected, p1.Coordinates[2].AbsX + " " + p1.Coordinates[2].AbsY);
 }
예제 #8
0
 public void TestPieceDrop3()
 {
     var piece = new Piece(new List<Point>()
     {
         new Point(0,0),
         new Point(0,-1),
         new Point(0,2),
         new Point(1,2)
     }.ToImmutableArray());
     var p1 = piece.Drop(9);
     var expected = new Piece(new List<Point>()
     {
         new Point(0,0,3,1),
         new Point(0,0,3,0),
         new Point(0,0,3,3),
         new Point(0,0,4,3)
     }.ToImmutableArray());
     Assert.AreEqual(p1, expected, p1.Coordinates[1].AbsX + " " + p1.Coordinates[1].AbsY);
 }