public List <WhereCanMatch> GetWheresCanMatch(Position sourcePosition, MatchLineModel matchLineModel, GemType matchingType) { wheresCanMatch.Clear(); foreach (var whereCanMatch in matchLineModel.wheresCanMatch) { var matchCount = 0; foreach (var matchOffset in whereCanMatch.MatchOffsets) { if (!IsAcceptableIndex(sourcePosition, matchOffset[0], matchOffset[1])) { break; } var matchPosition = Position.Get(sourcePosition, matchOffset[0], matchOffset[1]); if (IsMovableTile(matchPosition) && (sourcePosition.index == matchPosition.index || GetGemModel(matchPosition).CanMatch(matchingType))) { matchCount++; } else { break; } } if (matchCount == whereCanMatch.MatchOffsets.Count) { wheresCanMatch.Add(whereCanMatch); } } return(wheresCanMatch); }
/// <summary> /// Used to spawn a unit /// </summary> /// <param name="Unit"></param> /// <param name="Model"></param> public void SpawnUnit(GameObject Unit, UnitModel Model) { // Check if the player can spawn a unit if (!m_gameManager.CheckForBalance(Model) || !CoolDownIsOver || m_gameManager.GameStatus != GameManager.MatchGameStatus.inProgress) { return; } /// Decrement the money m_gameManager.DecrementMoney(Model); // Get the active line MatchLineModel activeLine = m_gameManager.MatchLines.Find(x => x.PlayerSelected == true); if (activeLine.Status != MatchLineModel.LineState.inProgress) { return; } // spawn a unit and set all its variables var unit = Instantiate(Unit, activeLine.PlayerSpawnPoint.transform.position, activeLine.PlayerSpawnPoint.transform.rotation, m_gameManager.UnitContainer.transform); unit.GetComponent <UnitController>().SpawnPoint = activeLine.PlayerSpawnPoint.transform; unit.GetComponent <UnitController>().TargetPoint = activeLine.OpponentSpawnPoint.transform; unit.GetComponent <UnitController>().IsPlayer = true; unit.GetComponent <UnitController>().LineIndex = activeLine.index; unit.GetComponent <UnitController>().GameManager = this.m_gameManager; // Increment thhe line's weight activeLine.PlayerWeight += Model.Weight; // Start cooldown before the player can spawn another unit StartCoroutine(WaitUntilCooldown(3)); }
public void ExistAnyMatches() { //1. Arrange var gameModel = GetGameModel(); var gameController = GetGameController(gameModel); var gemModels = gameModel.GemModels; var normalGemModels = (from GemModel gemModel in gemModels where gemModel is EmptyGemModel select gemModel).ToList(); //2. Act var sampleGemTypes = new GemType[] { GemType.RedGem, GemType.RedGem, GemType.RedGem, GemType.RedGem, GemType.RedGem, GemType.GreenGem, GemType.RedGem, GemType.GreenGem, GemType.GreenGem }; var index = 0; foreach (var sampleGemType in sampleGemTypes) { normalGemModels[index].Type = sampleGemTypes[index]; index++; } //3. Assert Assert.AreEqual(GemType.EmptyGem, gameController.GetGemModel(Position.Get(0, 0)).Type); Assert.AreEqual(GemType.RedGem, gameController.GetGemModel(Position.Get(0, 1)).Type); //1. Arrange var horizontalMatch = new MatchLineModel(-2, 0, 3, 1); var verticalMatch = new MatchLineModel(-2, 0, 1, 3); var sqaureMatch = new MatchLineModel(-1, -1, 2, 2); //2. Act & Assert Assert.AreEqual(3, horizontalMatch.wheresCanMatch[0].MatchOffsets.Count); var position = Position.Get(0, 0); Assert.AreEqual(true, gameController.GetWheresCanMatch(position, horizontalMatch, GemType.RedGem)); Assert.AreEqual(true, gameController.GetWheresCanMatch(position, verticalMatch, GemType.RedGem)); Assert.AreEqual(true, gameController.GetWheresCanMatch(position, sqaureMatch, GemType.RedGem)); Assert.AreEqual(false, gameController.GetWheresCanMatch(position, horizontalMatch, GemType.GreenGem)); Assert.AreEqual(false, gameController.GetWheresCanMatch(position, verticalMatch, GemType.PurpleGem)); Assert.AreEqual(false, gameController.GetWheresCanMatch(position, sqaureMatch, GemType.BlueGem)); }
public List <GemModel> GetAnyMatches(GemModel sourceGemModel, MatchLineModel matchLineModel) { matchedGemModels.Clear(); foreach (var whereCanMatch in matchLineModel.wheresCanMatch) { foreach (var matchOffset in whereCanMatch.MatchOffsets) { if (!IsAcceptableIndex(sourceGemModel.Position, matchOffset[0], matchOffset[1])) { continue; } var matchingPosition = Position.Get(sourceGemModel.Position, matchOffset[0], matchOffset[1]); if (!IsMovableTile(matchingPosition)) { continue; } var matchingGemModel = GetGemModel(matchingPosition); if (sourceGemModel.CanMatch(matchingGemModel.Type) && Model.currentTurn > matchingGemModel.preservedFromMatch && !IsFalling(matchingGemModel) ) { matchedGemModels.Add(matchingGemModel); } else { // Need to match about all offsets. break; } } if (matchedGemModels.Count == whereCanMatch.MatchOffsets.Count) { // Finally found! break; } else { matchedGemModels.Clear(); } } return(matchedGemModels); }
public void MatchLineModel() { //1. Arrange & 2. Act var matchLineModel = new MatchLineModel(-2, 0, 3, 1); //3. Assert var whereCanMatch = matchLineModel.wheresCanMatch[0]; Assert.AreEqual(3, whereCanMatch.MatchOffsets.Count); Assert.AreEqual(new int[2] { -2, 0 }, whereCanMatch.MatchOffsets[0]); Assert.AreEqual(new int[2] { -1, 0 }, whereCanMatch.MatchOffsets[1]); Assert.AreEqual(new int[2] { 0, 0 }, whereCanMatch.MatchOffsets[2]); whereCanMatch = matchLineModel.wheresCanMatch[1]; Assert.AreEqual(3, whereCanMatch.MatchOffsets.Count); Assert.AreEqual(new int[2] { -1, 0 }, whereCanMatch.MatchOffsets[0]); Assert.AreEqual(new int[2] { 0, 0 }, whereCanMatch.MatchOffsets[1]); Assert.AreEqual(new int[2] { 1, 0 }, whereCanMatch.MatchOffsets[2]); whereCanMatch = matchLineModel.wheresCanMatch[2]; Assert.AreEqual(new int[2] { 0, 0 }, whereCanMatch.MatchOffsets[0]); Assert.AreEqual(3, whereCanMatch.MatchOffsets.Count); Assert.AreEqual(new int[2] { 1, 0 }, whereCanMatch.MatchOffsets[1]); Assert.AreEqual(new int[2] { 2, 0 }, whereCanMatch.MatchOffsets[2]); //1. Arrange & 2. Act matchLineModel = new MatchLineModel(-1, -1, 2, 2); //3. Assert whereCanMatch = matchLineModel.wheresCanMatch[0]; Assert.AreEqual(4, whereCanMatch.MatchOffsets.Count); Assert.AreEqual(new int[2] { -1, -1 }, whereCanMatch.MatchOffsets[0]); Assert.AreEqual(new int[2] { 0, -1 }, whereCanMatch.MatchOffsets[1]); Assert.AreEqual(new int[2] { -1, 0 }, whereCanMatch.MatchOffsets[2]); Assert.AreEqual(new int[2] { 0, 0 }, whereCanMatch.MatchOffsets[3]); whereCanMatch = matchLineModel.wheresCanMatch[1]; Assert.AreEqual(4, whereCanMatch.MatchOffsets.Count); Assert.AreEqual(new int[2] { 0, -1 }, whereCanMatch.MatchOffsets[0]); Assert.AreEqual(new int[2] { 1, -1 }, whereCanMatch.MatchOffsets[1]); Assert.AreEqual(new int[2] { 0, 0 }, whereCanMatch.MatchOffsets[2]); Assert.AreEqual(new int[2] { 1, 0 }, whereCanMatch.MatchOffsets[3]); whereCanMatch = matchLineModel.wheresCanMatch[2]; Assert.AreEqual(4, whereCanMatch.MatchOffsets.Count); Assert.AreEqual(new int[2] { -1, 0 }, whereCanMatch.MatchOffsets[0]); Assert.AreEqual(new int[2] { 0, 0 }, whereCanMatch.MatchOffsets[1]); Assert.AreEqual(new int[2] { -1, 1 }, whereCanMatch.MatchOffsets[2]); Assert.AreEqual(new int[2] { 0, 1 }, whereCanMatch.MatchOffsets[3]); whereCanMatch = matchLineModel.wheresCanMatch[3]; Assert.AreEqual(4, whereCanMatch.MatchOffsets.Count); Assert.AreEqual(new int[2] { 0, 0 }, whereCanMatch.MatchOffsets[0]); Assert.AreEqual(new int[2] { 1, 0 }, whereCanMatch.MatchOffsets[1]); Assert.AreEqual(new int[2] { 0, 1 }, whereCanMatch.MatchOffsets[2]); Assert.AreEqual(new int[2] { 1, 1 }, whereCanMatch.MatchOffsets[3]); }