static void BlockDownCollision() { // Add blocks from current to background for (int i = 0; i < positions.GetLength(2); i++) { bg[positions[currentIndex, currentRot, i, 1] + currentY, positions[currentIndex, currentRot, i, 0] + currentX] = currentChar; } // Loop while (true) { // Check for line int lineY = Line(bg); // If a line is detected if (lineY != -1) { ClearLine(lineY); continue; } break; } // New block NewBlock(); }
private static void Show4DMatrix(int[,,,] array) { try { for (var i = 0; i < array.GetLength(0); i++) { Console.WriteLine(" ["); for (var j = 0; j < array.GetLength(1); j++) { for (var k = 0; k < array.GetLength(2); k++) { for (var l = 0; l < array.GetLength(3); l++) { Console.Write($" { array[i, j, k, l] }"); } Console.WriteLine(); } } Console.WriteLine(" ]\n"); } } catch (Exception ex) { Console.WriteLine(ex.Message); } }
public static void fourDimDisplay() { for (int i = 0; i < myArray.GetLength(0); i++) { Console.WriteLine(""); for (int j = 0; j < myArray.GetLength(1); j++) { Console.WriteLine(""); for (int k = 0; k < myArray.GetLength(2); k++) { Console.WriteLine(""); for (int l = 0; l < myArray.GetLength(3); l++) { Random rdm = new Random(); myArray[i, j, k, l] = rdm.Next(1, 11); Console.Write(myArray[i, j, k, l] + " "); } } } } }
private static void MatrixSquared(int[,,,] array) { var arrayCopy = (int[, , , ])array.Clone(); var rowCount = array.GetLength(2); var columnCount = array.GetLength(3); var copyColumnCount = arrayCopy.GetLength(3); if (rowCount == copyColumnCount) { var arrayProduct = new int[1, 1, 4, 4]; for (var i = 0; i < rowCount; i++) { for (var j = 0; j < copyColumnCount; j++) { var sum = 0; for (var k = 0; k < columnCount; k++) { var a = array[0, 0, i, k]; var b = arrayCopy[0, 0, k, j]; sum += a * b; } arrayProduct[0, 0, i, j] = sum; } } Console.WriteLine("Here is the square of the matrix above"); DisplayMatrix(arrayProduct); } else { Console.WriteLine("The matrix must have the same number of rows as columns"); } }
private static void MatrixDeterminant(int[,,,] array) { if (array.GetLength(2) != array.GetLength(3)) { Console.WriteLine("Determinant can only be calculated only for square matrices! \nEqual rows and columns"); } else { var determinant = array[0, 0, 0, 0] * (array[0, 0, 1, 1] * (array[0, 0, 2, 2] * array[0, 0, 3, 3] - array[0, 0, 2, 3] * array[0, 0, 3, 2]) - array[0, 0, 1, 2] * (array[0, 0, 2, 1] * array[0, 0, 3, 3] - array[0, 0, 2, 3] * array[0, 0, 3, 1]) + array[0, 0, 1, 3] * (array[0, 0, 2, 1] * array[0, 0, 3, 2] - array[0, 0, 2, 2] * array[0, 0, 3, 1])) // second column - array[0, 0, 0, 1] * (array[0, 0, 1, 0] * (array[0, 0, 2, 2] * array[0, 0, 3, 3] - array[0, 0, 2, 3] * array[0, 0, 3, 2]) - array[0, 0, 1, 2] * (array[0, 0, 2, 0] * array[0, 0, 3, 3] - array[0, 0, 2, 3] * array[0, 0, 3, 0]) + array[0, 0, 1, 3] * (array[0, 0, 2, 0] * array[0, 0, 3, 2] - array[0, 0, 2, 2] * array[0, 0, 3, 0])) //third column + array[0, 0, 0, 2] * (array[0, 0, 1, 0] * (array[0, 0, 2, 1] * array[0, 0, 3, 3] - array[0, 0, 2, 3] * array[0, 0, 3, 1]) - array[0, 0, 1, 1] * (array[0, 0, 2, 0] * array[0, 0, 3, 3] - array[0, 0, 2, 3] * array[0, 0, 3, 0]) + array[0, 0, 1, 3] * (array[0, 0, 2, 0] * array[0, 0, 3, 1] - array[0, 0, 2, 1] * array[0, 0, 3, 0])) //fourth column - array[0, 0, 0, 3] * (array[0, 0, 1, 0] * (array[0, 0, 2, 1] * array[0, 0, 3, 2] - array[0, 0, 2, 2] * array[0, 0, 3, 1]) - array[0, 0, 1, 1] * (array[0, 0, 2, 0] * array[0, 0, 3, 2] - array[0, 0, 2, 2] * array[0, 0, 3, 0]) + array[0, 0, 1, 2] * (array[0, 0, 2, 0] * array[0, 0, 3, 1] - array[0, 0, 2, 1] * array[0, 0, 3, 0])); Console.WriteLine($"The determinant of the matrix is {determinant}."); } }
private static void EnterMatrixEntries(int[,,,] array) { Console.WriteLine("Now start entering values for the matrix one row after the other"); for (var i = 0; i < array.GetLength(0); i++) { for (var j = 0; j < array.GetLength(1); j++) { for (var k = 0; k < array.GetLength(2); k++) { for (var l = 0; l < array.GetLength(3); l++) { try { var input = int.Parse(Console.ReadLine()); array[i, j, k, l] = input; } catch (Exception) // once user tries anything fishy, i generate random values { Console.WriteLine("You wanted to crash the program but you failed. I will generate random values"); RandomNumberGen(Matrix4D); Console.WriteLine("Now enter the next number for the matrix"); } } if (i < array.GetLength(0)) { Console.WriteLine("Now the next row"); // only print when all rows have not been filled } } } Console.WriteLine(); } }
private static int[,,,] Iterate(int[,,,] grid) { var expandedGrid = Expand(grid); var newGrid = new int[ grid.GetLength(0) + 2, grid.GetLength(1) + 2, grid.GetLength(2) + 2, grid.GetLength(3) + 2 ]; ForEach(newGrid, (i, j, k, l, v) => { var numActiveNeighbours = CountActiveNeighbours(expandedGrid, i, j, k, l); if (expandedGrid[i, j, k, l] == 0 && numActiveNeighbours == 3) { newGrid[i, j, k, l] = 1; } if (expandedGrid[i, j, k, l] == 1 && (numActiveNeighbours == 2 || numActiveNeighbours == 3)) { newGrid[i, j, k, l] = 1; } }); return(newGrid); }
public override void write(Object obj1, BOutput bout1, long version) { BOutputBin bout = (BOutputBin)bout1; BBufferBin bbuf = bout.bbuf; int[,,,] arr = (int[, , , ])obj1; // lengths int n3 = arr.GetLength(0); int n2 = arr.GetLength(1); int n1 = arr.GetLength(2); int n0 = arr.GetLength(3); bbuf.putLength(n3); bbuf.putLength(n2); bbuf.putLength(n1); bbuf.putLength(n0); // write for (int i3 = 0; i3 < n3; i3++) { for (int i2 = 0; i2 < n2; i2++) { for (int i1 = 0; i1 < n1; i1++) { for (int i0 = 0; i0 < n0; i0++) { bbuf.putInt(arr[i3, i2, i1, i0]); } } } } }
private int[,,,] matrix; //holds values of matrix itself //create r*c matrix and fill it with data passed to this constructor public Matrix(int[,,,] int_array) { matrix = int_array; row_matrix = matrix.GetLength(2); column_matrix = matrix.GetLength(3); Console.WriteLine("Contructor which sets matrix size {0}x{1} and fill it with initial data executed.", row_matrix, column_matrix); }
private static int[,,,] Expand(int[,,,] grid) { var newGrid = new int[ grid.GetLength(0) + 2, grid.GetLength(1) + 2, grid.GetLength(2) + 2, grid.GetLength(3) + 2 ]; ForEach(grid, (i, j, k, l, v) => newGrid[i + 1, j + 1, k + 1, l + 1] = v); return(newGrid); }
int[,,,] array4d = new int[5, 2, 2, 3]; //[4rd:dim 0, 3rd:dim 1,row:dim 2,column:dim 4]! public NDArray() { for (int i = 0; i < array3d.GetLength(0); i++) //3rd dimension { for (int j = 0; j < array3d.GetLength(1); j++) // Row dimension { Console.WriteLine(array3d[i, j, 0] + "\t" + array3d[i, j, 1] + "\t" + array3d[i, j, 2]); } } Console.WriteLine(array4d.GetLength(3)); // Will show 3! Console.WriteLine(array4d.GetLength(0)); // Will show 5! }
public void DrawMap(PaintEventArgs e) { int n = tilenum; for (int Y = 0; Y < map.GetLength(1); Y++) { for (int X = 0; X < map.GetLength(0); X++) { tilenum = map[X, Y, worldx, worldy]; e.Graphics.DrawImage(tile[tilenum], X * 32, Y * 32, 32, 32); } } tilenum = n; }
private static void ForEach(int[,,,] grid, Action <int, int, int, int, int> action) { for (var i = 0; i < grid.GetLength(0); i++) { for (var j = 0; j < grid.GetLength(1); j++) { for (var k = 0; k < grid.GetLength(2); k++) { for (var l = 0; l < grid.GetLength(2); l++) { action(i, j, k, l, grid[i, j, k, l]); } } } } }
private static void RandomNumberGen(int[,,,] array) { for (var i = 0; i < Matrix4D.GetLength(0); i++) { for (var j = 0; j < Matrix4D.GetLength(1); j++) { for (var k = 0; k < Matrix4D.GetLength(2); k++) { for (var l = 0; l < Matrix4D.GetLength(3); l++) { array[i, j, k, l] = Random.Next(RandomMinValue, RandomMaxValue); } } } } }
/* print binary table */ public static void printTable(int[, , ,] arr, Bitmap image) { for (int majr = 0; majr < arr.GetLength(0); majr++) { for (int minr = 0; minr < arr.GetLength(2); minr++) { for (int majc = 0; majc < arr.GetLength(1); majc++) { for (int minc = 0; minc < arr.GetLength(3); minc++) { Console.Write(arr[majr, majc, minr, minc]); } } Console.WriteLine(); } } }
private static void DisplayMatrix(int[,,,] array) { for (var i = 0; i < array.GetLength(0); i++) { for (var j = 0; j < array.GetLength(1); j++) { for (var k = 0; k < array.GetLength(2); k++) { for (var l = 0; l < array.GetLength(3); l++) { Console.Write($" {array[i, j, k, l]}\t"); } Console.WriteLine(); } } Console.WriteLine(""); } }
private static int CountActiveNeighbours(int[,,,] grid, int x, int y, int z, int w) { var numActiveNeighbours = 0; for (var i = x - 1; i < x + 2; i++) { for (var j = y - 1; j < y + 2; j++) { for (var k = z - 1; k < z + 2; k++) { for (var l = w - 1; l < w + 2; l++) { if (i < 0 || i >= grid.GetLength(0)) { continue; } if (j < 0 || j >= grid.GetLength(1)) { continue; } if (k < 0 || k >= grid.GetLength(2)) { continue; } if (l < 0 || l >= grid.GetLength(3)) { continue; } if (i == x && j == y && k == z && l == w) { continue; } numActiveNeighbours += grid[i, j, k, l]; } } } } return(numActiveNeighbours); }
void init() { int l0 = f.GetLength(0); int l1 = f.GetLength(1); int l2 = f.GetLength(2); int l3 = f.GetLength(3); for (int i = 0; i < l0; i++) { for (int j = 0; j < l1; j++) { for (int u = 0; u < l2; u++) { for (int v = 0; v < l3; v++) { f[i, j, u, v] = -1; } } } } }
public void SaveState(BinaryWriter stream) { stream.Write(clocksCount); int iLen = _tileset.GetLength(0), jLen = _tileset.GetLength(1), kLen = _tileset.GetLength(2), lLen = _tileset.GetLength(3); for (int i = 0; i < iLen; i++) { for (int j = 0; j < jLen; j++) { for (int k = 0; k < kLen; k++) { for (int l = 0; l < lLen; l++) { stream.Write(_tileset[i, j, k, l]); } } } } for (int i = 0; i < _bgPalettes.Length; i++) { _bgPalettes[i].SaveState(stream); } for (int i = 0; i < _spPalettes.Length; i++) { _spPalettes[i].SaveState(stream); } }
public static void DisplayMatrixGen(int[,,,] array)//Generates a 4 Dimensional Matrix of dimensions [1,1,4,4], with it's elements randomly generated. { for (var i = 0; i < array.GetLength(0); i++) { Console.WriteLine("["); for (var j = 0; j < array.GetLength(1); j++) { Console.WriteLine(" {"); for (var k = 0; k < array.GetLength(2); k++) { for (var l = 0; l < array.GetLength(3); l++) { array[i, j, k, l] = random.Next(0, 20); //Randomly generates elements in the matrix Console.Write($" { array[i, j, k, l] }"); } Console.WriteLine(); } Console.WriteLine(" }"); } Console.WriteLine("]\n"); } }
public static void Main(string[] args) { OpMatrizNxNxN op = new OpMatrizNxNxN(); int[,,] vec = { { { 2, 4 }, { 3, 0 } }, { { 2, 4 }, { 5, 6 } } }; int[,,] vec2 = { { { 2, 3 }, { 3, 4 } }, { { 2, 4 }, { 5, 6 } } }; int[,,,] resposta = op.MultMatrizNxNxN(vec, vec2); for (int u = 0; u < resposta.GetLength(0); u++) { Console.Write("\n\n[CUBO {0}]", u); for (int z = 0; z < resposta.GetLength(0); z++) { Console.Write("\n[TABELA{0}]", z); //mostra vetor mostra vetor for (int i = 0; i < resposta.GetLength(0); i++) { Console.WriteLine(); for (int j = 0; j < resposta.GetLength(1); j++) { Console.Write("[{0}]", resposta[u, z, i, j]); } } } } Console.WriteLine(); }
public void SquareMatrix() { try { var arrayClone = (int[, , , ])matrix.Clone(); var rowCount = matrix.GetLength(2); int columnCount = matrix.GetLength(3); int cloneColumnCount = arrayClone.GetLength(3); if (rowCount == cloneColumnCount) { var arrayProduct = (int[, , , ])matrix.Clone(); for (var i = 0; i < rowCount; i++) { for (var j = 0; j < cloneColumnCount; j++) { var sum = 0; for (var k = 0; k < columnCount; k++) { var a = matrix[0, 0, i, k]; var b = arrayClone[0, 0, k, j]; sum += a * b; } arrayProduct[0, 0, i, j] = sum; } } Console.WriteLine("The Square of the matrix is: "); Show4DMatrix(arrayProduct); } else { Console.WriteLine("The matrix must have the same number of rows as columns, in order to be squared"); } } catch (Exception ex) { Console.WriteLine(ex.Message); } }
/// <summary> /// Chnage int[,,] to int[] /// </summary> /// <param name="input"></param> /// <returns></returns> public static int[] ChangeArray4dimTo1dim(int[,,,] input) { int row = input.GetLength(0); int colmun = input.GetLength(1); int depth = input.GetLength(2); int dim4 = input.GetLength(3); int[] result = new int[row * colmun * depth * dim4]; for (int i = 0; i < row; i++) { for (int j = 0; j < colmun; j++) { for (int k = 0; k < depth; k++) { for (int l = 0; l < dim4; l++) { result[i * colmun * depth * dim4 + j * depth * dim4 + k * dim4 + l] = input[i, j, k, l]; } } } } return(result); }
public static void AttemptRoomPlace(Vector2 TopLeft, List <int[]>[] RoomTileTypes, int[,,,] Rooms, ref bool[,] region, int type = -1) { for (int i = 0; i < 100; i++) { int x = Main.rand.Next(region.GetLength(0) - Rooms.GetLength(3)); int y = Main.rand.Next(region.GetLength(1) - Rooms.GetLength(2)); if (CheckRegion(x, y, Rooms.GetLength(3), Rooms.GetLength(2), region)) { Fortress2Blueprints.BuildRoom((int)(TopLeft.X + x), (int)(TopLeft.Y + y), RoomTileTypes, Rooms); OccupyRegion(x, y, Rooms.GetLength(3), Rooms.GetLength(2), ref region); return; } } }
/// <summary> /// Change int[,,,] to string[,,] /// </summary> /// <param name="input"></param> /// <returns></returns> public static string[,,,] Number_to_String(int[,,,] input) { string[,,,] result = new string[input.GetLength(0), input.GetLength(1), input.GetLength(2), input.GetLength(3)]; for (int i = 0; i < input.GetLength(0); i++) { for (int j = 0; j < input.GetLength(1); j++) { for (int k = 0; k < input.GetLength(2); k++) { for (int L = 0; L < input.GetLength(3); L++) { result[i, j, k, L] = input[i, j, k, L].ToString(); } } } } return(result); }
public static void SquaredMatrix(int[,,,] array) { var rowcount = rows; var columncount = columns; int[,,,] arrayCopy = (int[, , , ])array.Clone(); int[,,,] arrayProduct = (int[, , , ])array.Clone(); for (var i = 0; i < rowcount; i++) { for (var j = 0; j < arrayCopy.GetLength(1); j++) { var product = 0; for (var k = 0; k < columncount; k++) { var a = array[0, 0, i, k]; var b = arrayCopy[0, 0, k, j]; product += a * b; } arrayProduct[0, 0, i, j] = product; } } Console.WriteLine($"The square of the matrix is "); DisplayMatrixGen(arrayProduct); }
public void TestInt() { Console.WriteLine("intの型変換などに関するテストメソッドです。"); Console.WriteLine("int -> string はありますが、string -> int はありません。"); Console.WriteLine("string -> int? -> int の順番にする必要があります。\n"); Console.WriteLine("次のint[8]をstring[8]に変換します"); int[] testArray = new int[8] { 1, -2, 11, -31, -9, 22, 33, -9 }; Console.WriteLine("要素番号" + "\t" + "文字列"); for (int i = 0; i < testArray.GetLength(0); i++) { Console.WriteLine("[" + i + "]" + "\t\t" + testArray[i]); } Console.WriteLine("\n" + "string[8]に戻します。"); string[] convertBack = IOTypeChange.NumberToString(testArray); Console.WriteLine("要素番号" + "\t" + "文字列"); for (int i = 0; i < convertBack.GetLength(0); i++) { Console.WriteLine("[" + i + "]" + "\t\t" + convertBack[i]); } Console.WriteLine("\n\n\n" + "int[8]をint[2,4]に変換します"); int[,] array2Dimension = IOTypeChange.ChangeArray1dimTo2dim(testArray, 2, 4); for (int i = 0; i < array2Dimension.GetLength(0); i++) { for (int j = 0; j < array2Dimension.GetLength(1); j++) { Console.Write(array2Dimension[i, j] + "\t"); } Console.WriteLine(""); } Console.WriteLine("\n" + "多次元への拡張を意識して、要素番号とともにint[2,4]を記載します。"); Console.WriteLine("要素番号" + "\t" + "値"); for (int i = 0; i < array2Dimension.GetLength(0); i++) { for (int j = 0; j < array2Dimension.GetLength(1); j++) { Console.WriteLine("[" + i + "," + j + "]" + "\t\t" + array2Dimension[i, j]); } } Console.WriteLine("\n" + "元のint[8]に戻せることを確認します。"); int[] array1Dimension = IOTypeChange.ChangeArray2dimTo1dim(array2Dimension); Console.WriteLine("要素番号" + "\t" + "値"); for (int i = 0; i < array1Dimension.GetLength(0); i++) { Console.WriteLine("[" + i + "]" + "\t\t" + array1Dimension[i]); } Console.WriteLine("\n" + "int[8]をint[2,2,2]に変換します"); int[,,] array3Dimension = IOTypeChange.ChangeArray1dimTo3dim(testArray, 2, 2, 2); Console.WriteLine("要素番号" + "\t" + "値"); for (int i = 0; i < array3Dimension.GetLength(0); i++) { for (int j = 0; j < array3Dimension.GetLength(1); j++) { for (int k = 0; k < array3Dimension.GetLength(2); k++) { Console.WriteLine("[" + i + "," + j + "," + k + "]" + "\t\t" + array3Dimension[i, j, k]); } } } Console.WriteLine("\n" + "元のint[8]に戻せることを確認します。"); array1Dimension = IOTypeChange.ChangeArray3dimTo1dim(array3Dimension); Console.WriteLine("要素番号" + "\t" + "値"); for (int i = 0; i < array1Dimension.GetLength(0); i++) { Console.WriteLine("[" + i + "]" + "\t\t" + array1Dimension[i]); } Console.WriteLine("\n" + "int[8]をint[2,2,2,1]に変換します"); int[,,,] array4Dimension = IOTypeChange.ChangeArray1dimTo4dim(testArray, 2, 2, 2, 1); Console.WriteLine("要素番号" + "\t" + "値"); for (int i = 0; i < array4Dimension.GetLength(0); i++) { for (int j = 0; j < array4Dimension.GetLength(1); j++) { for (int k = 0; k < array4Dimension.GetLength(2); k++) { for (int dim4 = 0; dim4 < array4Dimension.GetLength(3); dim4++) { Console.WriteLine("[" + i + "," + j + "," + k + "," + dim4 + "]" + "\t\t" + array4Dimension[i, j, k, dim4]); } } } } Console.WriteLine("\n" + "元のint[8]に戻せることを確認します。"); array1Dimension = IOTypeChange.ChangeArray4dimTo1dim(array4Dimension); Console.WriteLine("要素番号" + "\t" + "値"); for (int i = 0; i < array1Dimension.GetLength(0); i++) { Console.WriteLine("[" + i + "]" + "\t" + array1Dimension[i]); } Console.WriteLine("\n\n\n" + "次のstring[2,4]をint[2,4]に変換します"); int[,] testArray2 = new int[2, 4] { { 1, -2, 11, -31 }, { -9, 22, 33, -9 } }; Console.WriteLine("要素番号" + "\t" + "文字列"); for (int i = 0; i < testArray2.GetLength(0); i++) { for (int j = 0; j < testArray2.GetLength(1); j++) { Console.WriteLine("[" + i + "," + j + "]" + "\t\t" + testArray2[i, j]); } } Console.WriteLine("\n" + "string[2,4]に変換します"); string[,] convertBack2 = IOTypeChange.NumberToString(testArray2); Console.WriteLine("要素番号" + "\t" + "文字列"); for (int i = 0; i < convertBack2.GetLength(0); i++) { for (int j = 0; j < convertBack2.GetLength(1); j++) { Console.WriteLine("[" + i + "," + j + "]" + "\t\t" + convertBack2[i, j]); } } Console.WriteLine("\n\n\n" + "次のstring[2,2,2]をint[2,2,2]に変換します"); int[,,] testArray3 = new int[2, 2, 2] { { { 1, -2 }, { 11, -31 } }, { { -9, 22 }, { 33, -9 } } }; Console.WriteLine("要素番号" + "\t" + "文字列"); for (int i = 0; i < testArray3.GetLength(0); i++) { for (int j = 0; j < testArray3.GetLength(1); j++) { for (int k = 0; k < testArray3.GetLength(2); k++) { Console.WriteLine("[" + i + "," + j + "," + k + "]" + "\t\t" + testArray3[i, j, k]); } } } Console.WriteLine("\n" + "string[2,2,2]に変換します"); string[,,] convertBack3 = IOTypeChange.NumberToString(testArray3); Console.WriteLine("要素番号" + "\t" + "文字列"); for (int i = 0; i < convertBack3.GetLength(0); i++) { for (int j = 0; j < convertBack3.GetLength(1); j++) { for (int k = 0; k < convertBack3.GetLength(2); k++) { Console.WriteLine("[" + i + "," + j + "," + k + "]" + "\t\t" + convertBack3[i, j, k]); } } } Console.WriteLine("\n\n\n" + "次のstring[2,2,2,1]をint[2,2,2,1]に変換します"); int[,,,] testArray4 = new int[2, 2, 2, 1] { { { { 1 }, { -2 } }, { { 11 }, { -31 } } }, { { { -9 }, { 22 } }, { { 33 }, { -9 } } } }; Console.WriteLine("要素番号" + "\t" + "文字列"); for (int i = 0; i < testArray4.GetLength(0); i++) { for (int j = 0; j < testArray4.GetLength(1); j++) { for (int k = 0; k < testArray4.GetLength(2); k++) { for (int dim4 = 0; dim4 < testArray4.GetLength(3); dim4++) { Console.WriteLine("[" + i + "," + j + "," + k + "," + dim4 + "]" + "\t\t" + testArray4[i, j, k, dim4]); } } } } Console.WriteLine("\n" + "string[2,2,2,1]に変換します。"); string[,,,] convertBack4 = IOTypeChange.NumberToString(testArray4); Console.WriteLine("要素番号" + "\t" + "文字列"); for (int i = 0; i < convertBack4.GetLength(0); i++) { for (int j = 0; j < convertBack4.GetLength(1); j++) { for (int k = 0; k < convertBack4.GetLength(2); k++) { for (int dim4 = 0; dim4 < convertBack4.GetLength(3); dim4++) { Console.WriteLine("[" + i + "," + j + "," + k + "," + dim4 + "]" + "\t\t" + convertBack4[i, j, k, dim4]); } } } } }
public IEnumerator <FourthDInt> GetEnumerator() { for (var i = 0; _cellField.GetLength(0) > i; i++) { for (var j = 0; _cellField.GetLength(1) > j; j++) { for (var k = 0; _cellField.GetLength(2) > k; k++) { for (var l = 0; _cellField.GetLength(3) > l; l++) { yield return(new FourthDInt(i, j, k, l, _cellField[i, j, k, l])); } } } } }
static void Main(string[] args) { Console.CursorVisible = false; int timer = 0; Thread inputThread = new Thread(Input); inputThread.Start(); bag = GenerateBag(); nextBag = GenerateBag(); NewBlock(); for (int y = 0; y < mapSizeY; y++) { for (int x = 0; x < mapSizeX; x++) { bg[y, x] = '-'; } } while (true) { // DOWN if (timer >= maxTime) { if (!Collision(currentIndex, bg, currentX, currentY + 1, currentRot)) { currentY++; } else { //maxTime--; //score += 100; //add block to bg for (int i = 0; i < positions.GetLength(2); i++) { bg[positions[currentIndex, currentRot, i, 1] + currentY, positions[currentIndex, currentRot, i, 0] + currentX] = currentChar; } // check for lines or something while (true) { int y = Line(bg); if (y != -1) { for (int x = 0; x < mapSizeX; x++) { bg[y, x] = '-'; } for (int i = y - 1; i > 0; i--) { for (int x = 0; x < mapSizeX; x++) { char character = bg[i, x]; if (character != '-') { bg[i, x] = '-'; bg[i + 1, x] = character; } } } continue; } break; } // new block NewBlock(); } timer = 0; } timer++; // INPUT bool space = false; switch (input.Key) { case ConsoleKey.LeftArrow: if (!Collision(currentIndex, bg, currentX - 1, currentY, currentRot)) { currentX -= 1; } break; case ConsoleKey.RightArrow: if (!Collision(currentIndex, bg, currentX + 1, currentY, currentRot)) { currentX += 1; } break; case ConsoleKey.UpArrow: int newRot = currentRot + 1; if (newRot >= 4) { newRot = 0; } if (!Collision(currentIndex, bg, currentX, currentY, newRot)) { currentRot = newRot; } break; case ConsoleKey.Spacebar: int i = 0; space = true; while (true) { i++; if (Collision(currentIndex, bg, currentX, currentY + i, currentRot)) { currentY += i - 1; break; } } break; case ConsoleKey.Escape: Environment.Exit(1); break; case ConsoleKey.Enter: if (holdIndex == -1) { holdIndex = currentIndex; holdChar = currentChar; NewBlock(); } else { if (!Collision(holdIndex, bg, currentX, currentY, 0)) { int c = currentIndex; char ch = currentChar; currentIndex = holdIndex; currentChar = holdChar; holdIndex = c; holdChar = ch; } } break; case ConsoleKey.DownArrow: timer = maxTime; break; default: break; } input = new ConsoleKeyInfo(); if (space) { continue; } // RENDER CURRENT char[,] view = new char[mapSizeY, mapSizeX]; for (int y = 0; y < mapSizeY; y++) { for (int x = 0; x < mapSizeX; x++) { view[y, x] = bg[y, x]; } } for (int i = 0; i < positions.GetLength(2); i++) { view[positions[currentIndex, currentRot, i, 1] + currentY, positions[currentIndex, currentRot, i, 0] + currentX] = currentChar; } // RENDER HOLD char[,] hold = new char[holdSizeY, holdSizeX]; for (int y = 0; y < holdSizeY; y++) { for (int x = 0; x < holdSizeX; x++) { hold[y, x] = ' '; } } if (holdIndex != -1) { for (int i = 0; i < positions.GetLength(2); i++) { hold[positions[holdIndex, 0, i, 1] + 1, positions[holdIndex, 0, i, 0] + 1] = holdChar; } } //RENDER UP NEXT char[,] next = new char[mapSizeY, upNextSize]; for (int y = 0; y < mapSizeY; y++) { for (int x = 0; x < upNextSize; x++) { next[y, x] = ' '; } } int nextBagIndex = 0; for (int i = 0; i < 3; i++) { for (int l = 0; l < positions.GetLength(2); l++) { if (i + bagIndex >= 7) { next[positions[nextBag[nextBagIndex], 0, l, 1] + 5 * i, positions[nextBag[nextBagIndex], 0, l, 0] + 1] = characters[nextBag[nextBagIndex]]; } else { next[positions[bag[bagIndex + i], 0, l, 1] + 5 * i, positions[bag[bagIndex + i], 0, l, 0] + 1] = characters[bag[bagIndex + i]]; } } if (i + bagIndex >= 7) { nextBagIndex++; } } // PRINT VIEW for (int y = 0; y < mapSizeY; y++) { for (int x = 0; x < holdSizeX + mapSizeX + upNextSize; x++) { char i = ' '; // Add hold + Main View + up next to view if (x < holdSizeX) { i = hold[y, x]; } else if (x >= holdSizeX + mapSizeX) { i = next[y, x - mapSizeX - upNextSize]; } else { i = view[y, (x - holdSizeX)]; } switch (i) { case 'O': Console.ForegroundColor = ConsoleColor.Red; Console.Write(i); break; case 'I': Console.ForegroundColor = ConsoleColor.Blue; Console.Write(i); break; case 'T': Console.ForegroundColor = ConsoleColor.Cyan; Console.Write(i); break; case 'S': Console.ForegroundColor = ConsoleColor.DarkMagenta; Console.Write(i); break; case 'Z': Console.ForegroundColor = ConsoleColor.DarkCyan; Console.Write(i); break; case 'L': Console.ForegroundColor = ConsoleColor.Green; Console.Write(i); break; case 'J': Console.ForegroundColor = ConsoleColor.DarkCyan; Console.Write(i); break; default: Console.ForegroundColor = ConsoleColor.DarkGray; Console.Write(i); break; } } //if (y == 1) //{ // Console.ForegroundColor = ConsoleColor.DarkGray; // Console.Write(" " + score); //} Console.WriteLine(); } Console.SetCursorPosition(0, Console.CursorTop - mapSizeY); Thread.Sleep(20); } }
public void ExportRoom(Vector2 position, int[,,,] Rooms) { position.X = (int)position.X; position.Y = (int)position.Y; //BuildTinyRoom((int)position.X, (int)position.Y, roomType); String tileList = "Tile type list: new int[] {-1"; String wallList = "Wall type list: new int[] {-1"; List <int> foundTiles = new List <int>() { -1 }; List <int> foundWalls = new List <int>() { -1 }; for (int y = 0; y < Rooms.GetLength(2); y++) { for (int x = 0; x < Rooms.GetLength(3); x++) { int i = (int)position.X + x; int j = (int)position.Y + y; if (Main.tile[i, j].active()) { if (!foundTiles.Contains(Main.tile[i, j].type)) { foundTiles.Add(Main.tile[i, j].type); if (Main.tile[i, j].type > 470) //checks if it's a modded tile { if (Main.tile[i, j].type == mod.TileType("FortressBrick")) { tileList += ", mod.TileType(\"FortressBrick\")"; } else if (Main.tile[i, j].type == mod.TileType("DnasBrick")) { tileList += ", mod.TileType(\"DnasBrick\")"; } else if (Main.tile[i, j].type == mod.TileType("ReverseSand")) { tileList += ", mod.TileType(\"ReverseSand\")"; } else if (Main.tile[i, j].type == mod.TileType("CaeliteBar")) { tileList += ", mod.TileType(\"CaeliteBar\")"; } else if (Main.tile[i, j].type == mod.TileType("ChiselledFortressBrick")) { tileList += ", mod.TileType(\"ChiselledFortressBrick\")"; } else if (Main.tile[i, j].type == mod.TileType("DnasLantern")) { tileList += ", mod.TileType(\"DnasLantern\")"; } else if (Main.tile[i, j].type == mod.TileType("DnasTransmutator")) { tileList += ", mod.TileType(\"DnasTransmutator\")"; } else if (Main.tile[i, j].type == mod.TileType("FakeFortressBrick")) { tileList += ", mod.TileType(\"FakeFortressBrick\")"; } else if (Main.tile[i, j].type == mod.TileType("FortressAltar")) { tileList += ", mod.TileType(\"FortressAltar\")"; } else if (Main.tile[i, j].type == mod.TileType("FortressCarving1")) { tileList += ", mod.TileType(\"FortressCarving1\")"; } else if (Main.tile[i, j].type == mod.TileType("FortressCarving2")) { tileList += ", mod.TileType(\"FortressCarving2\")"; } else if (Main.tile[i, j].type == mod.TileType("FortressCarving3")) { tileList += ", mod.TileType(\"FortressCarving3\")"; } else if (Main.tile[i, j].type == mod.TileType("FortressPillar")) { tileList += ", mod.TileType(\"FortressPillar\")"; } else if (Main.tile[i, j].type == mod.TileType("FortressPlatform")) { tileList += ", mod.TileType(\"FortressPlatform\")"; } else if (Main.tile[i, j].type == mod.TileType("FortressTrap")) { tileList += ", mod.TileType(\"FortressTrap\")"; } else if (Main.tile[i, j].type == mod.TileType("FortressTrap")) { tileList += ", mod.TileType(\"FortressTrap\")"; } else if (Main.tile[i, j].type == mod.TileType("LaunchPad")) { tileList += ", mod.TileType(\"LaunchPad\")"; } else if (Main.tile[i, j].type == mod.TileType("ReverseSand")) { tileList += ", mod.TileType(\"ReverseSand\")"; } else if (Main.tile[i, j].type == mod.TileType("FortressBathtub")) { tileList += ", mod.TileType(\"FortressBathtub\")"; } else if (Main.tile[i, j].type == mod.TileType("FortressBed")) { tileList += ", mod.TileType(\"FortressBed\")"; } else if (Main.tile[i, j].type == mod.TileType("FortressBench")) { tileList += ", mod.TileType(\"FortressBench\")"; } else if (Main.tile[i, j].type == mod.TileType("FortressBookcase")) { tileList += ", mod.TileType(\"FortressBookcase\")"; } else if (Main.tile[i, j].type == mod.TileType("FortressCandelabra")) { tileList += ", mod.TileType(\"FortressCandelabra\")"; } else if (Main.tile[i, j].type == mod.TileType("FortressCandle")) { tileList += ", mod.TileType(\"FortressCandle\")"; } else if (Main.tile[i, j].type == mod.TileType("FortressChair")) { tileList += ", mod.TileType(\"FortressChair\")"; } else if (Main.tile[i, j].type == mod.TileType("FortressChandelier")) { tileList += ", mod.TileType(\"FortressChandelier\")"; } else if (Main.tile[i, j].type == mod.TileType("FortressClock")) { tileList += ", mod.TileType(\"FortressClock\")"; } else if (Main.tile[i, j].type == mod.TileType("FortressCouch")) { tileList += ", mod.TileType(\"FortressCouch\")"; } else if (Main.tile[i, j].type == mod.TileType("FortressDresser")) { tileList += ", mod.TileType(\"FortressDresser\")"; } else if (Main.tile[i, j].type == mod.TileType("FortressLamp")) { tileList += ", mod.TileType(\"FortressLamp\")"; } else if (Main.tile[i, j].type == mod.TileType("FortressLantern")) { tileList += ", mod.TileType(\"FortressLantern\")"; } else if (Main.tile[i, j].type == mod.TileType("FortressPiano")) { tileList += ", mod.TileType(\"FortressPiano\")"; } else if (Main.tile[i, j].type == mod.TileType("FortressSink")) { tileList += ", mod.TileType(\"FortressSink\")"; } else if (Main.tile[i, j].type == mod.TileType("FortressTable")) { tileList += ", mod.TileType(\"FortressTable\")"; } else { tileList += ", " + Main.tile[i, j].type; tileList += "m"; } } else { tileList += ", " + Main.tile[i, j].type; } } } if (Framing.GetTileSafely(i, j).active()) { if (!foundWalls.Contains(Framing.GetTileSafely(i, j).wall)) { foundWalls.Add(Framing.GetTileSafely(i, j).wall); wallList += ", " + Framing.GetTileSafely(i, j).wall; if (Framing.GetTileSafely(i, j).wall > 230) // checks if it's a modded wall { wallList += "m"; } } } } } tileList += "}"; wallList += "}"; // create a writer and open the file TextWriter tw = new StreamWriter(roomName + ".txt"); // write a line of text to the file tw.WriteLine(tileList); tw.WriteLine(wallList); tw.WriteLine("Tile Structure: "); String tileStructure = "{ { {"; for (int y = 0; y < Rooms.GetLength(2); y++) { if (y != 0) { tileStructure += "},{"; } for (int x = 0; x < Rooms.GetLength(3); x++) { int i = (int)position.X + x; int j = (int)position.Y + y; if (x != 0) { tileStructure += ", "; } if (Main.tile[i, j].active()) { if (Main.tileFrameImportant[Main.tile[i, j].type]) { int width = TileObjectData.GetTileData(Main.tile[i, j].type, Main.tile[i, j].frameX).Width; int height = TileObjectData.GetTileData(Main.tile[i, j].type, Main.tile[i, j].frameX).Height; if ((Main.tile[i, j].frameX / 18) % width == TileObjectData.GetTileData(Main.tile[i, j].type, Main.tile[i, j].frameX).Origin.X&& (Main.tile[i, j].frameY / 18) % height == TileObjectData.GetTileData(Main.tile[i, j].type, Main.tile[i, j].frameX).Origin.Y) { tileStructure += foundTiles.IndexOf(Main.tile[i, j].type); } else { tileStructure += "0"; } } else { tileStructure += foundTiles.IndexOf(Main.tile[i, j].type); } } else { tileStructure += "0"; } } } tileStructure += "} }, { {"; for (int y = 0; y < Rooms.GetLength(2); y++) { if (y != 0) { tileStructure += "},{"; } for (int x = 0; x < Rooms.GetLength(3); x++) { int i = (int)position.X + x; int j = (int)position.Y + y; if (x != 0) { tileStructure += ", "; } if (foundWalls.IndexOf(Framing.GetTileSafely(i, j).wall) != -1) { tileStructure += foundWalls.IndexOf(Framing.GetTileSafely(i, j).wall); } else { tileStructure += "0"; } } } tileStructure += "} }, { {"; for (int y = 0; y < Rooms.GetLength(2); y++) { if (y != 0) { tileStructure += "},{"; } for (int x = 0; x < Rooms.GetLength(3); x++) { int i = (int)position.X + x; int j = (int)position.Y + y; if (x != 0) { tileStructure += ", "; } int slope = Main.tile[i, j].slope(); if (Main.tile[i, j].halfBrick()) { slope += 100; } tileStructure += slope; } } tileStructure += "} }, { {"; for (int y = 0; y < Rooms.GetLength(2); y++) { if (y != 0) { tileStructure += "},{"; } for (int x = 0; x < Rooms.GetLength(3); x++) { int i = (int)position.X + x; int j = (int)position.Y + y; if (x != 0) { tileStructure += ", "; } int wires = 0; if (Main.tile[i, j].wire()) { wires += 1; } if (Main.tile[i, j].wire2()) { wires += 10; } if (Main.tile[i, j].wire3()) { wires += 100; } if (Main.tile[i, j].wire4()) { wires += 1000; } if (Main.tile[i, j].actuator()) { wires += 10000; } tileStructure += wires; } } tileStructure += "} }, { {"; for (int y = 0; y < Rooms.GetLength(2); y++) { if (y != 0) { tileStructure += "},{"; } for (int x = 0; x < Rooms.GetLength(3); x++) { int i = (int)position.X + x; int j = (int)position.Y + y; if (x != 0) { tileStructure += ", "; } tileStructure += Main.tile[i, j].liquid; } } tileStructure += "} }, { {"; for (int y = 0; y < Rooms.GetLength(2); y++) { if (y != 0) { tileStructure += "},{"; } for (int x = 0; x < Rooms.GetLength(3); x++) { int i = (int)position.X + x; int j = (int)position.Y + y; if (x != 0) { tileStructure += ", "; } tileStructure += Main.tile[i, j].frameX; } } tileStructure += "} }, { {"; for (int y = 0; y < Rooms.GetLength(2); y++) { if (y != 0) { tileStructure += "},{"; } for (int x = 0; x < Rooms.GetLength(3); x++) { int i = (int)position.X + x; int j = (int)position.Y + y; if (x != 0) { tileStructure += ", "; } tileStructure += Main.tile[i, j].frameY; } } tileStructure += "} } }"; tw.WriteLine(tileStructure); // close the stream tw.Close(); PlaceUpdate(); }