1 Star 0 Fork 0

Junruoyu-Zheng/sonar-captain-cli

加入 Gitee
与超过 1200万 开发者一起发现、参与优秀开源项目,私有仓库也完全免费 :)
免费加入
文件
克隆/下载
Map.cs 2.24 KB
一键复制 编辑 原始数据 按行查看 历史
Junruoyu-Zheng 提交于 2021-06-01 23:36 +08:00 . add: map class and display map method
using System;
using System.Linq;
namespace SonarCaptain
{
enum MapState
{
EMPTY, ISLAND, TRACK, PLAYER, MASK
}
class Map
{
public int RowCount {get; set;} = Game.ROW_COUNT;
public int ColumnCount {get; set;} = Game.COLUMN_COUNT;
public MapState[,] MapInfo {get;} = new MapState[Game.ROW_COUNT, Game.COLUMN_COUNT];
public Map()
{
var random = new Random();
for (int i=0; i < Game.ISLAND_COUNT; i++)
{
while (true)
{
int rowIndex = random.Next(1, RowCount-1);
int columnIndex = random.Next(1, ColumnCount-1);
if (MapInfo[rowIndex, columnIndex] == MapState.EMPTY)
{
MapInfo[rowIndex, columnIndex] = MapState.ISLAND;
break;
}
}
}
}
public void PrintMap()
{
Console.Write(' ');
for (int i=0; i < ColumnCount; i++)
{
Console.Write(' ');
Console.Write(i.ToString().Last());
}
Console.WriteLine();
for (int r=0; r < RowCount; r++)
{
Console.Write((char) (r+'A'));
for (int c=0; c < ColumnCount; c++)
{
Console.Write(' ');
switch (MapInfo[r, c])
{
case MapState.EMPTY:
Console.Write('+');
break;
case MapState.ISLAND:
Console.Write('O');
break;
case MapState.PLAYER:
Console.Write('x');
break;
case MapState.TRACK:
Console.Write('*');
break;
case MapState.MASK:
Console.Write('.');
break;
}
}
Console.WriteLine();
}
Console.WriteLine("图例:空(+)岛屿(O)玩家(x)轨迹(*)蒙版(.)");
}
}
}
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

搜索帮助