실행 코드
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
|
enum eMoveType
{
Up, Down, Right, Left
}
class App
{
public int[] xy;
public int[,] arr;
public App()
{
//int[,] arr = new int[6, 3]
//{ { 0, 0, 0 }, { 0, 0, 0 }, { 0 ,0, 0 }, { 0, 0, 0 },{ -1, -1, 0 }, { -1, -1, -1 } };
arr = new int[6, 3];
arr[4, 0] = -1;
arr[4, 1] = -1;
arr[5, 0] = -1;
arr[5, 1] = -1;
arr[5, 2] = -1;
for (int i = 0; i < 6; i++)
{
for (int j = 0; j < 3; j++)
{
Console.Write(arr[i, j]);
}
Console.WriteLine("");
}
int tileval = GetTileVal(1, -1);
Console.WriteLine(tileval);
var position = this.GetHeroPos(); //1, -1
Console.WriteLine("초기 현재 위치 : {0}, {1}", position[0], position[1]);
this.Move(eMoveType.Up);
var pos = this.GetHeroPos();
Console.WriteLine("Up 이동 위치 : {0}, {1}", pos[0], pos[1]);
this.Move(eMoveType.Down);
pos = this.GetHeroPos();
Console.WriteLine("Down 이동 위치 : {0}, {1}", pos[0], pos[1]);
this.Move(eMoveType.Right);
pos = this.GetHeroPos();
Console.WriteLine("Right 이동 위치 : {0}, {1}", pos[0], pos[1]);
this.Move(eMoveType.Left);
pos = this.GetHeroPos();
Console.WriteLine("Left 이동 위치 : {0}, {1}", pos[0], pos[1]);
}
public int GetTileVal(int x, int y)
{
if (x == 1 && y == -1)
{
arr[-y, x] = 100;
}
return arr[-y, x];
}
public int[] GetHeroPos()
{
for (int i = 0; i < 6; i++)
{
for (int j = 0; j < 3; j++)
{
if(arr[i, j] == 100)
{
xy = new int[2];
xy[0] = i;
xy[1] = -j;
break;
}
}
}
return this.xy;
}
public void Move(eMoveType moveType)
{
int x = this.xy[0];
int y = this.xy[1];
this.arr[x, -y] = 0;
switch (moveType)
{
case eMoveType.Down:
y--;
break;
case eMoveType.Up:
y++;
break;
case eMoveType.Right:
x++;
break;
case eMoveType.Left:
x--;
break;
}
this.arr[x, -y] = 100;
}
}
|
cs |
실행 창
'c# > 수업내용' 카테고리의 다른 글
캡쳐해서 아이콘 따는 법 (0) | 2020.05.14 |
---|---|
2020.05.13 ObjectPool을 왜 사용한 것인가? (0) | 2020.05.13 |
2020.04.29 출석 보상 아이템 (0) | 2020.04.30 |
2020.04.24 수업내용 업적과 % 출력 (0) | 2020.04.27 |
2020.04.22 json파일 역직렬화, 직렬화 Achievement (0) | 2020.04.22 |