using System;
using System.Collections.Generic;
using System.Linq;
using System.Runtime.InteropServices;
using System.Text;
using System.Threading.Tasks;
namespace LearnDotnet
{
internal class App
{
//생성자
int[,] playerMap;
int rowIdx;
int colIdx;
public App()
{
int[,] arr =
{
{1,1,1 },
{1,1,2 }
};
playerMap = new int[arr.GetLength(0),arr.GetLength(1)];
this.rowIdx = 1;
this.colIdx = 2;
playerMap[this.rowIdx, this.colIdx] = 100;
this.PrintMap(playerMap);
this.PrintSpace();
this.MoveLeft();
this.PrintMap(playerMap);
this.PrintSpace();
this.MoveLeft();
this.PrintMap(playerMap);
this.PrintSpace();
this.MoveLeft();
this.PrintMap(playerMap);
this.PrintSpace();
}
void PrintSpace()
{
Console.WriteLine();
}
void PrintMap(int[,] arr)
{
for (int x = 0; x < arr.GetLength(0); x++)
{
for (int y = 0; y < arr.GetLength(1); y++)
{
Console.Write("{0} ", arr[x, y]);
}
Console.WriteLine();
}
}
void MoveLeft()
{
if (this.colIdx != 0)
{
playerMap[this.rowIdx, this.colIdx - 1] = 100;
playerMap[this.rowIdx, this.colIdx] = 0;
this.colIdx -= 1;
Console.WriteLine("왼쪽으로 이동 [{0},{1}], {2}", this.rowIdx, this.colIdx, this.playerMap[this.rowIdx, this.colIdx]);
}
else
{
Console.WriteLine("이동이 불가능 합니다.");
return;
}
}
}
}
반응형
'KDT > C# 프로그래밍' 카테고리의 다른 글
(1x4) 2048 (0) | 2023.07.26 |
---|---|
2차원 배열 맵에서 플레이어 키보드 이동 (0) | 2023.07.26 |
아이템 순차 출력 (0) | 2023.07.25 |
1차원 인벤토리 + 용량 늘리기 (0) | 2023.07.25 |
1차원 배열 인벤토리 (0) | 2023.07.24 |