void UpdateMatrixGrid() { string ourNiceGrid = ""; //Debug.Log ("Updating " + transform.gameObject.name); for (int y = 0; y < MatrixGrid.column; ++y) { ourNiceGrid += "\n"; for (int x = 0; x < MatrixGrid.row; ++x) { if (MatrixGrid.grid[x, y]) { ourNiceGrid += MatrixGrid.grid[x, y].position; } else { ourNiceGrid += 0; }; //if (MatrixGrid.grid [x, y] != null) { // if (MatrixGrid.grid [x, y].parent = transform) { /// MatrixGrid.grid [x, y] = null; // } //} } } //print (ourNiceGrid); foreach (Transform child in transform) { Vector2 v = MatrixGrid.RoundVector(child.position); MatrixGrid.grid [(int)v.x, (int)v.y] = child; } }
public static void GetSubMatrix(MatrixGrid grid, Point cell) { var matrixPair = matricesView.Where(e => e.Value == grid).ToList()[0]; var matrix = matrixPair.Key.GetSubMatrix(cell); CreateMatrix(matrix); }
bool IsValidGridPosition() { //Debug.Log(transform.childCount); string childInfo = ""; foreach (Transform child in transform) { Vector2 v = MatrixGrid.RoundVector(child.position); childInfo += gameObject.name + "::" + child.name + " = " + v + "\n"; if (!MatrixGrid.IsInsideBorder(v)) { print("INVALID, Stopping... FInal Child Info from: " + gameObject.name); print("\n" + childInfo); return(false); } //if (MatrixGrid.grid [(int)v.x, (int)v.y] != null //&& MatrixGrid.grid [(int)v.x, (int)v.y].parent != child // ) { // Debug.Log("Second thing failed it"); // Debug.Log (MatrixGrid.grid[(int)v.x, (int)v.y]); // Debug.Log (MatrixGrid.grid[(int)v.x, (int)v.y].parent); // Debug.Log (transform); //return false; //} } print(childInfo); return(true); }
void Awake() { MatrixGrid.InitializeGrid(); oldRandomBlock = 7; isBlockPlaced = true; boolArray = ""; }
public static void Insert(MatrixGrid oldGrid, MatrixGrid newGrid) { var matrixPair = matricesView.Where(e => e.Value == oldGrid).ToList()[0]; var matrix = matricesView.Where(e => e.Value == newGrid).ToList()[0].Key; var side = oldGrid.side; var parent = oldGrid.Parent; matricesView.Remove(matrixPair); matrices.Remove(matrixPair.Key); //DeleteMatrix(oldGrid); var newMatrix = (Matrix <T>)matrix.Clone(); var grid = CreateMatrixGrid(newMatrix); grid.GridSizeChanged = oldGrid.GridSizeChanged; matrices.Add(newMatrix); matricesView.Add(new KeyValuePair <Matrix <T>, MatrixGrid>(newMatrix, grid)); grid.Parent = parent; grid.side = side; grid.GridSize = grid.GridSize; oldGrid.Dispose(); var oldMatrix = matrixPair.Key; Matrix <T> .Copy(newMatrix, oldMatrix); }
void UpdateMatrixGrid() { for (int y = 0; y < MatrixGrid.column; ++y) { for (int x = 0; x < MatrixGrid.row; ++x) { if (MatrixGrid.grid[x, y] != null) { if (MatrixGrid.grid[x, y] == transform) { MatrixGrid.grid[x, y] = null; } } } } foreach (Transform child in transform) { Vector2 v = MatrixGrid.RoundVector(child.position); MatrixGrid.grid[(int)v.x, (int)v.y] = child; } FindObjectOfType <Score>().IncreaseScore(1); /*for (int y = MatrixGrid.column-1; y >= 0 ; --y) * { * string s = ""; * for (int x = 0; x < MatrixGrid.row; ++x) * { * if (MatrixGrid.grid[x, y] != null) * s += " " + 0; * else s += " 8"; * * } * Debug.Log(s); * }*/ }
void Update() { if (!gameover && MatrixGrid.IsInsideBorder(MatrixGrid.RoundVector(transform.position))) { if (Input.GetKeyDown(KeyCode.LeftArrow) || Input.GetKeyDown(KeyCode.A)) { transform.position += new Vector3(-1, 0, 0); if (IsValidGridPosition()) { } else { transform.position += new Vector3(1, 0, 0); } } else if (Input.GetKeyDown(KeyCode.KeypadPlus) || Input.GetKeyDown(KeyCode.Equals)) { FindObjectOfType <Speed>().SpeedUp(); Debug.Log("SpeedUp"); } else if (Input.GetKeyDown(KeyCode.KeypadMinus) || Input.GetKeyDown(KeyCode.Minus)) { FindObjectOfType <Speed>().SpeedDown(); } else if (Input.GetKeyDown(KeyCode.RightArrow) || Input.GetKeyDown(KeyCode.D)) { transform.position += new Vector3(1, 0, 0); if (IsValidGridPosition()) { } else { transform.position += new Vector3(-1, 0, 0); } } else if (Input.GetKeyDown(KeyCode.Space)) { transform.Rotate(new Vector3(0, 0, -90)); if (IsValidGridPosition()) { } else { transform.Rotate(new Vector3(0, 0, 90)); } } else if (Input.GetKeyDown(KeyCode.DownArrow) || Input.GetKeyDown(KeyCode.S) || Time.time - lastFall >= tick) { GameObjectDown(); lastFall = Time.time; } } else if (Input.GetKeyDown(KeyCode.R) && gameover) { Restart(); } }
public static void PrintToFile(MatrixGrid grid) { var matrix = matricesView.Where(e => e.Value == grid).ToList()[0].Key; using (var SFD = new SaveFileDialog()) { SFD.FileName = grid.MatrixName; SFD.Filter = "Text files(*.txt)|*.txt|All files(*.*)|*.*"; DialogResult result = SFD.ShowDialog(); if (result == DialogResult.Cancel) { return; } string filename = SFD.FileName; string text = ""; for (int i = 0; i < matrix.rowsCount; i++) { for (int j = 0; j < matrix.columnsCount; j++) { text += matrix[i, j].ToString() + ((j == matrix.columnsCount - 1)? "":" "); } text += '\n'; } File.WriteAllText(filename, text); } }
void GameObjectDown() { transform.position += new Vector3(0, -1, 0); if (IsValidGridPosition()) { countofsteps++; } else { if (countofsteps > 0) { transform.position += new Vector3(0, 1, 0); UpdateMatrixGrid(); MatrixGrid.DeleteWholeRows(); FindObjectOfType <Spawner>().SpawnRandom(SpawnerNext.index); enabled = false; } else { transform.position += new Vector3(0, 1, 0); gameover = true; FindObjectOfType <GameOver>().ShowGameOver(); //Debug.Log("game over"); } } }
void moveObject() { if (Input.GetKeyDown(KeyCode.LeftArrow)) { transform.position += new Vector3(-1, 0, 0); if (IsValidGridPosition()) { UpdateMatrixGrid(); } else { transform.position += new Vector3(1, 0, 0); } } else if (Input.GetKeyDown(KeyCode.RightArrow)) { transform.position += new Vector3(1, 0, 0); if (IsValidGridPosition()) { UpdateMatrixGrid(); } else { transform.position += new Vector3(-1, 0, 0); } } else if (Input.GetKeyDown(KeyCode.UpArrow)) { transform.Rotate(new Vector3(0, 0, -90)); if (IsValidGridPosition()) { UpdateMatrixGrid(); } else { transform.Rotate(new Vector3(0, 0, 90)); } } else if (Input.GetKeyDown(KeyCode.DownArrow) || Time.time - lastFall >= 1) { transform.position += new Vector3(0, -1, 0); if (IsValidGridPosition()) { UpdateMatrixGrid(); } else { transform.position += new Vector3(0, 1, 0); MatrixGrid.DeleteWholeRows(); FindObjectOfType <Spawn>().spawnRandom(); enabled = false; } lastFall = Time.time; } }
private void Form1_Load(object sender, EventArgs e) { Input = new MatrixGrid(InputMatrix); Input.AddRow(sender, e); AddRowBtn.Click += Input.AddRow; RemoveRowBtn.Click += Input.DeleteRow; Output = new MatrixGrid(OutputMatrix); }
public DragDropCommand(MatrixGrid grid) { this.grid = grid; grid.dragDropExecuted += (o, e) => { newGrid = (MatrixGrid)o; }; }
void Update() { dynamicScore.text = "Your Current Score : " + MatrixGrid.returnPlayerScore().ToString(); if (TetrisObject.IsGameOver()) { Application.LoadLevel("End screen"); } }
public static ControllerData <T> DeleteMatrix(MatrixGrid mg) { var matrixPair = matricesView.Where(e => e.Value == mg).ToList()[0]; matricesView.Remove(matrixPair); matrixPair.Key.Dispose(); matrices.Remove(matrixPair.Key); return(new ControllerData <T>(GetData(matrixPair.Key), matrixPair.Key)); }
void CheckRowClears() { MatrixGrid.rowClears = 0; for (int i = 0; i < 20; i++) { if (MatrixGrid.IsRowClear(i)) { MatrixGrid.rowClears++; } } }
void RotateBlock() { transform.Rotate(Vector3.forward, curRot); foreach (Transform child in transform) { if (MatrixGrid.CheckPosFilled(Vector3Int.RoundToInt(child.position))) { transform.Rotate(Vector3.forward, -curRot); return; } } }
public static Matrix <T> GetMatrix(MatrixGrid grid) { var matrixPairs = matricesView.Where(e => e.Value == grid).ToList(); if (matrixPairs.Count > 0) { return(matrixPairs[0].Key); } else { return(null); } }
public static void DoDragDrop(MatrixGrid grid) { if (grid.side != WorkingPanelSide.List) { var matrixPair = matricesView.Where(e => e.Value == grid).ToList()[0]; OperationController <T> .DoDragDrop(grid, matrixPair.Key); return; } panel.AllowDrop = false; grid.DoDragDrop(grid, DragDropEffects.Copy); }
public static MatrixGrid ExecuteDragDrop(MatrixGrid gridDragDrop) { var matrixPair = matricesView.Where(e => e.Value == gridDragDrop).ToList()[0]; var matrix = (Matrix <T>)matrixPair.Key.Clone(); var newGrid = CreateMatrix(matrix); var matrixPairList = matricesView.Where(e => e.Value.side == gridDragDrop.side).ToList(); if (gridDragDrop.dragDropExecuted != null) { gridDragDrop.dragDropExecuted.Invoke(newGrid, null); } newGrid.lines = matrix.lines; newGrid.MatrixName = gridDragDrop.MatrixName; return(newGrid); }
public void Undo() { if (isMatrixController) { if (matrix != null) { if (grid.side == WorkingPanelSide.List) { MatrixController <T> .CreateMatrix(matrix); } else { //костыль (: //зато работает! var side = grid.side; grid = MatrixController <T> .CreateMatrix(matrix); OperationController <T> .ExecuteDragDrop(side, grid, opView); MatrixController <T> .DeleteMatrix(matrix); } } } else { //тоже костыль :( opView = OperationController <T> .CreateEmptyOperation(); var left = operation.leftMatrix; var right = operation.rightMatrix; if (left != null) { var leftGrid = MatrixController <T> .CreateMatrix(left); OperationController <T> .ExecuteDragDrop(WorkingPanelSide.Left, leftGrid, opView); MatrixController <T> .DeleteMatrix(leftGrid); } if (right != null) { var rightGrid = MatrixController <T> .CreateMatrix(right); OperationController <T> .ExecuteDragDrop(WorkingPanelSide.Right, rightGrid, opView); MatrixController <T> .DeleteMatrix(rightGrid); } } }
bool isValidGridPosition() { foreach (Transform child in transform) { Vector2 v = MatrixGrid.RoundVector(child.position); if (!MatrixGrid.IsInsideBorder(v)) { return(false);//косание стен } if (MatrixGrid.grid[(int)v.x, (int)v.y] != null && MatrixGrid.grid[(int)v.x, (int)v.y].parent != transform) { return(false);//косание другой фигуры } } return(true); }
public void Execute() { if (type == CreationType.Matrix) { if (data.GetLength(0) != 0 || data.GetLength(1) != 0) { grid = MatrixController <T> .CreateMatrix(data); } grid.MatrixName = name; } else { opView = OperationController <T> .CreateEmptyOperation(); } }
bool IsValidGridPosition() { foreach (Transform child in transform) { Vector2 v = MatrixGrid.RoundVector(child.position); if (!MatrixGrid.IsInsideBorder(v)) { return(false); } if (MatrixGrid.grid[(int)v.x, (int)v.y] != null && MatrixGrid.grid[(int)v.x, (int)v.y] != transform) { return(false); } } return(true); }
void CheckBlockPosition() { if (delayStart + delay > Time.time) { valid = true; foreach (Transform child in transform) { if (MatrixGrid.CheckPosFilled(Vector3Int.RoundToInt(child.position))) { MatrixGrid.gameOver = true; return; } if (MatrixGrid.ReachedBottom(Vector3Int.RoundToInt(child.position))) { valid = false; } } if (valid) { SoftDrop(); } foreach (Transform child in transform) { if (MatrixGrid.ReachedBottom(Vector3Int.RoundToInt(child.position))) { Spawner.activeBlock = null; //yield return new WaitForSeconds(BlockFallTimer.timer + (14f / 60f)); foreach (Transform child2 in transform) { MatrixGrid.Lock(Vector3Int.RoundToInt(child2.position)); MatrixGrid.SetGrid(Vector3Int.RoundToInt(child2.position), child2.gameObject); } CheckRowClears(); Spawner.isBlockPlaced = true; Destroy(this); break; } } } }
bool IsValidGridPostion() { foreach (Transform child in transform) { Vector2 v = MatrixGrid.RoundVector(child.position); // if object is not inside the boders the return false - i.e. not valid if (!MatrixGrid.IsInsideBorder(v)) { return(false); } // check if block is in the grid, but not part of the group - then not valid if (MatrixGrid.grid[(int)v.x, (int)v.y] != null && MatrixGrid.grid[(int)v.x, (int)v.y].parent != transform) { return(false); } } return(true); }
public static ControllerData <T> EditMatrix(MatrixGrid mg) { var matrixPair = matricesView.Where(e => e.Value == mg).ToList()[0]; //currentEditMatrix = matrixPair.Key; EditMatrix editMatrixForm = new EditMatrix(MatrixEditMode.Edit, matrixPair.Key.rowsCount, matrixPair.Key.columnsCount, matrixPair.Key, matrixPair.Value.MatrixName, true); var dgv = editMatrixForm.dataGridView1; dgv.RowCount = matrixPair.Key.rowsCount; dgv.ColumnCount = matrixPair.Key.columnsCount; for (int i = 0; i < matrixPair.Key.rowsCount; i++) { for (int j = 0; j < matrixPair.Key.columnsCount; j++) { dgv[j, i].Value = matrixPair.Key[i, j].ToString(); } } editMatrixForm.Show(); return(new ControllerData <T>(GetData(matrixPair.Key), matrixPair.Key)); }
void UpdateMatrixGrid() { for (int y = 0; y < MatrixGrid.column; ++y) { for (int x = 0; x < MatrixGrid.row; ++x) { if (MatrixGrid.grid[x, y] != null) { if (MatrixGrid.grid[x, y].parent == transform) { MatrixGrid.grid[x, y] = null; } } } } //removing children foreach (Transform child in transform) { Vector2 v = MatrixGrid.RoundVector(child.position); MatrixGrid.grid[(int)v.x, (int)v.y] = child; } // adding new children }
void UpdateMatrixGrid() { for (int y = 0; y < MatrixGrid.column; y++) { for (int x = 0; x < MatrixGrid.row; x++) { if (MatrixGrid.grid[x, y] != null) { if (MatrixGrid.grid[x, y].parent == transform) { MatrixGrid.grid[x, y] = null; } } } } foreach (Transform child in transform) { Vector2 v = MatrixGrid.RoundVector(child.position); MatrixGrid.grid[(int)v.x, (int)v.y] = child; } }
bool isValidGridPos() { foreach (Transform child in transform) { Vector2 v = MatrixGrid.RoundVector(child.position); // Not inside Border? if (!MatrixGrid.IsInsideBorder(v)) { return(false); } // Block in grid cell (and not part of same group)? if (MatrixGrid.grid[(int)v.x, (int)v.y] != null && MatrixGrid.grid[(int)v.x, (int)v.y].parent != transform) { return(false); } } return(true); }
private void OnMouseDown() { if (isMine) { MatrixGrid.ShowAllMines(); } else { string[] index = gameObject.name.Split('-'); int x = int.Parse(index[0]); int y = int.Parse(index[1]); ShowNearMinesCount(MatrixGrid.NearMines(x, y)); MatrixGrid.InvestigateMines(x, y, new bool[GameManager.Instance.Rows, GameManager.Instance.Columns]); if (MatrixGrid.IsGameFinished()) { Debug.Log("You won"); } } }