public Figure(int[,] grid) { _step = 1; IsRun = true; _grid = grid; _state = CreateState(); _cells = _state.State.ToArray(); }
public void Update(GameEngine engine) { if (Input.IsKeyDown(Keys.LEFT)) { if (CanMove(Keys.LEFT)) { for (int i = 0; i < _cells.Length; i++) { _cells[i].X -= FieldSize.width; } } } else if (Input.IsKeyDown(Keys.RIGHT)) { if (CanMove(Keys.RIGHT)) { for (int i = 0; i < _cells.Length; i++) { _cells[i].X += FieldSize.width; } } } else if (Input.IsKeyDown(Keys.DOWN)) { if (CanMove(Keys.DOWN)) { for (int i = 0; i < _cells.Length; i++) { _cells[i].Y += FieldSize.height; } } } if (Input.IsKeyDown(Keys.SPACE)) { if (CanMove(Keys.SPACE)) { _state = _state.TurnFigure(); _cells = _state.State.ToArray(); } } if (_step % _speed == 0) { if (CanMove(Keys.DOWN)) { for (int i = 0; i < _cells.Length; i++) { _cells[i].Y += FieldSize.height; } } else { IsRun = false; for (int i = 0; i < _cells.Length; i++) { int gridX = (_cells[i].X - FieldSize.xMin) / FieldSize.width; int gridY = (_cells[i].Y - FieldSize.yMin) / FieldSize.height; _grid[gridX, gridY] = 1; } } } _step++; }