void Awake() { if (instance == null) { instance = this; } else if (instance != this) { Destroy(gameObject); } classroom = new GameObject[4, 4]; classroom[0, 0] = GameObject.FindGameObjectWithTag("Enemy"); classroom [classroom.GetUpperBound(0), classroom.GetUpperBound(1)] = GameObject.FindGameObjectWithTag("Player"); int index = 0; GameObject[] others = GameObject.FindGameObjectsWithTag("Student"); for (int i = 0; i < classroom.GetLength(0); i++) { for (int j = 0; j < classroom.GetLength(1); j++) { if ((i == 0 && j == 0) || (i == classroom.GetUpperBound(0) && j == classroom.GetUpperBound(1))) { continue; } classroom[i, j] = others[index]; index++; } } }
void GenerateBlocks() { string leftTeam = ""; string bottomTeam = ""; for (int j = 0; j <= blockPositions.GetUpperBound(1); j++) { Vector3 xPos = new Vector3(-screenSpace.x + BlockPrefab.GetComponent <RectTransform>().rect.width / 2, -screenSpace.y + .03f * j + BlockPrefab.GetComponent <RectTransform>().rect.width *(.5f + j), 0); for (int i = 0; i <= blockPositions.GetUpperBound(0); i++) { if (i > 0) { leftTeam = blockPositions[i - 1, j].GetComponent <BlockScript>().team;// ?? ""; } if (j > 0) { bottomTeam = blockPositions[i, j - 1].GetComponent <BlockScript>().team;// ?? ""; } blockPositions[i, j] = (GameObject)Instantiate(BlockPrefab); TeamRandomizer(blockPositions[i, j], leftTeam, bottomTeam); blockPositions[i, j].transform.position = xPos; xPos += new Vector3(BlockPrefab.GetComponent <RectTransform>().rect.width + .03f, 0, 0); } } }
public void MoveUp(GameObject[,] brickArray) { // This takes the entire BrickArray and goes column by column moving every block that is in the side up to the top of its column. // First int brickArrayWidth = brickArray.GetUpperBound(0) + 1; int brickArrayHeight = brickArray.GetUpperBound(1) + 1; int newX = 0; int newY = brickArrayHeight - 1; for (int x = 0; x < brickArrayWidth; x++) { for (int y = brickArrayHeight - 1; y >= 0; y--) { if (brickArray[x, y] == null) { } // Need to add in a check to see which side the brick is on else if (brickArray[x, y] != null) { Debug.Log(brickArray[x, y].ToString()); brickArray[x, y].GetComponent <BrickComponent>().Location = new Vector2((float)newX, (float)newY); newY--; } } newY = brickArrayHeight - 1; newX++; } moveProcessor.UpdateBrickArray(); }
// onPaint is called automatically (if form requires an update) but is forced by the Refresh call // onPaint is responsible for all the drawing on the Graphics private void onPaint(object sender, PaintEventArgs e) { for (int intRow = 0; intRow <= arrBricks.GetUpperBound(0); intRow++) { for (int intColumn = 0; intColumn <= arrBricks.GetUpperBound(1); intColumn++) { if (arrBricks[intRow, intColumn].GetBlnIsVisible() == true) { e.Graphics.FillRectangle(arrBricks[intRow, intColumn].GetDrawingBrushColour(), arrBricks[intRow, intColumn].GetRecPosition()); } } } e.Graphics.FillRectangle(ball.GetDrawingBrushColour(), ball.GetRecPosition()); e.Graphics.FillRectangle(paddle.GetDrawingBrushColour(), paddle.GetRecPosition()); }
private void WinCheck() { int bound0 = crates.GetUpperBound(0); int bound1 = crates.GetUpperBound(1); // ... Loop over bounds. for (int i = 0; i <= bound0; i++) { for (int j = 0; j <= bound1; j++) { if ((crates[i, j] != null) == (targets[i, j] != null)) { } else { Debug.Log("Loose"); return; } } } if (currentLevel < levels.Count - 1) { Destroy(player); for (int i = 0; i <= bound0; i++) { for (int j = 0; j <= bound1; j++) { if ((crates[i, j] != null)) { Destroy(crates[i, j]); } if ((targets[i, j] != null)) { Destroy(targets[i, j]); } } } LoadLevel(++currentLevel); } else { Application.Quit(); } text.text = "0"; steps = 0; Debug.Log("Win"); }
/// <summary> /// set Path around block /// </summary> /// <param name="maze"></param> private void SetPath(GameObject[,] maze) { int rows = maze.GetUpperBound(0) + 1; int columns = maze.Length / rows; for (int i = 0; i < rows - 1; i++) { for (int j = 0; j < columns - 1; j++) { if (maze[i, j] is Wall) { if (maze[i, j + 1] == null) { maze[i, j + 1] = new Path(i, j + 1); } if (maze[i + 1, j] == null) { maze[i + 1, j] = new Path(i + 1, j); } if (maze[i + 1, j + 1] == null) { maze[i + 1, j + 1] = new Path(i + 1, j + 1); } if ((j > 1) && (maze[i + 1, j - 1] == null)) { maze[i + 1, j - 1] = new Path(i + 1, j); } } } } }
//Made it so now this returns either a valid tile when given valid coordinates or null when not. public GameObject getTileAt(int xCoord, int zCoord) { if ((xCoord > tileList.GetLowerBound(0) && xCoord < tileList.GetUpperBound(0)) && (zCoord > tileList.GetLowerBound(1) && zCoord < tileList.GetUpperBound(1))) { return(tileList [xCoord, zCoord]); } return(null); }
// Use this for initialization void Start() { //instantiate all neutral here for (int i = 0; i < classroom.GetLength(0); i++) { for (int j = 0; j < classroom.GetLength(1); j++) { classroom[i, j].tag = "Student"; Nodes n = classroom[i, j].GetComponent <Nodes>(); Personality p = classroom[i, j].GetComponent <Personality>(); string randFirst = firstNames[(int)Random.Range(0, Mathf.Round(firstNames.Count))]; firstNames.Remove(randFirst); string randLast = lastNames[(int)Random.Range(0, Mathf.Round(lastNames.Count))]; lastNames.Remove(randLast); p.fullName = randFirst + " " + randLast; p.posts.Add(posts[(int)Random.Range(0, Mathf.Round(posts.Count))]); p.posts.Add(posts[(int)Random.Range(0, Mathf.Round(posts.Count))]); p.posts.Add(posts[(int)Random.Range(0, Mathf.Round(posts.Count))]); p.posts.Add(posts[(int)Random.Range(0, Mathf.Round(posts.Count))]); Actions randAction = (Actions)Random.Range(2, 11); n.GetComponent <Nodes> ().location(i, j); n.GetComponent <Nodes> ().nodeAction(randAction); n.GetComponent <Nodes> ().cost = 5; //same thing for pictures } } //instantiate player nodes classroom [0, 0].tag = "Enemy"; enemy = classroom [0, 0]; enemy.GetComponent <Nodes> ().nodeAction((Actions)((int)Actions.hang + 1)); enemy.GetComponent <Nodes> ().enemy = true; //details classroom [classroom.GetUpperBound(0), classroom.GetUpperBound(1)].tag = "Player"; player = classroom [classroom.GetUpperBound(0), classroom.GetUpperBound(1)]; player.GetComponent <Nodes> ().nodeAction((Actions)((int)Actions.hang + 1)); player.GetComponent <Nodes> ().set(); SetDefaultScores(); SetUpNewTurn(); }
public static Vector2Int GetNearestVerticalCollision( this IGridManager gridManager, Vector2Int coordinate, GameObject[,] blocks) { var sizeX = blocks.GetUpperBound(0) + 1; var sizeY = blocks.GetUpperBound(1) + 1; var grid = gridManager.Grid; for (var x = 0; x < sizeX; x++) { for (var y = sizeY - 1; y >= 0; y--) { //for (var gridY = ) } } return(Vector2Int.down); }
public void LoadMap() { InitializeGameMap(); for (int row = 0; row <= _gameMap.GetUpperBound(0); row++) { for (int coll = 0; coll <= _gameMap.GetUpperBound(1); coll++) { LoadElement(row, coll); } } }
// Use this for initialization void Start() { //we need to set up every gem that there is in the gem lock list. Setup_Gem_Lock_List(); //test for enemy gui. //Enemy_List.Add(new Enemy_Template("Test1", 1, 2, 3, 4, 5, 6, 7, 8, "Test2", Test_Sprite)); //Enemy_List.Add(new Enemy_Template("Test4", 11, 22, 33, 44, 55, 66, 77, 88, "Test5", Test_Sprite)); //test for allies/towers. //Tower_List.Add(new Tower_Template("Tower1", 1, 2, 3, 4, 5, Test_Sprite)); //Tower_List.Add(new Tower_Template("Tower2", 12, 22, 32, 42, 52, Test_Sprite)); //Debug.Log("Start field called"); //This will be called once to create the field initially. All_Field_Spots = new GameObject[i_field_width, i_field_height]; //go through each of the field spots and give it the game object and then update it. for (int i = 0; i <= All_Field_Spots.GetUpperBound(0); i++) { for (int j = 0; j <= All_Field_Spots.GetUpperBound(1); j++) { //Create/initilze a spot for this spot. GameObject New_Game_Field_Spot = Instantiate(Empty_Field_Spot); New_Game_Field_Spot.transform.parent = The_Field_Test.transform; //now we add the spot to the spot on the all field spots. All_Field_Spots[i, j] = New_Game_Field_Spot; //SpriteRenderer New_Path_Renderer = New_Game_Field_Spot.GetComponent<SpriteRenderer>(); //Sprite Temp_Sprite = Resources.Load("Temp_Sprite", typeof(Sprite)) as Sprite; //New_Path_Renderer.sprite = Temp_Sprite; //now we tell that spot to move it's gameobject to the correct location on said grid. //we use 1.28 because the sprite is 256 pixles, but devided by half so 128. so 1.28 is how far apart they are. Vector2 New_Vect = new Vector2(i * 1.28f, j * -1.28f); New_Game_Field_Spot.transform.localPosition = New_Vect; } } }
/// <summary> /// Установка стен и дверей в комнату. /// </summary> /// <param name="i"> Место на карте (горизонталь). </param> /// <param name="j"> Место на карте (вертикаль). </param> private void AddWallsAndDoorsToRoom(int i, int j) { if (Map[i, j] != null) { if (i == 0 || Map[i - 1, j] == null) //Стена слева { PlaceWall(i, j, 'L'); } else //Дверь слева { PlaceDoor(i, j, 'L'); } if (j == 0 || Map[i, j - 1] == null) //Стена сверху { PlaceWall(i, j, 'T'); } else //Дверь сверху { PlaceDoor(i, j, 'T'); } if (i == Map.GetUpperBound(0) || Map[i + 1, j] == null) //Стена справа { PlaceWall(i, j, 'R'); } else //Дверь справа { PlaceDoor(i, j, 'R'); } if (j == Map.GetUpperBound(1) || Map[i, j + 1] == null) //Стена снизу { PlaceWall(i, j, 'B'); } else //Дверь снизу { PlaceDoor(i, j, 'B'); } } }
/// <summary> /// Shuffle this Grid's CableTiles. /// </summary> /// <param name="values"></param> protected virtual void ShuffleGrid(GameObject[,] values) { int numOfRows = values.GetUpperBound(0) + 1; int numOfColumns = values.GetUpperBound(1) + 1; int numOfTiles = numOfRows * numOfColumns; for (int i = 0; i < numOfTiles - 1; i++) { // Pick a random tile between i and the end of the array. int j = UnityEngine.Random.Range(i, numOfTiles); // Convert to row/column indexes. int row_i = i / numOfColumns; int col_i = i % numOfColumns; int row_j = j / numOfColumns; int col_j = j % numOfColumns; // Swap tiles i and j. GameObject temp = values[row_i, col_i]; //temp = tile1 values[row_i, col_i] = values[row_j, col_j]; //tile1 = tile2 values[row_j, col_j] = temp; //tile2 = temp(tile1) } }
/// <summary> /// Full all empty maze tails /// </summary> /// <param name="maze"></param> private void FullMaze(GameObject[,] maze) { int rows = maze.GetUpperBound(0) + 1; int columns = maze.Length / rows; for (int i = 0; i < rows; i++) { for (int j = 0; j < columns; j++) { if (maze[i, j] == null) { maze[i, j] = new Path(i, j); } } } }/// <summary>
// Do Empty Tile Move Down private void DoEmptyDown(ref GameObject[,] cells) { Vector3 position = gameObject.transform.position; Vector3 size = gameObject.GetComponent <BoxCollider>().bounds.size; //replace the empty tiles with the ones above for (int x = 0; x <= cells.GetUpperBound(0); x++) { for (int y = 0; y <= cells.GetUpperBound(1); y++) { var thisCell = cells[x, y]; if (thisCell.name == "Empty(Clone)") { for (int y2 = y; y2 <= cells.GetUpperBound(1); y2++) { if (cells[x, y2].name != "Empty(Clone)") { cells[x, y] = cells[x, y2]; cells[x, y2] = thisCell; break; } } } } } //Instantiate new tiles to replace the ones destroyed for (int x = 0; x <= cells.GetUpperBound(0); x++) { for (int y = 0; y <= cells.GetUpperBound(1); y++) { if (cells[x, y].name == "Empty(Clone)") { Destroy(cells[x, y]); GameObject gb = null; gb = GameObject.Instantiate(_listOfGems[Random.Range(0, _listOfGems.Length)] as GameObject) as GameObject; gb.transform.position = new Vector3((position.x - size.x / 2 + 0.035f) + x * 0.041f, (position.y - size.y / 2 + 0.045f) + (cells.GetUpperBound(1) + 1) * 0.0452f, position.z - 0.02f); cells[x, y] = gb; } } } for (int x = 0; x <= cells.GetUpperBound(0); x++) { for (int y = 0; y <= cells.GetUpperBound(1); y++) { TweenParms parms = new TweenParms().Prop("localPosition", new Vector3((position.x - size.x / 2 + 0.035f) + x * 0.041f, (position.y - size.y / 2 + 0.045f) + y * 0.0452f, position.z - 0.02f)).Ease(EaseType.EaseOutQuart); HOTween.To(cells[x, y].transform, .4f, parms); } } }
float[,] CombineMaps(float[,] map1, float[,] map2) { for (int z = 0; z <= gameObjectMap.GetUpperBound(0); z++) { for (int x = 0; x <= gameObjectMap.GetUpperBound(1); x++) { map1[z, x] = Mathf.Clamp01(map1[z, x] + map2[z, x]); } } return(map1); }
/// <summary> /// Return all walls on maze /// </summary> /// <param name="maze"></param> /// <returns></returns> private IEnumerable <Wall> GetWalls(GameObject[,] maze) { List <Wall> listWall = new List <Wall>(); int rows = maze.GetUpperBound(0) + 1; int columns = maze.Length / rows; for (int i = 0; i < rows; i++) { for (int j = 0; j < columns; j++) { if (maze[i, j] is Wall wall) { listWall.Add(wall); } } } return(listWall); }
/// <summary> /// Return All Paths on maze /// </summary> /// <param name="maze"></param> /// <returns></returns> private IEnumerable <Path> GetPaths(GameObject[,] maze) { List <Path> listPath = new List <Path>(); int rows = maze.GetUpperBound(0) + 1; int columns = maze.Length / rows; for (int i = 0; i < rows; i++) { for (int j = 0; j < columns; j++) { if (maze[i, j] is Path path) { listPath.Add(path); } } } return(listPath); }
}/// <summary> /// Symmetrical reflection of the labyrinth /// </summary> /// <param name="halfMaze"></param> /// <param name="maze"></param> private void MirrorReflect(GameObject[,] halfMaze, GameObject[,] maze) { int rows = halfMaze.GetUpperBound(0) + 1; int columns = halfMaze.Length / rows; for (int i = 0; i < rows; i++) { for (int j = 0; j < columns; j++) { if (halfMaze[i, j] is Wall) { maze[i, columns - j - 1] = new Wall(i, columns - j - 1); maze[i, columns + j] = halfMaze[i, j]; maze[i, columns + j].Row = i; maze[i, columns + j].Cell = columns + j; } } } }
// Do Empty Tile Move Down private void DoEmptyDown(ref GameObject[,] cells) { // Replace the empty objects with the ones above for (int x = 0; x <= cells.GetUpperBound(0); x++) { for (int y = 0; y <= cells.GetUpperBound(1); y++) { var thisCell = cells[x, y]; if (thisCell.name == "Empty(Clone)") { for (int y2 = y; y2 <= cells.GetUpperBound(1); y2++) { if (cells[x, y2].name != "Empty(Clone)") { cells[x, y] = cells[x, y2]; cells[x, y2] = thisCell; break; } } } } } //Instantiate new gems to replace the ones destroyed for (int x = 0; x <= cells.GetUpperBound(0); x++) { for (int y = 0; y <= cells.GetUpperBound(1); y++) { if (cells[x, y].name == "Empty(Clone)") { Destroy(cells[x, y]); cells[x, y] = GameObject.Instantiate(listOfGems[Random.Range(0, listOfGems.Length)] as GameObject, new Vector3(x, cells.GetUpperBound(1) + 2, 0), transform.rotation) as GameObject; } } } for (int x = 0; x <= cells.GetUpperBound(0); x++) { for (int y = 0; y <= cells.GetUpperBound(1); y++) { TweenParms parms = new TweenParms().Prop("position", new Vector3(x, y, -1)).Ease(EaseType.EaseOutQuart); HOTween.To(cells[x, y].transform, .4f, parms); } } }
private void DoEmptyDown(ref GameObject[,] cells) { for (int x = 0; x <= cells.GetUpperBound(0); x++) { for (int y = 0; y <= cells.GetUpperBound(1); y++) { var thisCell = cells [x, y]; if (thisCell.name == "empty(Clone)") { for (int y2 = y; y2 <= cells.GetUpperBound(1); y2++) { if (cells [x, y2].name != "empty(Clone)") { cells [x, y] = cells [x, y2]; cells [x, y2] = thisCell; break; } } } } } for (int x = 0; x <= cells.GetUpperBound(0); x++) { for (int y = 0; y <= cells.GetUpperBound(1); y++) { if (cells [x, y].name == "empty(Clone)") { Destroy(cells [x, y]); cells [x, y] = GameObject.Instantiate(_listOfShapes [Random.Range(0, _listOfShapes.Length)] as GameObject, new Vector3(x, y, 0), transform.rotation) as GameObject; } } } for (int x = 0; x <= cells.GetUpperBound(0); x++) { for (int y = 0; y <= cells.GetUpperBound(1); y++) { cells [x, y].transform.position = new Vector3(x, y, 0); } } }
/// <summary> /// set maze border /// </summary> /// <param name="maze"></param> private void SetBorder(GameObject[,] maze) { int rows = maze.GetUpperBound(0) + 1; int columns = maze.Length / rows; for (int i = 0; i < columns; i++) { maze[0, i] = new Wall(0, i); maze[rows - 1, i] = new Wall(rows - 1, i); if (columns - i > 2) { maze[1, i] = new Path(1, i); maze[rows - 2, i] = new Path(rows - 2, i); } } for (int i = 1; i < rows - 1; i++) { maze[i, columns - 1] = new Wall(i, columns - 1); maze[i, columns - 2] = new Path(i, columns - 2); } }
public void InitializeGridObjectsPositions(GameObject[,] _grid_objects) { int arraySize = _grid_objects.GetUpperBound(0) + 1; for (int i = 0; i < arraySize; i++) { for (int j = 0; j < arraySize; j++) { if (i % 2 == 0) //if its column index is even, it's either an intersection or a segment { hOffset = ((((i / 2) + 0.5f) * GridFactory.Instance.intersectionWidth) + ((i / 2) * GridFactory.Instance.segmentWidth)); if (j % 2 == 0) //if its row index is even, it's an intersection { vOffset = ((((j / 2) + 0.5f) * GridFactory.Instance.intersectionWidth) + (Mathf.Round(j / 2) * GridFactory.Instance.segmentWidth)) - (GridFactory.Instance.intersectionWidth / 2); } else // else it's a segment { vOffset = ((((j / 2) + 0.5f) * GridFactory.Instance.intersectionWidth) + (Mathf.Round(j / 2)) * GridFactory.Instance.segmentWidth) + (GridFactory.Instance.segmentWidth / 2); } } else { //else it's either a segment or a zone hOffset = ((((i / 2) + 0.5f) * GridFactory.Instance.intersectionWidth) + (((i / 2) + 0.5f) * GridFactory.Instance.segmentWidth)) + (GridFactory.Instance.intersectionWidth / 2); if (j % 2 == 0) //if its row index is even, it's a segment { vOffset = ((((j / 2) + 0.5f) * GridFactory.Instance.intersectionWidth) + (Mathf.Round(j / 2)) * GridFactory.Instance.segmentWidth) - (GridFactory.Instance.intersectionWidth / 2); _grid_objects[i, j].transform.rotation = new Quaternion(); } else //else it is a zone { vOffset = ((((j / 2) + 0.5f) * GridFactory.Instance.intersectionWidth) + (Mathf.Round(j / 2)) * GridFactory.Instance.segmentWidth) + (GridFactory.Instance.zoneWidth / 2); } } _grid_objects[i, j].transform.position = new Vector3(hOffset, 0, vOffset); //set GameObject position } } }
// Find Match-3 Tile private ArrayList FindMatch(GameObject[,] cells) { // Create an arraylist to store the matching tiles ArrayList stack = new ArrayList(); // Check the vertical gems for (var x = 0; x <= cells.GetUpperBound(0); x++) { for (var y = 0; y <= cells.GetUpperBound(1); y++) { var thiscell = cells[x, y]; // If it's empty, continue if (thiscell.name == "Empty(Clone)") { continue; } int matchCount = 0; int y2 = cells.GetUpperBound(1); int y1; // Getting the number of gems of the same type for (y1 = y + 1; y1 <= y2; y1++) { if (cells[x, y1].name == "Empty(Clone)" || thiscell.name != cells[x, y1].name) { break; } matchCount++; } // If we found more than 2 gems close, we add them in the array of matching gems if (matchCount >= 2) { y1 = Mathf.Min(cells.GetUpperBound(1), y1 - 1); for (var y3 = y; y3 <= y1; y3++) { if (!stack.Contains(cells[x, y3])) { stack.Add(cells[x, y3]); } } } } } // Check the horizontal gems for (var y = 0; y < cells.GetUpperBound(1) + 1; y++) { for (var x = 0; x < cells.GetUpperBound(0) + 1; x++) { var thiscell = cells[x, y]; // If it's empty, continue if (thiscell.name == "Empty(Clone)") { continue; } int matchCount = 0; int x2 = cells.GetUpperBound(0); int x1; // Getting the number of gems of the same type for (x1 = x + 1; x1 <= x2; x1++) { if (cells[x1, y].name == "Empty(Clone)" || thiscell.name != cells[x1, y].name) { break; } matchCount++; } // If we found more than 2 gems close, we add them in the array of matching gems if (matchCount >= 2) { x1 = Mathf.Min(cells.GetUpperBound(0), x1 - 1); for (var x3 = x; x3 <= x1; x3++) { if (!stack.Contains(cells[x3, y])) { stack.Add(cells[x3, y]); } } } } } return(stack); }
private void InitialiseGameScreenForm() { tmrGame.Tick += new EventHandler(onTick); this.KeyDown += new KeyEventHandler(onKeyDown); this.MouseMove += new MouseEventHandler(onMouseMove); this.MouseClick += new MouseEventHandler(onMouseClick); this.Paint += new PaintEventHandler(onPaint); DoubleBuffered = true; KeyPreview = true; this.MinimizeBox = false; this.MaximizeBox = false; this.BackColor = Color.SkyBlue; this.FormBorderStyle = FormBorderStyle.FixedDialog; this.Size = new Size(640, 482); this.Text = "Breakout Game"; int intBrickRows = 5; int intBrickColumns = 5; int intBrickWidth = 80; int intBrickHeight = 20; int paddleWidth = 80; int paddleHeight = 15; int paddleX = 300; int paddleY = 434; int ballWidth = 20; int ballHeight = 20; int ballX = paddleX + paddleHeight / 2 - (ballHeight / 2); int ballY = paddleY - ballWidth; float defaultSpeed = 20; float defaultXVel = (float)Math.Cos(defaultSpeed) * defaultSpeed; float defaultYVel = (float)Math.Cos(defaultSpeed) * defaultSpeed; paddle = new MoveableGameObject(paddleX, paddleY, paddleWidth, paddleHeight, true, defaultSpeed, 0, 0, false, Brushes.Pink); ball = new MoveableGameObject(ballX, ballY, ballWidth, ballHeight, true, defaultSpeed, defaultXVel, defaultYVel, true, Brushes.Yellow); arrBricks = new GameObject[intBrickRows, intBrickColumns]; tmrGame.Interval = 20; tmrGame.Start(); int intXOffset = (intBrickWidth / 2) + 1; int intYOffset = 100; for (int intRow = 0; intRow <= arrBricks.GetUpperBound(0); intRow++) { for (int intColumn = 0; intColumn <= arrBricks.GetUpperBound(1); intColumn++) { arrBricks[intRow, intColumn] = new GameObject(intXOffset, intYOffset, intBrickWidth, intBrickHeight, true, Brushes.Red); intXOffset += intBrickWidth + 10; } intYOffset += intBrickHeight + 10; intXOffset = (intBrickWidth / 2) + 1; } }
// Randomize a 2D array. private IEnumerator randomize() { //don't count these moves for the user countMoves = false; //yield return new WaitForSeconds(2.0f); // hide a puzzle tile (one is always missing to allow the puzzle movement). TileDisplayArray[Random.Range(0, Width), Random.Range(0, Height)].GetComponent <ST_PuzzleTileHyper>().Active = false; // Get the dimensions. int num_rows = TileDisplayArray.GetUpperBound(0) + 1; int num_cols = TileDisplayArray.GetUpperBound(1) + 1; int num_cells = num_rows * num_cols; for (int x = 0; x < num_cells * 2; x++) { // Randomize the array. System.Random rand = new System.Random(); for (int i = 0; i < num_cells - 1; i++) { // Pick a random cell between i and the end of the array. int j = rand.Next(i, num_cells); // Convert to row/column indexes. int row_i = i / num_cols; int col_i = i % num_cols; int row_j = j / num_cols; int col_j = j % num_cols; // Swap cells i and j. ST_PuzzleTileHyper thisTile1 = TileDisplayArray[row_i, col_i].GetComponent <ST_PuzzleTileHyper>(); ST_PuzzleTileHyper thisTile2 = TileDisplayArray[row_j, col_j].GetComponent <ST_PuzzleTileHyper>(); //Vector2 tempArrayLocation1 = thisTile1.ArrayLocation; //Vector2 tempGridLocation1 = thisTile1.GridLocation; //Vector3 localPosition = thisTile1.transform.localPosition; thisTile1.ExecuteAdditionalMove(40f); thisTile2.ExecuteAdditionalMove(40f); yield return(new WaitForSeconds(0.0001f)); //thisTile1.transform.localPosition = thisTile2.transform.localPosition; //thisTile2.transform.localPosition = localPosition; //thisTile1.ArrayLocation = thisTile2.ArrayLocation; //thisTile1.GridLocation = thisTile2.GridLocation; //thisTile2.ArrayLocation = tempArrayLocation1; //thisTile2.GridLocation = tempGridLocation1; //GameObject tempTile1 = TileDisplayArray[row_i, col_i]; //TileDisplayArray[row_i, col_i] = TileDisplayArray[row_j, col_j]; //TileDisplayArray[row_j, col_j] = tempTile1; //thisTile1.LaunchPositionCoroutine(thisTile2.transform.localPosition); //thisTile2.LaunchPositionCoroutine(localPosition); } } Complete = false; moveCounter = 0; countMoves = true; MovesCounterDisplay.text = "0"; // continually check for the correct answer. StartCoroutine(CheckForComplete()); gameStarted = true; startTime = Time.time; yield return(null); }
//Instantiate the star objects void DoShapeEffect() { foreach (GameObject row in _currentParticleEffets) { Destroy(row); } for (int i = 0; i <= 2; i++) { _currentParticleEffets.Add(GameObject.Instantiate(_particleEffect, new Vector3(Random.Range(0, _arrayOfShapes.GetUpperBound(0) + 1), Random.Range(0, _arrayOfShapes.GetUpperBound(1) + 1), -1), new Quaternion(0, 0, Random.Range(0, 1000f), 100)) as GameObject); } }
private ArrayList FindMatch(GameObject[,] cells) { ArrayList stack = new ArrayList(); for (var x = 0; x <= cells.GetUpperBound(0); x++) { for (var y = 0; y <= cells.GetUpperBound(1); y++) { var thiscell = cells [x, y]; if (thiscell.name == "empty(Clone)") { continue; } int matchCount = 0; int y2 = cells.GetUpperBound(1); int y1; for (y1 = y + 1; y1 <= y2; y1++) { if (cells [x, y1].name == "empty(Clone)" || (thiscell.name != cells [x, y1].name)) { break; } matchCount++; } if (matchCount >= 2) { y1 = Mathf.Min(cells.GetUpperBound(1), y1 - 1); for (var y3 = y; y3 <= y1; y3++) { if (!stack.Contains(cells [x, y3])) { stack.Add(cells [x, y3]); } } } } } for (var y = 0; y <= cells.GetUpperBound(1); y++) { for (var x = 0; x <= cells.GetUpperBound(0); x++) { var thiscell = cells [x, y]; if (thiscell.name == "empty(Clone)") { continue; } int matchCount = 0; int x2 = cells.GetUpperBound(0); int x1; for (x1 = x + 1; x1 <= x2; x1++) { if (cells [x1, y].name == "empty(Clone)" || (thiscell.name != cells [x1, y].name)) { break; } matchCount++; } if (matchCount >= 2) { x1 = Mathf.Min(cells.GetUpperBound(0), x1 - 1); for (var x3 = x; x3 <= x1; x3++) { if (!stack.Contains(cells [x3, y])) { stack.Add(cells [x3, y]); } } } } } return(stack); }
public bool CheckForMatches() { List <GameObject> matches = new List <GameObject>(); List <GameObject> tempMatches = new List <GameObject>(); // For all hexagons in grid array for (int i = 0; i <= gridArrray.GetUpperBound(0) - 1; i++) { for (int j = 0; j <= gridArrray.GetUpperBound(1); j++) { // If i,j = i+1,j continue. If not, there will not be any match if (gridArrray[i, j].GetComponent <Hex>().color == gridArrray[i + 1, j].GetComponent <Hex>().color) { tempMatches.Add(gridArrray[i, j]); tempMatches.Add(gridArrray[i + 1, j]); int sign = i % 2 == 0 ? -1 : 1; // Because, the even rows are located at lower heights than odd ones // Desired hexagon should be at the (odd) top or the (even) bottom of the hexagon at right. if (j + sign >= 0 && j + sign <= gridArrray.GetUpperBound(1)) { if (gridArrray[i, j].GetComponent <Hex>().color == gridArrray[i + 1, j + sign].GetComponent <Hex>().color) { tempMatches.Add(gridArrray[i + 1, j + sign]); } } // Desired hexagon should be at the (odd) bottom or the (even) top of the hexagon at left. if (j - sign >= 0 && j - sign <= gridArrray.GetUpperBound(1)) { if ((gridArrray[i, j].GetComponent <Hex>().color == gridArrray[i, j - sign].GetComponent <Hex>().color)) { tempMatches.Add(gridArrray[i, j - sign]); } } // If there are 3 or more matches, add them to the list if (tempMatches.Count > 2) { foreach (GameObject obj in tempMatches) { if (!matches.Contains(obj)) { matches.Add(obj); } } } tempMatches = new List <GameObject>(); } } } // If no match, return false if (matches.Count == 0) { return(false); } // Else, blow all hexagons matched else { foreach (GameObject obj in matches) { obj.GetComponent <Hex>().Blow(); } // And call the function StartCoroutine("WaitAndSlide"); return(true); } }
// Write a general move command that uses only the directions public void Move(GameObject[,] brickArray, MoveDirection moveDir) { // Settings to figure out which way it is going int brickArrayWidth = brickArray.GetUpperBound(0) + 1; int brickArrayHeight = brickArray.GetUpperBound(1) + 1; int newX; int newY; int xModifier = 0; int yModifier = 0; int startX = 0; int startY = 0; bool movingUpAndDown = false; newX = startX; newY = startY; if (moveDir == MoveDirection.Up) { // This should all be done by column newY = brickArrayHeight - 1; newX = 0; // Set up here which sides will be affected for (int x = 0; x < brickArrayWidth; x++) { for (int y = brickArrayHeight - 1; y >= 0; y--) { if (brickArray[x, y] == null || brickArray[x, y] == gameModel.CurrentActiveBrick) { } else if (brickArray[x, y] != null) { BrickComponent brickComponet = brickArray[x, y].GetComponent <BrickComponent>(); if (brickComponet.Side == Sides.Top || brickComponet.Side == Sides.Bottom) { } else if (brickComponet.Side == Sides.Left || brickComponet.Side == Sides.Right) { gameModel.MoveBrick(brickArray[x, y], moveDir, false); } newY -= 1; } } newY = brickArrayHeight - 1; newX += 1; } } else if (moveDir == MoveDirection.Down) { newY = 0; newX = 0; // Set up here which sides will be affected for (int x = 0; x < brickArrayWidth; x++) { for (int y = 0; y < brickArrayHeight; y++) { if (brickArray[x, y] == null || brickArray[x, y] == gameModel.CurrentActiveBrick) { } else if (brickArray[x, y] != null) { BrickComponent brickComponet = brickArray[x, y].GetComponent <BrickComponent>(); if (brickComponet.Side == Sides.Top || brickComponet.Side == Sides.Bottom) { } else if (brickComponet.Side == Sides.Left || brickComponet.Side == Sides.Right) { gameModel.MoveBrick(brickArray[x, y], moveDir, false); } newY += 1; } } newY = 0; newX += 1; } } else if (moveDir == MoveDirection.Left) { newX = 0; newY = brickArrayHeight - 1; // Set up here which sides will be affected for (int y = brickArrayHeight - 1; y >= 0; y--) { for (int x = 0; x < brickArrayWidth; x++) { if (brickArray[x, y] == null || brickArray[x, y] == gameModel.CurrentActiveBrick) { } else if (brickArray[x, y] != null) { BrickComponent brickComponet = brickArray[x, y].GetComponent <BrickComponent>(); if (brickComponet.Side == Sides.Left || brickComponet.Side == Sides.Right) { } else if (brickComponet.Side == Sides.Top || brickComponet.Side == Sides.Bottom) { gameModel.MoveBrick(brickArray[x, y], moveDir, false); } newX += 1; } } newX = 0; newY -= 1; } } else if (moveDir == MoveDirection.Right) { newX = brickArrayWidth - 1; newY = brickArrayHeight - 1; // Set up here which sides will be affected for (int y = brickArrayHeight - 1; y >= 0; y--) { for (int x = brickArrayWidth - 1; x >= 0; x--) { if (brickArray[x, y] == null || brickArray[x, y] == gameModel.CurrentActiveBrick) { } else if (brickArray[x, y] != null) { BrickComponent brickComponet = brickArray[x, y].GetComponent <BrickComponent>(); if (brickComponet.Side == Sides.Left || brickComponet.Side == Sides.Right) { } else if (brickComponet.Side == Sides.Top || brickComponet.Side == Sides.Bottom) { gameModel.MoveBrick(brickArray[x, y], moveDir, false); } newX -= 1; } } newX = brickArrayWidth - 1; newY -= 1; } } moveProcessor.UpdateBrickArray(); }
// Find Match-3 Tile private ArrayList FindMatch(GameObject[,] cells) {//creating an arraylist to store the matching tiles ArrayList stack = new ArrayList(); //Checking the vertical tiles for (var x = 0; x <= cells.GetUpperBound(0); x++) { for (var y = 0; y <= cells.GetUpperBound(1); y++) { var thiscell = cells[x, y]; //If it's an empty tile continue //if (thiscell.name == "Empty(Clone)") continue; if (null == thiscell.GetComponent <PoolObject>()) { continue; } int matchCount = 0; int y2 = cells.GetUpperBound(1); int y1; //Getting the number of tiles of the same kind for (y1 = y + 1; y1 <= y2; y1++) { //if (cells[x, y1].name == "Empty(Clone)" || thiscell.name != cells[x, y1].name) break; if (cells[x, y1].GetComponent <PoolObject>() == null || thiscell.name != cells[x, y1].name) { break; } matchCount++; } //If we found more than 2 tiles close we add them in the array of matching tiles if (matchCount >= 2) { y1 = Mathf.Min(cells.GetUpperBound(1), y1 - 1); for (var y3 = y; y3 <= y1; y3++) { if (!stack.Contains(cells[x, y3])) { stack.Add(cells[x, y3]); } } } } } //Checking the horizontal tiles , in the following loops we will use the same concept as the previous ones for (var y = 0; y < cells.GetUpperBound(1) + 1; y++) { for (var x = 0; x < cells.GetUpperBound(0) + 1; x++) { var thiscell = cells[x, y]; if (thiscell.name == "Empty(Clone)") { continue; } int matchCount = 0; int x2 = cells.GetUpperBound(0); int x1; for (x1 = x + 1; x1 <= x2; x1++) { if (cells[x1, y].name == "Empty(Clone)" || thiscell.name != cells[x1, y].name) { break; } matchCount++; } if (matchCount >= 2) { x1 = Mathf.Min(cells.GetUpperBound(0), x1 - 1); for (var x3 = x; x3 <= x1; x3++) { if (!stack.Contains(cells[x3, y])) { stack.Add(cells[x3, y]); } } } } } return(stack); }