基本信息
源码名称:坦克的算法
源码大小:0.06M
文件格式:.zip
开发语言:C#
更新时间:2017-09-06
友情提示:(无需注册或充值,赞助后即可获取资源下载链接)
嘿,亲!知识可是无价之宝呢,但咱这精心整理的资料也耗费了不少心血呀。小小地破费一下,绝对物超所值哦!如有下载和支付问题,请联系我们QQ(微信同号):78630559
本次赞助数额为: 20 元×
微信扫码支付:20 元
×
请留下您的邮箱,我们将在2小时内将文件发到您的邮箱
源码介绍
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
namespace test
{
class Program
{
static void Main(string[] args)
{
//坦克信号:
//MTMPRPMTMLMRPRMTPLMMTLMRRMP
var xinhao = "MTMPRPMTMLMRPRMTPLMMTLMRRMP";
//坦克坐标
var xy = new int[] { 11, 39 };
//坦克运行方向
string direction = "W";
foreach (var xh in xinhao)
{
switch (xh)
{
case 'L':
case 'R':
direction = set_news(direction, xh);
break;
case 'M':
xy = set_xy(xy, direction);
break;
default:
break;
}
}
Console.Write("{0},{1}", xy[0], xy[1]);
}
//旋转
private static string set_news(string news, char xh)
{
string directions = "NESW";
var index = directions.IndexOf(news);
if (xh == 'R')
{
return directions[index >= 3 ? 0 : index 1].ToString();
}
else
{
return directions[index <= 0 ? 3 : index - 1].ToString();
}
}
//移动
private static int[] set_xy(int[] xy, string news)
{
switch (news)
{
case "N"://北
xy[1] = xy[1] 1;
break;
case "E"://东
xy[0] = xy[0] 1;
break;
case "S"://南
xy[1] = xy[1] - 1;
break;
case "W"://西
xy[0] = xy[0] - 1;
break;
}
return xy;
}
}
}