Ai
1 Star 0 Fork 0

Junruoyu-Zheng/sonar-captain-cli

加入 Gitee
与超过 1200万 开发者一起发现、参与优秀开源项目,私有仓库也完全免费 :)
免费加入
文件
克隆/下载
Game.cs 2.94 KB
一键复制 编辑 原始数据 按行查看 历史
Junruoyu-Zheng 提交于 2021-06-01 23:36 +08:00 . add: map class and display map method
using System;
namespace SonarCaptain
{
class Game
{
#region static resources
public static int ROW_COUNT = 10;
public static int COLUMN_COUNT = 10;
public static int ISLAND_COUNT = 8;
#endregion
#region properties
public string RoomName {get; private set;}
public Routine MyRoutine {get;} = new Routine();
public Map WarFieldMap {get;} = new Map();
#endregion
#region start
private bool SetRoomName(string roomName)
{
if (roomName.Length == 6)
{
RoomName = roomName;
return true;
}
else
{
return false;
}
}
public void StartHandler()
{
while (true)
{
Console.WriteLine("请输入6位房间号:");
string roomName = Console.ReadLine();
if (SetRoomName(roomName))
{
break;
}
Console.Write("房间号不合法,");
}
}
#endregion
#region initial
private (int, int) GetPosition(string position)
{
int rowPosition = -1;
int colPosition = -1;
if (position.Length < 2 || position.Length > 3)
{
return (-1, -1);
}
if (position[0]>='a' && position[0]<='z')
{
rowPosition = position[0] - 'a';
}
else if (position[0]>='A' && position[0]<='Z')
{
rowPosition = position[0] - 'A';
}
if (position[1]>='0' && position[1]<='9')
{
colPosition = position[1] - '0';
}
if (position.Length == 3)
{
colPosition *= 10;
if (position[2]>='0' && position[2]<='9')
{
colPosition += position[2] - '0';
}
else
{
colPosition = -1;
}
}
return (rowPosition, colPosition);
}
private bool ValidatePosition((int, int) position)
{
return position.Item1 >= 0 && position.Item1 <= 25 && position.Item2 >= 0 && position.Item2 <= 25;
}
public void InitialHandler()
{
while (true)
{
Console.Clear();
WarFieldMap.PrintMap();
Console.WriteLine("请输入初始化位置(如A3、J07、D22等):");
var position = GetPosition(Console.ReadLine());
if (ValidatePosition(position))
{
MyRoutine.StartPosition = position;
break;
}
Console.Write("位置不合法,");
}
}
#endregion
}
}
Loading...
马建仓 AI 助手
尝试更多
代码解读
代码找茬
代码优化
1
https://gitee.com/junruoyu-zheng/sonar-captain-cli.git
git@gitee.com:junruoyu-zheng/sonar-captain-cli.git
junruoyu-zheng
sonar-captain-cli
sonar-captain-cli
master

搜索帮助