//Contains all of the methods and steps that occur when an empty tile is clicked private void TileOnClick(RaycastHit2D hit) { //Gets the tile value data from the tile that's been clicked EmptyTile emptyTile = hit.transform.GetComponent <EmptyTile>(); Vector2Int tileValue = emptyTile.TileValue; //try to add to board array - if error, then end the current match. try { BoardState.AddPosition(tileValue, (int)GameManager.CurrentPlayer); } catch (Exception e) { Debug.LogError(e); GameManager.instance.GameError(); } //Record the move to game data GameDataRecorder.instance.AddPlayerMove(tileValue); //Call the tiles spawn function emptyTile.SpawnTile(); //Goes back to Game Manager which uses BoardState to check if the game is over and then calls the corresponding win/draw animation GameManager.instance.CheckBoardPositions(tileValue); }
//adds a position in the board array and spawns a tile in the corresponding empty tile. Switches player at the end. private void AddTestPosition(int row, int col) { if (BoardState.BoardPositions[row, col] != 0) { StopAllCoroutines(); GameDataRecorder.instance.AddPlayerMove(new Vector2Int(-2, -2)); GameDataRecorder.instance.RecordGameFinish(4); GameManager.instance.DebugWindow("ERROR: \n Space is already occupied by another Tile. Exiting Test"); return; } BoardState.AddPosition(new Vector2Int(row, col), (int)GameManager.CurrentPlayer); GameDataRecorder.instance.AddPlayerMove(new Vector2Int(row, col)); try { BoardState.EmptyTileArray[row, col].SpawnTile(); } catch (System.Exception e) { StopAllCoroutines(); Debug.LogError(e); GameDataRecorder.instance.AddPlayerMove(new Vector2Int(-2, -2)); GameDataRecorder.instance.RecordGameFinish(4); GameManager.instance.DebugWindow("ERROR: \n Unable to Spawn Tile. Exiting Test"); return; } }