public void Handlekey(ConsoleKey key) { if (key == ConsoleKey.LeftArrow) { direction = d.Left; } else if (key == ConsoleKey.RightArrow) { direction = d.Right; } else if (key == ConsoleKey.DownArrow) { direction = d.FastDown; } else if (key == ConsoleKey.Spacebar) { direction = d.Rotation; } else if (key == ConsoleKey.Escape) { direction = d.Stop; } else if (key == ConsoleKey.P) { direction = d.Pause; } }
public bool CanMoveBorders(List <Point> figure, d dir) { foreach (Point item in figure) { if (dir == d.Left) { if (item.x - 1 <= 0) { return(false); } } else if (dir == d.Right) { if (item.x + 1 >= Width) { return(false); } } else { if (item.y + 1 >= Length) { return(false); } } } return(true); } //Check: can move figure in selected d (there is borders or no)
public bool CanMoveFreeCell(List <Point> figure, d dir = d.SlowDown) //Check: can move figure in selected direction (free or not cells) { List <Point> CheckList = new List <Point>(); Point point; for (int j = 0; j < figure.Count; j++) // Select d for moving and create new point { bool trim = true; switch (dir) { case d.Left: point = new Point(figure[j].x - 1, figure[j].y); break; case d.Right: point = new Point(figure[j].x + 1, figure[j].y); break; default: point = new Point(figure[j].x, figure[j].y + 1); break; } for (int k = 0; k < figure.Count; k++) // Checking point do not belong any points of figure { if (point == figure[k]) { trim = false; break; } } if (trim) { CheckList.Add(point); } // Creating new list from new point which forming when a figure try to move } foreach (Point p in CheckList) // Checking new list. If all cells is free and figure can move return true { foreach (GridUnit item in PosiblePlace) { if ((item == p) && (item.PlaceBusy == true)) { return(false); } } } return(true); }
} //Check: can move figure in selected d (there is borders or no) public List <Point> MoveSide(List <Point> figure, d dir) { List <Point> figureNew = new List <Point>(); if (dir == d.Left) { for (int i = 0; i < figure.Count; i++) { figureNew.Add(new Point(figure[i].x - 1, figure[i].y)); } } else if (dir == d.Right) { for (int i = 0; i < figure.Count; i++) { figureNew.Add(new Point(figure[i].x + 1, figure[i].y)); } } return(figureNew); }
private void ChangePosition(Tetris.Direction direction) { for (int i = 0; i < 4; i++) { moving[coordinates[0, i], coordinates[1, i]] = 0; } Update(false); if (direction == Tetris.Direction.Rotate) { Tetris.Rotate(ref current); } else { for (int i = 0; i < 4; i++) { switch (direction) { case Tetris.Direction.Down: coordinates[1, i] += 1; break; case Tetris.Direction.Left: coordinates[0, i] -= 1; break; case Tetris.Direction.Right: coordinates[0, i] += 1; break; } } for (int i = 0; i < 4; i++) { moving[coordinates[0, i], coordinates[1, i]] = Convert.ToInt32(figure); } switch (direction) { case Tetris.Direction.Down: y++; break; case Tetris.Direction.Left: x--;; break; case Tetris.Direction.Right: x++; break; } Update(true); } }