using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using System.Threading; namespace _2d
{
class Dit
{
public int x, y; }
class Map
{
public void mp()
{
const int buy = 20;
for (int i = 0; i < buy; i++)
{
for (int j = 0; j < buy; j++)
{
if (i == 0 || i == buy - 1 || j == 0 || j == buy - 1)
Console.Write("█");
else
Console.Write(" ");
}
Console.WriteLine();
}
}
const char b='@';
const char d = ' ';
const char e = '*';
public int fenshu=0;
public void set(int x, int y, char b)
{
int buy = 20;
Console.SetCursorPosition(2 * y, x);
Console.Write(b);
Console.SetCursorPosition(0, buy);
} public void put()
{
int speed = 160;
int buy=20;
Random where = new Random();
Random _where=new Random();
Dit renwu = new Dit();
renwu.x = _where.Next(1, buy - 2);
renwu.y = _where.Next(1, buy - 2);
set(renwu.x, renwu.y, b);
bool food = false;
Dit _food=new Dit();
_food.x=where.Next(1,buy-2);
_food.y=where.Next(1,buy-2);
set(_food.y,_food.x,e); char c;
for (; ; )
{
c = Console.ReadKey(true).KeyChar; switch (c)
{ case 'w': set(renwu.x, renwu.y, d); set(renwu.x - 1, renwu.y, b); renwu.x--; Thread.Sleep(speed); break;
case 'a': set(renwu.x, renwu.y, d); set(renwu.x, renwu.y - 1, b); renwu.y--; Thread.Sleep(speed); break;
case 's': set(renwu.x, renwu.y, d); set(renwu.x + 1, renwu.y, b); renwu.x++; Thread.Sleep(speed); break;
case 'd': set(renwu.x, renwu.y, d); set(renwu.x, renwu.y + 1, b); renwu.y++; Thread.Sleep(speed); break;
}
if (renwu.x == 0 || renwu.y == 0 || renwu.x == buy - 1 || renwu.y == buy - 1)
{
Console.Clear();
Console.WriteLine("GameOver!\n您的得分是{0}",fenshu);
}
if(renwu.x==_food.y&&renwu.y==_food.x)
{
food=true;
_food.x = where.Next(1, buy - 2);
_food.y = where.Next(1, buy - 2);
set(_food.y, _food.x, e);
fenshu++;
}
} } } class Menu
{
public void paly()
{
Console.WriteLine("2d命令行小游戏");
Console.WriteLine("输入1开始游戏\n请将输入法调至英文状态");
}
public void start()
{
int a = Convert.ToInt32(Console.ReadLine());
if (a == 1)
{
Console.Clear();
Map _map = new Map();
_map.mp();
_map.put();
}
}
}
class Program
{
static void Main(string[] args)
{
Menu _menu = new Menu();
Console.CursorVisible = false;
_menu.paly();
_menu.start();
Console.ReadLine();
}
}
}

最新文章

  1. flexbox布局神器
  2. ACM/ICPC 之 最小割转网络流(POJ3469)
  3. C#中的Lambda表达式的演化过程
  4. Spring集成MyBatis完整示例
  5. jmeter随笔(1)-在csv中数据为json格式的数据不完整
  6. 46.谈谈SDRAM的作用
  7. ip_conntrack 实现
  8. 阿里云配置php环境 ubuntu12.04 32 nginx+php5+mysql
  9. JS学习笔记Day14
  10. Centos6.8-hadoop-2.7.2 64 bit源码编译(伪分布-5大守护进程在本机上)
  11. 基于zepto的移动端轻量级日期插件
  12. 一句话说清楚cache和buffer
  13. JS 中 if / if...else...替换方式
  14. MySQL中整型和字符串类型指定长度的含义
  15. python 菜鸟入门
  16. 【纯代码】Swift-自定义PickerView单选(可修改分割线颜色、修改字体大小、修改字体颜色。)(可根据需要自己扩展)
  17. 7个常见Javascript框架介绍
  18. $_SERVER[&#39;SCRIPT_NAME&#39;]、$_SERVER[&#39;SCRIPT_FILENAME&#39;]及__FILE__不同
  19. 解决IE6的PNG透明
  20. 关于android R.java文件无法创建的问题

热门文章

  1. thinkphp 5.1/tp5.1 route路由bug
  2. 20190118-利用Python实现Pig Latin游戏
  3. Python知乎热门话题爬取
  4. pip快速git项目安装
  5. P2P通讯
  6. Java基础之进制转换
  7. mysql 优化笔记
  8. MySQL不能连接本地数据库10061
  9. iOS 测试工具reveal可视化调试工具的使用
  10. MySQL日期函数、时间函数总结(MySQL 5.X)