public void TestEdgesAndMovement() { Block TestBlock = new Block_Line(Color.Blue, 20, 10, 20, 4, 1); TestBlock.Rotate = false; TestBlock.Assign(); TestBlock.AssignEdges(); int x = 20 * (TestBlock.Size - 1); TestBlock.MoveRight(x); TestBlock.MoveRight(x); TestBlock.MoveRight(x); TestBlock.AssignEdges(); foreach (Point2D lte in TestBlock.TopLeftEdges) { Assert.AreEqual(20 + 20 * 3, lte.X); Assert.AreEqual(10, lte.Y); } TestBlock.MoveDown(x); TestBlock.MoveDown(x); TestBlock.AssignEdges(); foreach (Point2D rbe in TestBlock.BottomRightEdges) { Assert.AreEqual(20 + 20 * TestBlock.Size + 20 * 3, rbe.X); Assert.AreEqual(10 + TestBlock.Length + 20 * 2, rbe.Y); } }
public void TestBottomEdgeAssign() { Block TestBlock = new Block_Line(Color.Blue, 20, 10, 20, 4, 1); TestBlock.Rotate = false; TestBlock.Assign(); TestBlock.AssignEdges(); foreach (Point2D rbe in TestBlock.BottomRightEdges) { Assert.AreEqual(20 + 20 * TestBlock.Size, rbe.X); Assert.AreEqual(10 + TestBlock.Length, rbe.Y); } foreach (Point2D lbe in TestBlock.BottomLeftEdges) { Assert.AreEqual(20, lbe.X); Assert.AreEqual(10 + TestBlock.Length, lbe.Y); } //test after Rotation TestBlock.Rotate = true; TestBlock.AssignEdges(); foreach (Point2D rbe in TestBlock.BottomRightEdges) { Assert.AreEqual(20 + TestBlock.Length, rbe.X); Assert.AreEqual(10 + 20 * TestBlock.Size, rbe.Y); } foreach (Point2D lbe in TestBlock.BottomLeftEdges) { Assert.AreEqual(20, lbe.X); Assert.AreEqual(10 + 20 * TestBlock.Size, lbe.Y); } }
public void TestMovement() { Block TestBlock = new Block_Line(Color.Blue, 20, 10, 20, 4, 1); TestBlock.Rotate = false; TestBlock.Assign(); Assert.AreEqual(20, TestBlock.X); Assert.AreEqual(10, TestBlock.Y); int x = 20 * (TestBlock.Size - 1); for (int i = 0; i < 2; i++) { TestBlock.MoveDown(x); } for (int i = 0; i < 4; i++) { TestBlock.MoveRight(x); } Assert.AreEqual(20 + 20 * 4, TestBlock.X); Assert.AreEqual(10 + 20 * 2, TestBlock.Y); for (int i = 0; i < 3; i++) { TestBlock.MoveLeft(); } Assert.AreEqual(20 + 20 * 4 - 20 * 3, TestBlock.X); Assert.AreEqual(50, TestBlock.Y); for (int i = 0; i < 5; i++) { TestBlock.MoveUp(); } Assert.AreEqual(20 + 20 * 4 - 20 * 3, TestBlock.X); Assert.AreEqual(10, TestBlock.Y); //Tesing After Rotaion TestBlock.Rotate = true; TestBlock.Assign(); for (int i = 0; i < 30; i++) { TestBlock.MoveDown(x); } Assert.AreEqual(20 + 20 * 4 - 20 * 3, TestBlock.X); Assert.AreEqual(390 - x, TestBlock.Y); for (int i = 0; i < 30; i++) { TestBlock.MoveRight(x); } Assert.AreEqual(400, TestBlock.X); Assert.AreEqual(390 - x, TestBlock.Y); }
public void TestInitialisation() { Block TestBlock = new Block_Line(Color.Blue, 20, 10, 20, 4, 1); Assert.AreEqual(20, TestBlock.X); Assert.AreEqual(10, TestBlock.Y); Assert.AreEqual(20, TestBlock.Length); Assert.AreEqual(4, TestBlock.Size); Assert.AreEqual(false, TestBlock.Used); TestBlock.Used = true; Assert.AreEqual(true, TestBlock.Used); }
/// <summary> /// Initializes a new instance of the <see cref="MyGame.Player"/> class. Adds all 21 blocks to the players blockset /// </summary> /// <param name="name">Name.</param> /// <param name="color">Color.</param> public Player(string name, Color color) { _name = name; _color = color; _playerSet = new BlockSet(); _move = 1; Block b1 = new Block_L(_color, 25, 425, 20, 3, 1); Block b2 = new Block_L(_color, 95, 425, 20, 4, 2); Block b3 = new Block_L(_color, 165, 425, 20, 5, 3); Block b4 = new Block_T(_color, 235, 425, 20, 4, 4); Block b5 = new Block_T(_color, 305, 425, 20, 5, 5); Block b6 = new Block_TSymmetric(_color, 375, 425, 20, 5, 6); Block b7 = new Block_Line(_color, 445, 425, 20, 1, 7); Block b8 = new Block_Line(_color, 515, 425, 20, 2, 8); Block b9 = new Block_Line(_color, 585, 425, 20, 3, 9); Block b10 = new Block_Line(_color, 655, 425, 20, 4, 10); Block b11 = new Block_Line(_color, 725, 425, 20, 5, 11); Block b12 = new Block_NoRotation(_color, 25, 515, 20, 4, 12); Block b13 = new Block_NoRotation(_color, 95, 515, 20, 5, 13); Block b14 = new Block_Z(_color, 165, 515, 20, 4, 14); Block b15 = new Block_Z(_color, 235, 515, 20, 5, 15); Block b16 = new Block_C(_color, 305, 515, 20, 5, 16); Block b17 = new Block_LSymmetric(_color, 375, 515, 20, 5, 17); Block b18 = new Block_M(_color, 445, 515, 20, 5, 18); Block b19 = new Block_ZSymmetric(_color, 515, 515, 20, 5, 19); Block b20 = new Block_N1(_color, 585, 515, 20, 5, 20); Block b21 = new Block_N2(_color, 655, 515, 20, 5, 21); _playerSet.AddBlock(b1); _playerSet.AddBlock(b2); _playerSet.AddBlock(b3); _playerSet.AddBlock(b4); _playerSet.AddBlock(b5); _playerSet.AddBlock(b6); _playerSet.AddBlock(b7); _playerSet.AddBlock(b8); _playerSet.AddBlock(b9); _playerSet.AddBlock(b10); _playerSet.AddBlock(b11); _playerSet.AddBlock(b12); _playerSet.AddBlock(b13); _playerSet.AddBlock(b14); _playerSet.AddBlock(b15); _playerSet.AddBlock(b16); _playerSet.AddBlock(b17); _playerSet.AddBlock(b18); _playerSet.AddBlock(b19); _playerSet.AddBlock(b20); _playerSet.AddBlock(b21); }
public void TestAssign() { Block TestBlock = new Block_Line(Color.Blue, 20, 10, 20, 4, 1); TestBlock.Rotate = false; TestBlock.Assign(); for (int i = 0; i < TestBlock.Squares.Count; i++) { Assert.AreEqual(20 + i * TestBlock.Length, TestBlock.Squares[i].X); Assert.AreEqual(10, TestBlock.Squares[i].Y); } TestBlock.Rotate = true; TestBlock.Assign(); for (int i = 0; i < TestBlock.Squares.Count; i++) { Assert.AreEqual(10 + i * TestBlock.Length, TestBlock.Squares[i].Y); Assert.AreEqual(20, TestBlock.Squares[i].X); } }
public void TestMoveLeft() { Block TestBlock = new Block_Line(Color.Blue, 20, 10, 20, 4, 1); TestBlock.Rotate = false; TestBlock.Assign(); Assert.AreEqual(20, TestBlock.X); int x = 20 * (TestBlock.Size - 1); TestBlock.MoveLeft(); TestBlock.MoveLeft(); Assert.AreEqual(20, TestBlock.X); for (int i = 0; i < 30; i++) { TestBlock.MoveLeft(); } Assert.AreEqual(20, TestBlock.X); //Testing After Block is Rotated TestBlock.Rotate = true; TestBlock.Assign(); Assert.AreEqual(20, TestBlock.X); TestBlock.MoveLeft(); TestBlock.MoveLeft(); Assert.AreEqual(20, TestBlock.X); for (int i = 0; i < 30; i++) { TestBlock.MoveLeft(); } Assert.AreEqual(20, TestBlock.X); }
/// <summary> /// Player Selects the Block /// </summary> /// <param name="player">Player.</param> public override void SelectBlock(Player player) { _BlokusBoard.BackgroundBox(); _BlokusBoard.DrawPlayerDetails(); _BlokusBoard.DrawShapeBox(); _BlokusBoard.SingleBlockBox(); _BlokusBoard.DrawBoard(); player.PlayerSet.Draw(); _BlokusBoard.GameInstructionDisplay(1); turnDisplay(); Point2D rand = new Point2D(); if (SwinGame.KeyTyped(KeyCode.vk_e)) { _end = true; Play(); } if (_p.Move != 1 && chosenblock == false) { if (player.PlayerSet.Blocks.Count == 0) { _end = true; Play(); } else { randomselection = choose.Next(player.PlayerSet.Blocks.Count); rand = player.PlayerSet.ReturnNum(_p.PlayerSet.GetBlockId(player.PlayerSet.Blocks [randomselection])); if ((player.PlayerSet.Blocks [randomselection] is Block_NoRotation && player.PlayerSet.Blocks [randomselection].Size == 5) || (player.PlayerSet.Blocks [randomselection] is Block_M)) { rand.X += 20; } player.PlayerSet.SelectBlockAt(rand); chosenblock = true; player.PlayerSet.DrawChosen(); } } else { player.PlayerSet.DrawChosen(); } if (_p.Move > 1) { foreach (Block b in player.PlayerSet.Blocks) { if (player.PlayerSet.Blocks.IndexOf(b) == randomselection) { b.Draw(); } } } if (SwinGame.MouseClicked(MouseButton.LeftButton)) { if (_p.Move == 1 && chosenblock == false) { player.PlayerSet.SelectBlockAt(SwinGame.MousePosition()); } foreach (Block b in player.PlayerSet.Blocks) { if (b.Used == false) { if (b is Block_Line) { _temp = new Block_Line(Color.Black, 0, 0, 0, 0, 0); _display = new Block_Line(Color.Black, 0, 0, 0, 0, 0); } else if (b is Block_Z) { _temp = new Block_Z(Color.Black, 0, 0, 0, 0, 0); _display = new Block_Z(Color.Black, 0, 0, 0, 0, 0); } else if (b is Block_NoRotation) { _temp = new Block_NoRotation(Color.Black, 0, 0, 0, 0, 0); _display = new Block_NoRotation(Color.Black, 0, 0, 0, 0, 0); } else if (b is Block_L) { _temp = new Block_L(Color.Black, 0, 0, 0, 0, 0); _display = new Block_L(Color.Black, 0, 0, 0, 0, 0); } else if (b is Block_LSymmetric) { _temp = new Block_LSymmetric(Color.Black, 0, 0, 0, 0, 0); _display = new Block_LSymmetric(Color.Black, 0, 0, 0, 0, 0); } else if (b is Block_M) { _temp = new Block_M(Color.Black, 0, 0, 0, 0, 0); _display = new Block_M(Color.Black, 0, 0, 0, 0, 0); } else if (b is Block_T) { _temp = new Block_T(Color.Black, 0, 0, 0, 0, 0); _display = new Block_T(Color.Black, 0, 0, 0, 0, 0); } else if (b is Block_C) { _temp = new Block_C(Color.Black, 0, 0, 0, 0, 0); _display = new Block_C(Color.Black, 0, 0, 0, 0, 0); } else if (b is Block_TSymmetric) { _temp = new Block_TSymmetric(Color.Black, 0, 0, 0, 0, 0); _display = new Block_TSymmetric(Color.Black, 0, 0, 0, 0, 0); } else if (b is Block_ZSymmetric) { _temp = new Block_ZSymmetric(Color.Black, 0, 0, 0, 0, 0); _display = new Block_ZSymmetric(Color.Black, 0, 0, 0, 0, 0); } else if (b is Block_N1) { _temp = new Block_N1(Color.Black, 0, 0, 0, 0, 0); _display = new Block_N1(Color.Black, 0, 0, 0, 0, 0); } else if (b is Block_N2) { _temp = new Block_N2(Color.Black, 0, 0, 0, 0, 0); _display = new Block_N2(Color.Black, 0, 0, 0, 0, 0); } _temp.X = 200; _temp.Y = 190; _temp.Length = b.Length; _temp.Size = b.Size; _temp.Color = b.Color; _temp.Number = b.Number; _display.Length = b.Length; _display.Size = b.Size; _display.Color = b.Color; _play = true; } } } }
/// <summary> /// Player Selects the Block /// </summary> /// <param name="player">Player.</param> public override void SelectBlock(Player player) { _BlokusBoard.BackgroundBox(); _BlokusBoard.DrawPlayerDetails(); _BlokusBoard.DrawShapeBox(); _BlokusBoard.SingleBlockBox(); _BlokusBoard.DrawBoard(); player.PlayerSet.Draw(); _BlokusBoard.GameInstructionDisplay(0); turnDisplay(); if (SwinGame.KeyTyped(KeyCode.vk_e)) { _end = true; Play(); } if (SwinGame.MouseClicked(MouseButton.LeftButton)) { player.PlayerSet.SelectBlockAt(SwinGame.MousePosition()); foreach (Block b in player.PlayerSet.Blocks) { if (b.Used == false) { if (b is Block_Line) { _temp = new Block_Line(Color.Black, 0, 0, 0, 0, 0); _display = new Block_Line(Color.Black, 0, 0, 0, 0, 0); } else if (b is Block_Z) { _temp = new Block_Z(Color.Black, 0, 0, 0, 0, 0); _display = new Block_Z(Color.Black, 0, 0, 0, 0, 0); } else if (b is Block_NoRotation) { _temp = new Block_NoRotation(Color.Black, 0, 0, 0, 0, 0); _display = new Block_NoRotation(Color.Black, 0, 0, 0, 0, 0); } else if (b is Block_L) { _temp = new Block_L(Color.Black, 0, 0, 0, 0, 0); _display = new Block_L(Color.Black, 0, 0, 0, 0, 0); } else if (b is Block_LSymmetric) { _temp = new Block_LSymmetric(Color.Black, 0, 0, 0, 0, 0); _display = new Block_LSymmetric(Color.Black, 0, 0, 0, 0, 0); } else if (b is Block_T) { _temp = new Block_T(Color.Black, 0, 0, 0, 0, 0); _display = new Block_T(Color.Black, 0, 0, 0, 0, 0); } else if (b is Block_C) { _temp = new Block_C(Color.Black, 0, 0, 0, 0, 0); _display = new Block_C(Color.Black, 0, 0, 0, 0, 0); } else if (b is Block_TSymmetric) { _temp = new Block_TSymmetric(Color.Black, 0, 0, 0, 0, 0); _display = new Block_TSymmetric(Color.Black, 0, 0, 0, 0, 0); } else if (b is Block_M) { _temp = new Block_M(Color.Black, 0, 0, 0, 0, 0); _display = new Block_M(Color.Black, 0, 0, 0, 0, 0); } else if (b is Block_ZSymmetric) { _temp = new Block_ZSymmetric(Color.Black, 0, 0, 0, 0, 0); _display = new Block_ZSymmetric(Color.Black, 0, 0, 0, 0, 0); } else if (b is Block_N1) { _temp = new Block_N1(Color.Black, 0, 0, 0, 0, 0); _display = new Block_N1(Color.Black, 0, 0, 0, 0, 0); } else if (b is Block_N2) { _temp = new Block_N2(Color.Black, 0, 0, 0, 0, 0); _display = new Block_N2(Color.Black, 0, 0, 0, 0, 0); } _temp.X = 200; _temp.Y = 190; _temp.Length = b.Length; _temp.Size = b.Size; _temp.Color = b.Color; _temp.Number = b.Number; _display.Length = b.Length; _display.Size = b.Size; _display.Color = b.Color; _play = true; } } } }