2019-10-23 23일차 엔트리 라인레인저스 내용을 코드로바꾸면
Console Programming/C# Console 2019. 10. 24. 17:48
나의 위치는1
미네랄은 10
종점은 2로 표현했다.
Program.cs
namespace Syntax04
{
class Program
{
static void Main(string[] args)
{
new App();
}
}
}
App.cs
using System;
namespace Syntax04
{
public class App
{
private int[] arr;
private int mineral;
public App()
{
arr = new int[5]
{
1,0,10,0,2
};
Show();
MoveRight(0);
Show();
}
public void Show()
{
for(int i = 0; i < arr.Length; i++)
{
Console.Write($"{arr[i]}\t");
}
Console.WriteLine();
Console.WriteLine($"Mineral = {mineral}");
Console.WriteLine("==========================");
}
public bool CheckCell(int num)
{
if (num >= 0 && num < arr.Length)
{
if(arr[num]==0 || arr[num]==10||arr[num]==2)
{
return true;
}
}
return false;
}
public void MoveRight(int startRow)
{
var nextRow = startRow + 1;
var val = arr[startRow];
if (CheckCell(nextRow))
{
if(arr[nextRow]==10)
{
mineral += arr[nextRow];
}
if(arr[nextRow]==2)
{
arr[nextRow] = val;
arr[startRow] = 0;
return;
}
arr[nextRow] = val;
arr[startRow] = 0;
MoveRight(nextRow);
}
else
{
return;
}
}
}
}
'Console Programming > C# Console' 카테고리의 다른 글
2019-10-23 게임 만들기 2048 게임 (0) | 2019.10.24 |
---|---|
2019-10-23 23일차 Json 역직렬화, 직렬화 (0) | 2019.10.24 |
2019-10-23 23일차 재귀함수 4 x 5행렬에서 숫자 움직이기 (0) | 2019.10.24 |
2019-10-23 23일차 재귀함수(2) (0) | 2019.10.24 |
2019-10-23 23일차 스택의 사용방법 (0) | 2019.10.24 |