public void SpawnAction() { Board board = CreateBoard(4, 2, new[] { // 0 1 2 3 Cube(3), Cube(3), Cube(1), Cube(3), // 0 Ball(1), Ball(1), Ball(2), Ball(1), // 1 }); var game = new Game(board); // IAction[] actions = game.Swap(new Point(2, 1), new Point(3, 1)); // Assert.IsInstanceOf(typeof(SwapAction), actions[0]); Assert.IsInstanceOf(typeof(DestroyAction), actions[1]); Assert.IsInstanceOf(typeof(FallDownAction), actions[2]); Assert.IsInstanceOf(typeof(SpawnAction), actions[3]); var spawnAct = (SpawnAction)actions[3]; var expectSpawnPos = new List <Point> { new Point(0, 0), new Point(1, 0), new Point(2, 0), }; Assert.AreEqual(expectSpawnPos.Count, spawnAct.Positions.Length); foreach (ItemPos spPos in spawnAct.Positions) { Assert.True(expectSpawnPos.Contains(spPos.Pos)); } }
public void FallDownAction() { Board board = CreateBoard(4, 2, new[] { // 0 1 2 3 Cube(5), Cube(6), Cube(7), Cube(8), // 0 Ball(1), Ball(1), Ball(2), Ball(1), // 1 }); var game = new Game(board); // IAction[] actions = game.Swap(new Point(2, 1), new Point(3, 1)); // Assert.IsInstanceOf(typeof(SwapAction), actions[0]); Assert.IsInstanceOf(typeof(DestroyAction), actions[1]); Assert.IsInstanceOf(typeof(FallDownAction), actions[2]); var fallAct = (FallDownAction)actions[2]; var expectFallPos = new List <FallDownPos> { new FallDownPos(new Point(0, 0), new Point(0, 1)), new FallDownPos(new Point(1, 0), new Point(1, 1)), new FallDownPos(new Point(2, 0), new Point(2, 1)), }; Assert.AreEqual(expectFallPos.Count, fallAct.Positions.Length); foreach (FallDownPos fPos in fallAct.Positions) { Assert.True(expectFallPos.Contains(fPos)); } }
public void Match3Vertical() { Board board = CreateBoard(4, 4, new[] { // 0 1 2 3 Ball(1), Cube(4), Cube(5), Cube(6), // 0 Ball(1), Cube(7), Cube(8), Cube(9), // 1 Ball(2), Cube(4), Cube(5), Cube(6), // 2 Ball(1), Cube(7), Cube(8), Cube(9), // 3 }); var game = new Game(board); // IAction[] actions = game.Swap(new Point(0, 2), new Point(0, 3)); // Assert.IsInstanceOf(typeof(SwapAction), actions[0]); Assert.IsInstanceOf(typeof(DestroyAction), actions[1]); var dAct = (DestroyAction)actions[1]; var destroyed = new List <Point> { new Point(0, 0), new Point(0, 1), new Point(0, 2), }; Assert.AreEqual(destroyed.Count, dAct.MatchDestroyedPos.Length); foreach (ItemPos dPos in dAct.MatchDestroyedPos) { Assert.True(destroyed.Contains(dPos.Pos)); } }
public void ChainedExplosions() { Board board = CreateBoard(4, 3, new[] { // 0 1 2 3 Cube(1), Cube(1), Cube(3), Cube(1), // 0 Cube(1), Cube(1), Bomb(2), Cube(1), // 1 Ball(1), Ball(1), Cube(3), Bomb(1), // 2 }); var game = new Game(board); // IAction[] actions = game.Swap(new Point(2, 2), new Point(3, 2)); // Console.Out.WriteLine(game.Dump()); var dAct = (DestroyAction)actions[1]; var matchBomb = new Point(2, 2); var chainBomb = new Point(2, 1); // Assert.False(dAct.MatchDestroyedPos.Any(p => p.Pos == chainBomb)); Assert.AreEqual(3, dAct.MatchDestroyedPos.Length); Assert.True(dAct.MatchDestroyedPos.Any(p => p.Pos == new Point(0, 2))); Assert.True(dAct.MatchDestroyedPos.Any(p => p.Pos == new Point(1, 2))); Assert.True(dAct.MatchDestroyedPos.Any(p => p.Pos == matchBomb)); Assert.True(dAct.DestroyedBy.Keys.Any(p => p.Pos == matchBomb)); Assert.True(dAct.DestroyedBy.Keys.Any(p => p.Pos == chainBomb)); // Chain bomb explosion ItemPos matchBombPos = dAct.DestroyedBy .Keys .First(p => p.Pos == matchBomb); ItemPos chainBombPos = dAct.DestroyedBy .Keys .First(p => p.Pos == chainBomb); ItemPos[] byMatchBombPos = dAct.DestroyedBy[matchBombPos]; ItemPos[] byChainBombPos = dAct.DestroyedBy[chainBombPos]; // Assert.AreEqual(4, byMatchBombPos.Length); Assert.True(byMatchBombPos.Any(p => p.Pos == new Point(1, 1))); Assert.True(byMatchBombPos.Any(p => p.Pos == new Point(2, 1))); Assert.True(byMatchBombPos.Any(p => p.Pos == new Point(3, 1))); Assert.True(byMatchBombPos.Any(p => p.Pos == new Point(3, 2))); Assert.AreEqual(3, byChainBombPos.Length); Assert.True(byChainBombPos.Any(p => p.Pos == new Point(1, 0))); Assert.True(byChainBombPos.Any(p => p.Pos == new Point(2, 0))); Assert.True(byChainBombPos.Any(p => p.Pos == new Point(3, 0))); }
public void SpawnBonusBombLine() { Board board = CreateBoard(5, 2, new[] { // 0 1 2 3 4 Cube(3), Cube(3), Ball(1), Cube(3), Cube(3), // 0 Ball(1), Ball(1), Ball(2), Ball(1), Ball(1), // 1 }); var game = new Game(board); // IAction[] actions = game.Swap(new Point(2, 0), new Point(2, 1)); // var dAct = (DestroyAction)actions[1]; var bomb = new Point(2, 1); Assert.AreEqual(bomb, dAct.SpawnBonuses[0].Pos); Assert.True(game.Items[bomb.X, bomb.Y].IsBombShape); }
public void SpawnBonusLine() { Board board = CreateBoard(4, 2, new[] { // 0 1 2 3 Cube(3), Ball(1), Cube(3), Cube(3), // 0 Ball(1), Ball(2), Ball(1), Ball(1), // 1 }); var game = new Game(board); // IAction[] actions = game.Swap(new Point(1, 0), new Point(1, 1)); // var dAct = (DestroyAction)actions[1]; var hLine = new Point(1, 1); Assert.AreEqual(hLine, dAct.SpawnBonuses[0].Pos); Assert.True(game.Items[hLine.X, hLine.Y].Shape == ItemShape.HLine); }
public void SpawnBonusBombCross() { Board board = CreateBoard(4, 3, new[] { // 0 1 2 3 Cube(1), Cube(1), Ball(1), Cube(1), // 0 Cube(1), Cube(1), Ball(1), Cube(1), // 1 Ball(1), Ball(1), Ball(2), Ball(1), // 2 }); var game = new Game(board); // IAction[] actions = game.Swap(new Point(2, 2), new Point(3, 2)); // Console.Out.WriteLine(game.Dump()); var dAct = (DestroyAction)actions[1]; var bomb = new Point(2, 2); Assert.AreEqual(bomb, dAct.SpawnBonuses[0].Pos); Assert.True(dAct.SpawnBonuses[0].Item.IsBombShape); }