/// <summary> /// Tells the Form which picture to use for the Preview Pictures /// </summary> private void LoadPreviewPictures() { List <TypeOfBlock> tmp = RandomBlock.LookAtTheNextThreePieces(); LoadFirstPreviewPicture?.Invoke(tmp[0]); LoadSecondPreviewPicture?.Invoke(tmp[1]); LoadThirdPreviewPicture?.Invoke(tmp[2]); }
/// <summary> /// Adding random blocks /// </summary> static void AddRandomBlocks(Engine engine, int startCol, int endCol, int startRow, int endRow) { for (int j = startRow + 1; j < endRow; j++) { for (int i = startCol; i < endCol; i++) { engine.AddObject(RandomBlock.GenerateRandomBlock(new MatrixCoords(j, i))); } } }
/// <summary> /// Try set block to Maze /// </summary> /// <param name="maze"></param> /// <param name="i"></param> /// <param name="j"></param> /// <param name="randomBlock"></param> /// <returns>false if non succesfull</returns> private bool TrySetBlock(GameObject[,] maze, int i, int j, RandomBlock randomBlock) { foreach (var wall in randomBlock.Walls) { if (maze[i + wall.Row, j + wall.Cell] != null) { return(false); } } foreach (var wall in randomBlock.Walls) { maze[i + wall.Row, j + wall.Cell] = wall; } foreach (var wall in randomBlock.Walls) { wall.Row += i; wall.Cell += j; } return(true); }
/// <summary> /// This is the Games Timer Tick /// </summary> /// <param name="sender"></param> /// <param name="e"></param> private void TimeClock_Tick(object sender, EventArgs e) { //Start of Game if (_grid.BlockThatsFalling == null) { _grid.CreateFallingBlock(RandomBlock.PullABlock()); LoadPreviewPictures(); } else { if (_grid.BlockThatsFalling.IsItFalling) { _grid.MoveFallingBlock(); } else { _grid.CreateFallingBlock(RandomBlock.PullABlock()); LoadPreviewPictures(); } } }
public MazeService(int height, int width) { Height = height; Width = width; GameObject[,] _maze = new GameObject[height, width]; int tetrisHeight = height; int tetrisWidth = width / 2; GameObject[,] _halfMaze = new GameObject[tetrisHeight, tetrisWidth]; bool canInstallYet = true; int countFals = 0; while (countFals < GameCore.EnumsAndConstant.GameConstants.MaxCountUnsuccessfulInstall) { countFals++; RandomBlock randomBlock = new RandomBlock(); for (int i = 1; i < tetrisHeight; i++) { for (int j = 0; j < tetrisWidth; j++) { if ((_halfMaze[i, j] == null) & (tetrisWidth - j > randomBlock.Width) & (tetrisHeight - i > randomBlock.Height)) { canInstallYet = TrySetBlock(_halfMaze, i, j, randomBlock); if (canInstallYet) { countFals--; SetPath(_halfMaze); i = tetrisHeight; //return from double cycle break; //return from double cycle } } } } } SetBorder(_halfMaze); MirrorReflect(_halfMaze, _maze); FullMaze(_maze); Walls = GetWalls(_maze); Paths = GetPaths(_maze); }