public void AddLetterAnswer(string letter) { GameObject letterTileStage = Instantiate(letterTile, Answer) as GameObject; LetterTile tile = letterTileStage.GetComponent <LetterTile>(); tile.letter = letter; }
public static Button[] GenerateHand(Panel pnlHand, Action <object, MouseEventArgs> mouseDown) { TileWidth = (pnlHand.Size.Width / HandSize) - (HorizontalPadding); TileHeight = (pnlHand.Size.Height) - (VerticalPadding); Size size = new Size(TileWidth, TileHeight); Point loc = new Point(0, 0); hand = new LetterTile[HandSize]; //Button Start for (int i = 0; i < HandSize; i++) { loc.Y = (size.Height - 30); hand[i] = new LetterTile() { Location = new Point(i * (size.Width + HorizontalPadding), loc.Y), Size = size, Font = new Font("Arial", 8, FontStyle.Bold), Name = "btnHand" + i.ToString(), Enabled = true, AllowDrop = true }; //Associates the same event handler with each of the buttons generated hand[i].MouseDown += new MouseEventHandler(mouseDown); // Add button to the form pnlHand.Controls.Add(hand[i]); } //One Row Complete return(hand); }
public override void OnTileHover(LetterTile tile, RaycastHit hit) { Vector3 newPos = transform.position; newPos.y = tileHoverHeight; tile.transform.position = newPos; }
void Explode(GridControl grid) { BombTickSFX.Stop(); SwapBombSFX.Play(); int cipher = Random.Range(1, 26); foreach (GameObject go in grid.grid) { GridSquare gs = go.GetComponent <GridSquare>(); if (gs && gs.tile) { LetterTile lt = gs.tile.GetComponent <LetterTile>(); if (lt) { int changedLetter = lt.letter + cipher; if (changedLetter > Game.ascii_z) { changedLetter = changedLetter - 26; } lt.ChangeLetterSprite((char)changedLetter); Instantiate(indicator, gs.tile.transform); } } } }
public override void OnTileHover(LetterTile tile, RaycastHit hit) { int position = WorldToHandPos(hit.point); ReorderTilesAround(position); PlaceTileHovering(tile, hit); }
public override void PlaceTile(LetterTile tile, RaycastHit hit) { int position = WorldToHandPos(hit.point); tile.transform.parent = transform; playerHand.Insert(Mathf.Clamp(position + 3, 0, playerHand.Count), tile); ReorderTiles(); }
public override void PlaceTile(LetterTile tile, RaycastHit hit) { Vector3 newPos = transform.position; newPos.y = transform.position.y + transform.lossyScale.y / 2; tile.transform.position = newPos; this.tile = tile; }
public void Choose_ConundrumCommand() { Assert.IsTrue(cvm.ChooseCommand.CanExecute(null)); cvm.ChooseCommand.Execute(null); Assert.IsTrue(GetConundrum().All(c => LetterTile.IsUpperLetter(c))); }
private void FillHand() { while (playerHand.Count < handSize) { LetterTile newTile = tilePile.DrawTile(); PlaceTile(newTile); newTile.OnPlaced(this); } }
private static bool IsUpperConsonant(string letter) { if (string.IsNullOrEmpty(letter)) { return(false); } return(LetterTile.IsUpperLetter(letter[0]) && !LetterTile.IsUpperVowel(letter[0])); }
private void PlaceTileHovering(LetterTile tile, RaycastHit hit) { Vector3 newPos = new Vector3(WorldToHandPos(hit.point) * tileOffsetX, tileOffsetY, 0) { y = tileHoverHeight }; tile.transform.position = transform.TransformPoint(newPos); tile.LastTileHolder = this; }
protected override void PerformMachineAction() { LetterTile tile = slot.GetComponent <GridSquare>().tile.GetComponent <LetterTile>(); char newTileChar = nextLetter(tile.letter); tile.SetLetter(newTileChar); //cost: 1 tile lifespan tile.DecLifespan(); base.PerformMachineAction(); }
public static List <LetterTile> exchangeTiles(int count, List <LetterTile> letterBag) { List <LetterTile> newTiles = new List <LetterTile>(); for (int i = 0; i < count; i++) { LetterTile tile = letterBag[rand.Next(letterBag.Count)]; newTiles.Add(tile); letterBag.Remove(tile); } return(newTiles); }
/// <summary> /// Adds the letterTile as a selected letter /// </summary> private void AddSelectedLetter(LetterTile letterTile) { letterTile.SetSelected(true); selectedLetterTiles.Add(letterTile); selectedWord += letterTile.Letter; UpdateLine(); // Call the event with the new selected word if (OnSelectedWordChanged != null) { OnSelectedWordChanged(selectedWord); } }
/// <summary> /// Makes and places the letter tiles /// </summary> private void MakeLetterTile() { var letters = LetterLevelController.Instance.Letters; foreach (var letter in letters) { GameObject n = Instantiate(this.letterTile, transform, true); var nRect = n.GetComponent <RectTransform>(); LetterTile tile = n.GetComponent <LetterTile>(); tile.LetterTileLetter = letter.Key; nRect.localScale = new Vector3(1, 1, 1); } }
public LetterTile DrawTile() { string chosenLetter = letterAmounts.Keys.ToArray()[Random.Range(0, letterAmounts.Count)]; --letterAmounts[chosenLetter]; if (letterAmounts[chosenLetter] <= 0) { letterAmounts.Remove(chosenLetter); } LetterTile tile = Instantiate(letterTilePrefab); tile.Init(chosenLetter); return(tile); }
public static int CaluclatePlacedTileScore(Button boardTile, LetterTile letterTile) { int tileValue = LetterValues.getLetterValue(letterTile.Text); string tileType = boardTile.Text; if (tileType == "" || string.Equals(tileType, "*")) { return(tileValue); } else if (string.Equals(tileType, "Double Letter Score")) { return(tileValue * 2); } else if (string.Equals(tileType, "Triple Letter Score")) { return(tileValue * 3); } return(-1); }
private void DisplayLetter(GridTile gridTile) { // If there is already a letter being displayed on this grid tile then don't instantiate a new one if (gridTile.displayed) { return; } // Get an instance of LetterTile, set the letter, then active it LetterTile letterTile = GameManager.Instance.LetterTilePool.GetObject().GetComponent <LetterTile>(); letterTile.LetterText.text = gridTile.letter.ToString(); letterTile.gameObject.SetActive(true); // Set a reference to them so when we reset the board we can remove them gridTile.letterTileObject = letterTile.gameObject; gridTile.displayed = true; // Create a container GameObject that will be the parent of the LetterTile, this way we can scale down the LetterTile and have the font scale down and still be visible GameObject letterTileContainer = new GameObject("letter_tile_container"); // Add a tile LayoutElement to the container so its sized properly in the layout group AddTileLayoutElement(letterTileContainer); // Set the letter tile containers parent to the parent of the grid tile then set the letter tiles sibling index to that of the grid tile, then de-activate the grid tile. // This will essently replaces the grid tile with the scaled down letter tile letterTileContainer.transform.SetParent(gridTile.gridTileObject.transform.parent, false); letterTileContainer.transform.SetSiblingIndex(gridTile.gridTileObject.transform.GetSiblingIndex()); gridTile.gridTileObject.gameObject.SetActive(false); // Get the scale of the letter tile so that it will be scaled down to the size of a grid tile float scale = tileSize / (letterTile.transform as RectTransform).rect.width; // Set the scale of the LetterTIle, set its localPosition to zero, then set its parent to be the letter_tile_container we created befor letterTile.transform.localScale = new Vector3(scale, scale, 1f); letterTile.transform.localPosition = Vector3.zero; letterTile.transform.SetParent(letterTileContainer.transform, false); }
public void freezeBlocks() { GameObject[] tileGOs = GameObject.FindGameObjectsWithTag("Tile"); foreach (GameObject go in tileGOs) { LetterTile letterTileComponent = go.GetComponent <LetterTile>(); go.transform.position = new Vector2(letterTileComponent.column - 2, letterTileComponent.row - 3); letterTileComponent.isSelected = false; letterTileComponent.TurnOffGlow(); foreach (GameObject go2 in tileGOs) { LetterTile letterTileComponent2 = go2.GetComponent <LetterTile>(); if (go2 != go && letterTileComponent.column == letterTileComponent2.column && letterTileComponent.row == letterTileComponent2.row) { Destroy(go2); //Debug.Log("Tile was destroyed because columns were " + letterTileComponent.column + letterTileComponent2.column //+ " and rows were " + letterTileComponent.row + letterTileComponent2.row); } } go.GetComponent <Rigidbody2D>().constraints = RigidbodyConstraints2D.FreezePositionX | RigidbodyConstraints2D.FreezePositionY | RigidbodyConstraints2D.FreezeRotation; } }
public void addTile(LetterTile tile) { int pos = tile.GetBoardPosition(); internalBoard.Insert(pos, tile); }
public override void RemoveTile(LetterTile tile) { this.tile = null; }
IEnumerator Numbers(int big, int small) { int i = 0; if (big > 4) { big = 4; } while (i < small) { int s = smallNumbers[Random.Range(0, smallNumbers.Count)]; mathSolver.numbers.SetValue(s, i); i++; GameObject letterTileStage = Instantiate(numberTile, numbersField) as GameObject; LetterTile tile = letterTileStage.GetComponent <LetterTile>(); tile.letter = s.ToString(); yield return(new WaitForSeconds(2)); } i = 0; while (i < big) { int b = bigNumbers[Random.Range(0, bigNumbers.Count - small)]; bigNumbers.Remove(b); //since only 4 big numbers can be used and can't be repeated, remove the number generated from the list. mathSolver.numbers.SetValue(b, i); i++; GameObject letterTileStage = Instantiate(numberTile, numbersField) as GameObject; LetterTile tile = letterTileStage.GetComponent <LetterTile>(); tile.letter = b.ToString(); yield return(new WaitForSeconds(2)); } i = 0; float randomTimer = 0; int randomTarget = 0; while (randomTimer < 3) { randomTarget = Random.Range(0, 999); targetText.text = randomTarget.ToString(); randomTimer += 0.1f; yield return(new WaitForSeconds(0.05f)); } mathSolver.target = randomTarget; mathSolver.StartCoroutine(mathSolver.CalculateSolutions()); Invoke("SetTimer", 3.5f); timer = 3.5f; yield return(null); }
public static bool CheckForTurnPlacement(int pos, InternalBoard ib) { LetterTile lt = (LetterTile)ib.Board[pos]; return(lt.PlacedThisTurn); }
public void Setup(GameManager.BoardState boardState) { // Reset the game tiles so they can be selected again Reset(); // Make sure the tile lists are cleared letterTiles.Clear(); selectedLetterTiles.Clear(); // Set the size of the current board currentBoardSize = boardState.wordBoardSize; // Get the maximum width and height a tile can be for this board without overflowing the container float maxTileWidth = ((letterTileContainer.transform as RectTransform).rect.width - (boardState.wordBoardSize - 1) * tileSpacing) / boardState.wordBoardSize; float maxTileHeight = ((letterTileContainer.transform as RectTransform).rect.height - (boardState.wordBoardSize - 1) * tileSpacing) / boardState.wordBoardSize; // The final tile size will be the minimum between the max width/height so that the tiles do not overflow out of the containers bounds currentTileSize = Mathf.Min(maxTileWidth, maxTileHeight); letterTileContainer.cellSize = new Vector2(currentTileSize, currentTileSize); letterTileContainer.spacing = new Vector2(tileSpacing, tileSpacing); letterTileContainer.constraint = GridLayoutGroup.Constraint.FixedColumnCount; letterTileContainer.constraintCount = boardState.wordBoardSize; // Place all the tiles on the board for (int i = 0; i < boardState.wordBoardSize; i++) { for (int j = 0; j < boardState.wordBoardSize; j++) { int tileIndex = i * boardState.wordBoardSize + j; // Create a GameObject that will go in the grid and be the parent for any LetterTile that needs to go in its place GameObject gridGameObject = new GameObject("grid_object", typeof(RectTransform)); gridGameObject.transform.SetParent(letterTileContainer.transform, false); gridGameObjects.Add(gridGameObject); switch (boardState.tileStates[tileIndex]) { case GameManager.BoardState.TileState.UsedButNotFound: LetterTile letterTile = GameManager.Instance.LetterTilePool.GetObject().GetComponent <LetterTile>(); letterTile.TileIndex = tileIndex; letterTile.Letter = boardState.tileLetters[tileIndex]; letterTile.LetterText.text = letterTile.Letter.ToString(); // Set it as a child of the gridGameObject we created before (so its in the correct position) letterTile.transform.SetParent(gridGameObject.transform, false); letterTile.transform.localPosition = Vector3.zero; letterTile.gameObject.SetActive(true); // Now we need to scale the LetterTile so its size is relative to currentTileSize. We can't just set the size of the RectTransform // because then the font on the Text component for the letter might be to big and the letter will disappear float scale = currentTileSize / (letterTile.transform as RectTransform).rect.width; letterTile.transform.localScale = new Vector3(scale, scale, 1f); letterTiles.Add(letterTile); break; default: // We add null so when we are selecting tiles we can easily determine what tiles are beside each other by checking the indexes in boardTiles. letterTiles.Add(null); break; } } } for (int i = 0; i < boardState.words.Length; i++) { currentWords.Add(boardState.words[i]); } }
/// <summary> /// Remove the chosen tile from this <see cref="TileHolder"/> /// </summary> /// <param name="tile"></param> public abstract void RemoveTile(LetterTile tile);
/// <summary> /// Insert a LetterTile into this.tileRack. This method does not catch any exceptions /// thrown by this.tileRack. /// </summary> /// <param name="drawnLetterTile">The LetterTile that is being inserted into this.tileRack.</param> public void DrawLetterTile(LetterTile drawnLetterTile) { this.tileRack.InsertLetterTile(drawnLetterTile); }
public void PlaceTile(LetterTile tile) { tile.transform.parent = transform; playerHand.Add(tile); ReorderTiles(); }
/// <summary> /// Place the chosen tile on this <see cref="TileHolder"/> /// </summary> /// <param name="tile">Tile to remove</param> /// <param name="hit">Optional hit info for placing the tile</param> public abstract void PlaceTile(LetterTile tile, RaycastHit hit);
public override void RemoveTile(LetterTile tile) { playerHand.Remove(tile); ReorderTiles(); }
/// <summary> /// Set tile to hover above this holder. /// </summary> /// <param name="tile"></param> /// <param name="hit">Optional hit info for placing the tile</param> public abstract void OnTileHover(LetterTile tile, RaycastHit hit);
private void LetterFrequencyTest(char[] letters) { const int cLoopCount = 100000; // per letter const double cAcceptableError = 0.2; // percent Dictionary <char, long> frequencies = new Dictionary <char, long>(); // initialise the dictionary contents foreach (char c in letters) { frequencies.Add(c, 0); } Func <char> GetLetter; if (LetterTile.IsUpperVowel(letters[0])) { GetLetter = () => lvm.Model.GetVowel(); } else { GetLetter = () => lvm.Model.GetConsonant(); } // choose the letters and record counts for (int index = 0; index < cLoopCount * letters.Length; ++index) { frequencies[GetLetter()] += 1; } // check that only the required letters have been picked Assert.AreEqual(letters.Length, frequencies.Count); // sum the settings frequencies to allow percentage comparisons double sum = 0; if (LetterTile.IsUpperVowel(letters[0])) { sum = UserSettings.Vowels.Sum(lt => lt.Frequency); } else { sum = UserSettings.Consonants.Sum(lt => lt.Frequency); } // compare settings and actual frequency percentages for (int index = 0; index < letters.Length; ++index) { double actualPercentage = (100.0 / (cLoopCount * letters.Length)) * frequencies[letters[index]]; double settingsPercentage = (100.0 / sum); if (LetterTile.IsUpperVowel(letters[0])) { settingsPercentage *= UserSettings.Vowels[index].Frequency; } else { settingsPercentage *= UserSettings.Consonants[index].Frequency; } // assumes that enough random choices have been made for the // frequency test to approach the required accuracy //System.Diagnostics.Debug.WriteLine($"{letters[index]}:{Math.Abs(actualPercentage - settingsPercentage)}"); Assert.IsTrue(Math.Abs(actualPercentage - settingsPercentage) <= cAcceptableError); } }