public int CalculateMirrorY(Block[,] a) { int tempInt = offSetY; bool tempBool = false; while(true) { for (int x = 0; x < 4; x++) { for (int y = 0; y < 4; y++) { if ((array[x, y].color != Color.Black && y + tempInt == 20) || (array[x, y].color != Color.Black && a[x + offSetX, y + tempInt].color != Color.Black)) { tempBool = true; break; } } if (tempBool) break; } if (tempBool) break; tempInt++; } return tempInt - 1; }
public bool CreatedOnWrittenShape(Block[,] a) { for (int i = 0; i < 4; i++) for (int j = 0; j < 4; j++) if (array[i, j].color != Color.Black && a[i + offSetX, j + offSetY].color != Color.Black) return true; return false; }
public Level(Texture2D tex) { blank = tex; for (int x = 0; x < 10; x++) for (int y = 0; y < 20; y++) array[x, y] = new Block(blank); CreateNewShape(); }
public Shape(Texture2D tex) { for (int i = 0; i < 4; i++) for (int j = 0; j < 4; j++) array[i, j] = new Block(tex); }
public void Update(GameTime gameTime, Block[,] a) { mirrorY = CalculateMirrorY(a); timer += gameTime.ElapsedGameTime; if (timer >= TimeSpan.FromSeconds(1)) { timer = TimeSpan.Zero; if (isYObstructed) { for (int x = 0; x < 4; x++) for (int y = 0; y < 4; y++) if (array[x, y].color != Color.Black) a[x + offSetX, y + offSetY].color = array[x, y].color; writtenToArray = true; } else offSetY++; } isYObstructed = false; for (int x = 0; x < 4; x++) { for (int y = 0; y < 4; y++) { if ((array[x, y].color != Color.Black && y + offSetY == 19)) { isYObstructed = true; break; } else { if (array[x, y].color != Color.Black && a[x + offSetX, y + offSetY + 1].color != Color.Black) { isYObstructed = true; break; } } } if (isYObstructed) break; } }
public bool RotateRightIsPossible(Block[,] a) { Block[,] tempArray = new Block[4, 4]; for (int i = 0; i < 4; i++) for (int j = 0; j < 4; j++) { tempArray[3 - j, i] = array[i, j]; } for (int i = 0; i < 4; i++) for (int j = 0; j < 4; j++) if (tempArray[i, j].color != Color.Black) { if (i + offSetX < 0) return false; if (i + offSetX > 9) return false; if (a[i + offSetX, j + offSetY].color != Color.Black) return false; } return true; }
public virtual void RotateRight(Block[,] a) { if (RotateRightIsPossible(a)) { Block[,] tempArray = new Block[4, 4]; for (int i = 0; i < 4; i++) for (int j = 0; j < 4; j++) { tempArray[3 - j, i] = array[i, j]; } for (int i = 0; i < 4; i++) for (int j = 0; j < 4; j++) { array[i, j] = tempArray[i, j]; } } }
public bool RightDragClear(Block[,] a) { for (int i = 0; i < 4; i++) for (int j = 0; j < 4; j++) if (array[i, j].color != Color.Black) { if (i + offSetX > 8) return false; else { if (a[i + offSetX + 1, j + offSetY].color != Color.Black) return false; } } return true; }
public override void RotateRight(Block[,] a) { }
public override void RotateLeft(Block[,] a) { }