/// <summary> /// Testing generation. Not used anymore. /// </summary> private void Update() { if (firstClick) { return; } if (Input.GetKeyDown(KeyCode.F1)) { for (int x = 0; x < currentRes.width; x++) { for (int y = 0; y < currentRes.height; y++) { Tile tile = tileMap[x, y]; if (tile.isBomb) { tile.Reveal("B"); //is bomb } else //no bomb { tile.Reveal(bombCount[x, y]); } } } } }
void FFuncover(int x, int y, bool[,] visited) { // is x and y within bounds of the grid if (x >= 0 && y >= 0 && x < width && y < height) { // have these cooridnates ben visited? if (visited[x, y]) { return; } // reveal tile in that x an y coodinate Tile tile = tiles[x, y]; int adjacentMines = GetAdjacentMineCount(tile); tile.Reveal(adjacentMines); // if there were no adjacent mines around that tile if (adjacentMines == 0) { // this tile has been visited visited[x, y] = true; FFuncover(x - 1, y, visited); FFuncover(x + 1, y, visited); FFuncover(x, y - 1, visited); FFuncover(x, y + 1, visited); } } }
void SelectATile() { //Generate ray from capera with mouse position Ray mouseRay = Camera.main.ScreenPointToRay(Input.mousePosition); //perform raycast RaycastHit2D hit = Physics2D.Raycast(mouseRay.origin, mouseRay.direction); //if mouse hits something if (hit.collider != null) { //try to get a tile component from what we clicked on Tile hitTile = hit.collider.GetComponent <Tile>(); //check if what was clicked on is a tile if (hitTile != null) { // count of all mines around the hit tile int adjacentMines = GetAdjacentMineCount(hitTile); //reveal what that tile was hitTile.Reveal(adjacentMines); } } }
void FFuncover(int x, int y, bool[,] visited) // Flood Fill algortihm { // Is x and y within bounds of the grid? if (x >= 0 && y >= 0 && x < width && y < height) { // Have these coordinates been visited? if (visited[x, y]) { return; } // Reveal tile in that x and y coordinate Tile tile = tiles[x, y]; int adjacentMines = GetAdjacentMineCount(tile); tile.Reveal(adjacentMines); // If there were no adjacent mines around that tile if (adjacentMines == 0) { // This tile has been visited visited[x, y] = true; // Visit all other tiles around this tile FFuncover(x - 1, y, visited); FFuncover(x + 1, y, visited); FFuncover(x, y - 1, visited); FFuncover(x, y + 1, visited); } } }
void SelectATile() { // Generate a ray from the camera using the mouse position Ray mouseRay = Camera.main.ScreenPointToRay(Input.mousePosition); // Perform a 2D Raycast using the above ray RaycastHit2D hit = Physics2D.Raycast(mouseRay.origin, mouseRay.direction); // If the mouse hits something (literally: 'if the hit collider isn't detecting nothing') if (hit.collider != null) { // Try getting a Tile component from the object we hit Tile hitTile = hit.collider.GetComponent <Tile>(); // Check if the object we hit is a Tile (literally: 'if hitTile doesn't return nothing') if (hitTile != null) { //Get a count of mines around the hit tile int adjacentMines = GetAdjacentMineCount(hitTile); // Reveal what that hit tile is hitTile.Reveal(adjacentMines); } } }
//Uncovers a selected tile void SelectTile(Tile selected) { int adjacentMines = GetAdjacentMineCount(selected); selected.Reveal(adjacentMines); //Is the selected tile a mine? if (selected.isMine) { UncoverMines(); } else if (adjacentMines == 0) { int x = selected.x; int y = selected.y; FFuncover(x, y, new bool[width, height]); } if (NoMoreEmptyTiles()) { UncoverMines(1); } }
void SelectTile(Tile selected) { int adjacentMines = GetAdjacentMineCount(selected); selected.Reveal(adjacentMines); if (selected.isMine) { UncoverMines(); } else if (adjacentMines == 0) { int x = selected.x; int y = selected.y; FFuncover(x, y, new bool[width, height]); } if (NoMoreEmptyTiles()) { UncoverMines(1); playAgain.enabled = true; } }
void FFuncover(int x, int y, bool[,] visited) { if (x >= 0 && y >= 0 && x < width && y < height) { if (visited[x, y]) { return; } Tile tile = tiles[x, y]; int adjacentMines = GetAdjacentMineCount(tile); tile.Reveal(adjacentMines); if (adjacentMines == 0) { visited[x, y] = true; FFuncover(x - 1, y, visited); FFuncover(x + 1, y, visited); FFuncover(x, y - 1, visited); FFuncover(x, y + 1, visited); } } }
void SelectTile(Tile selected) { int adjacentMines = GetAdjacentMineCount(selected); selected.Reveal(adjacentMines); //is the tile a mine if (selected.isMine) { //uncover all mines with loss state 0 UncoverMines(); //you lose dummy } //otherwise are there no mines around this tile? else if (adjacentMines == 0) { int x = selected.x; int y = selected.y; // the use flood fill to uncover adjacent mines FFuncover(x, y, new bool[width, height]); } //are there no more empty tiles in the game? if (NoMoreEmptyTiles()) { //uncover all the mines with win state 1 UncoverMines(1); //You win, cool } }
void FFuncover(int x, int y, bool[,] Visited) { //is x and y within bounds of the grid if (x >= 0 && y >= 0 && x < width && y < height) { //have these coords been visited if (Visited[x, y]) { //reveal that tile in that x & y coord return; } Tile tile = tiles[x, y]; int adjacentMines = GetAdjacentMineCount(tile); tile.Reveal(adjacentMines); // if there are no adjacent mines around that tile if (adjacentMines == 0) { //this tile has been visited Visited[x, y] = true; //visit all other tiles around this one FFuncover(x - 1, y, Visited); FFuncover(x + 1, y, Visited); FFuncover(x, y - 1, Visited); FFuncover(x, y + 1, Visited); } } }
// uncovers a selected tile void SelectTile(Tile selected) { int adjacentMines = GetAdjacentMineCount(selected); selected.Reveal(adjacentMines); // is the selected tiule a mine? if (selected.isMine) { // uncover all mines UncoverMines(); } // otherwise are there no mines around this tile? else if (adjacentMines == 0) { int x = selected.x; int y = selected.y; // then use flood fill to uncover all adjacent mines FFuncover(x, y, new bool[width, height]); } // are there no more empty tiles in the game at this point? if (NoMoreEmptyTiles()) { // uncover all mines, with the win state 1 UncoverMines(1); // win } }
// Uncovers a selected tile void SelectTile(Tile selected) { int adjacentMines = GetAdjacentMineCount(selected); selected.Reveal(adjacentMines); // Is the selected tile a mine? if (selected.isMine) { // Uncover all mines - with default loss state '0' UncoverMines(); // Lose } // Otherwise, are there no mines around this tile? else if (adjacentMines == 0) { int x = selected.x; int y = selected.y; // Then use flood fill to uncover all adjacent mines FFuncover(x, y, new bool[width, height]); } // Are there no more empty tiles in the game at this point? if (NoMoreEmptyTiles()) { // Uncover all mines - with the win state '1' UncoverMines(1); // Win } }
void selectTile() { mouseRay = Camera.main.ScreenPointToRay(Input.mousePosition); hit = Physics2D.Raycast(mouseRay.origin, mouseRay.direction); if (hit.collider != null) { hitTile = hit.collider.GetComponent <Tile>(); } if (hitTile != null) { adjcentMine = GetAdjcentMineCount(hitTile); hitTile.Reveal(adjcentMine); } }
void SelectATile() { Ray mouseRay = Camera.main.ScreenPointToRay(Input.mousePosition); RaycastHit2D hit = Physics2D.Raycast(mouseRay.origin, mouseRay.direction); Tile hitTile = hit.collider.GetComponent <Tile>(); if (hit.collider != null) { int adjacentMines = GetAdjacentMineCount(hitTile); hitTile.Reveal(adjacentMines); } }
void UncoverMines(int mineState = 0) { for (int x = 0; x < width; x++) { for (int y = 0; y < height; y++) { Tile tile = tiles[x, y]; if (tile.isMine) { int adjacentMines = GetAdjacentMinecount(tile); tile.Reveal(adjacentMines, mineState); } } } }
public void UncoverMines(int mineState) { for (int x = 0; x < width; x++) { for (int y = 0; y < height; y++) { Tile currentTile = tiles[x, y]; if (currentTile.isMine) { int adjacentMines = GetAdjacentMineCountAt(currentTile); currentTile.Reveal(adjacentMines, mineState); } } } }
void SelectATile() { Ray mouseRay = Camera.main.ScreenPointToRay(Input.mousePosition); // Generate a ray from the camera with mouse position RaycastHit2D hit = Physics2D.Raycast(mouseRay.origin, mouseRay.direction); // Perform raycast if (hit.collider != null) // If the mouse hit something { Tile hitTile = hit.collider.GetComponent <Tile>(); // Try getting a tile component from the thing we hit if (hitTile != null) // Check if the thing it hit was a tile { int adjacentMines = GetAdjacentMineCount(hitTile); // Get a count of mines around the hit tile hitTile.Reveal(adjacentMines); // Reveal what the hit tile is } } }
void UncoverMines(int mineState = 0) { // Loop through 2D array for (int x = 0; x < width; x++) { for (int y = 0; y < height; y++) { Tile tile = tiles[x, y]; // check if tile is a mine if (tile.isMine) { int adjacentMines = GetAdjacentMineCount(tile); tile.Reveal(adjacentMines, mineState); } } } }
public void SelectTile(Tile selectedTile) { int adjacentMines = GetAdjacentMineCountAt(selectedTile); selectedTile.Reveal(adjacentMines); if (selectedTile.isMine) { UncoverMines(0); } else if (adjacentMines == 0) { int x = selectedTile.x; int y = selectedTile.y; FFuncover(x, y, new bool[width, height]); } if (NoMoreEmptyTiles()) { UncoverMines(1); } }
void SelectATile() { //Generate a ray from the camera with the mouse position Ray mouseRay = Camera.main.ScreenPointToRay(Input.mousePosition); //Perform Raycast RaycastHit2D hit = Physics2D.Raycast(mouseRay.origin, mouseRay.direction); //If the mouse hit something if (hit.collider != null) { //try getting a tile componemt for the next thing that we hit Tile hitTile = hit.collider.GetComponent <Tile>(); //check if the thing that it hit was a tile if (hitTile != null) { //Gt a count of all the mines around the hit tile int adjacentMines = GetAdjacentMineCount(hitTile); //reveal what that hit tile is hitTile.Reveal(adjacentMines); } } }