using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
namespace Study0121
{
class App
{
private int[,] arr2;
private int colIndex = 0; //1차원 인덱스
private int rowIndex = 0; //2차원 인덱스
//생성자
public App()
{
int[,] arr = new int[2, 3]; //1차원의 길이 3, 2차원의 길이 2
for (int i = 0; i < 2; i++)
{
for (int j = 0; j < 3; j++)
{
arr[i, j] = 1;
}
}
arr[1, 2] = 2;
for (int i = 0; i < 2; i++)
{
for (int j = 0; j < 3; j++)
{
Console.Write("{0} ", arr[i, j]);
}
Console.WriteLine();
}
this.arr2 = new int[2, 3];
this.rowIndex = 1;
this.colIndex = 2;
this.arr2[this.rowIndex, this.colIndex] = 100;
this.MoveDown();
this.PrintArr2();
this.MoveDown();
this.PrintArr2();
}
void MoveUp()
{
int to = rowIndex - 1; //2차원
Console.WriteLine("{0}, {1}", to, this.arr2.GetLength(0) - 1);
if (to < 0)
{
Console.WriteLine("막혀있습니다.");
}
else
{
this.arr2[to, this.colIndex] = this.arr2[this.rowIndex, this.colIndex];
this.arr2[this.rowIndex, this.colIndex] = 0;
this.rowIndex = to;
}
}
void MoveDown()
{
int to = rowIndex + 1; //2차원
if (to > this.arr2.GetLength(0) - 1)
{
Console.WriteLine("막혀있습니다.");
}
else
{
this.arr2[to, this.colIndex] = this.arr2[this.rowIndex, this.colIndex];
this.arr2[this.rowIndex, this.colIndex] = 0;
this.rowIndex = to;
}
}
void MoveLeft()
{
int to = this.colIndex - 1;
if (to < 0)
{
Console.WriteLine("막혀있습니다.");
}
else
{
this.arr2[1, to] = 100;
this.arr2[1, this.colIndex] = 0;
this.colIndex = to;
}
}
void MoveRight()
{
int to = this.colIndex + 1;
if (to < 0)
{
Console.WriteLine("막혀있습니다.");
}
else
{
this.arr2[1, to] = 100;
this.arr2[1, this.colIndex] = 0;
this.colIndex = to;
}
}
void PrintArr2()
{
for (int i = 0; i < arr2.GetLength(0); i++)
{
for (int j = 0; j < arr2.GetLength(1); j++)
{
Console.Write("{0} ", arr2[i, j]);
}
Console.WriteLine();
}
}
}
}