资源简介
C#控制台编写的贪吃蛇,欢迎大家一起探讨学习,要积分是为了下其它东西,我也是被逼的!
代码片段和文件信息
using System;
using System.Collections.Generic;
using System.Text;
namespace GluttonousSnake
{
class Map
{
Random ran = new Random();
public int length = 25;
public int wide = 25;
public char[] maps;
public int[] food;
///
/// 绘制出地图边界
///
public void DrawMap()
{
maps = new char[length wide];
for (int i = 0; i < maps.GetLength(0); i++)
{
for (int j = 0; j < maps.GetLength(1); j++)
{
if (i == 0|| j == 0 || j == maps.GetLength(1) - 1|| i == maps.GetLength(0) - 1)
{
maps[i j] = ‘▓‘;
}
else
{
maps[i j] = ‘ ‘;
}
}
}
}
///
/// 打印地图
///
public void PrintMap()
{
Console.Clear();
for (int i = 0; i < maps.GetLength(0); i++)
{
for (int j = 0; j < maps.GetLength(1); j++)
{
Console.SetCursorPosition(j * 2 i);
Console.Write(maps[i j]);
}
}
Console.CursorVisible = false;
}
///
/// 随机生成一个蛇
///
public void RandomSnake(Snake sn)
{
sn.snakeList = new List();
int x =ran.Next(1 length - 1);
int y =ran.Next(1 wide - 1);
for (int i = 0; i < sn.lenght; i++)
{
int[] xy = new int[2];
xy[0] = x;
xy[1] = y - i;
sn.snakeList.Add(xy);
//maps[xy[0] xy[1]] = “♀“;
maps[xy[0] xy[1]] = ‘♀‘;
Console.SetCursorPosition(xy[1]*2 xy[0]);
Console.Write(maps[xy[0] xy[1]]);
}
}
///
/// 随机一个食物
///
public void RandomFood(List snkeList)
{
int x=1;
int y=1;
bool bl = true;
while (bl)
{
x = ran.Next(1 length - 1);
y = ran.Next(1 wide - 1);
int i=0;
foreach (var item in snkeList)
{
if (item[0] == x && item[1] == y)
{
i++;
}
}
if (i==0)
{
bl = false;
}
}
food = new int[2];
food[0] = x;
food[1] = y;
maps[x y] = ‘〇‘;
Console.SetCursorPosition(y*2 x);
Console.Write(maps[x
属性 大小 日期 时间 名称
----------- --------- ---------- ----- ----
目录 0 2018-05-28 20:15 GluttonousSnake\
目录 0 2018-05-28 20:15 GluttonousSnake\.vs\
目录 0 2018-05-28 20:15 GluttonousSnake\.vs\GluttonousSnake\
目录 0 2018-05-28 20:15 GluttonousSnake\.vs\GluttonousSnake\DesignTimeBuild\
文件 368916 2018-05-29 00:34 GluttonousSnake\.vs\GluttonousSnake\DesignTimeBuild\.dtbcache
目录 0 2018-05-28 20:15 GluttonousSnake\.vs\GluttonousSnake\v15\
文件 32256 2018-05-29 00:39 GluttonousSnake\.vs\GluttonousSnake\v15\.suo
目录 0 2018-05-28 20:15 GluttonousSnake\.vs\GluttonousSnake\v15\Server\
目录 0 2018-05-28 20:15 GluttonousSnake\.vs\GluttonousSnake\v15\Server\sqlite3\
文件 0 2018-05-27 10:34 GluttonousSnake\.vs\GluttonousSnake\v15\Server\sqlite3\db.lock
文件 634880 2018-05-29 00:19 GluttonousSnake\.vs\GluttonousSnake\v15\Server\sqlite3\storage.ide
文件 32768 2018-05-29 00:36 GluttonousSnake\.vs\GluttonousSnake\v15\Server\sqlite3\storage.ide-shm
文件 4144752 2018-05-29 00:34 GluttonousSnake\.vs\GluttonousSnake\v15\Server\sqlite3\storage.ide-wal
目录 0 2018-05-29 00:32 GluttonousSnake\GluttonousSnake\
文件 178 2018-05-27 10:33 GluttonousSnake\GluttonousSnake\GluttonousSnake.csproj
文件 3090 2018-05-28 23:35 GluttonousSnake\GluttonousSnake\Map.cs
文件 2186 2018-05-29 00:32 GluttonousSnake\GluttonousSnake\Program.cs
文件 9722 2018-05-28 23:38 GluttonousSnake\GluttonousSnake\Snake.cs
目录 0 2018-05-28 20:15 GluttonousSnake\GluttonousSnake\bin\
目录 0 2018-05-28 20:15 GluttonousSnake\GluttonousSnake\bin\Debug\
目录 0 2018-05-28 20:15 GluttonousSnake\GluttonousSnake\bin\Debug\netcoreapp2.0\
文件 477 2018-05-29 00:34 GluttonousSnake\GluttonousSnake\bin\Debug\netcoreapp2.0\GluttonousSnake.deps.json
文件 10752 2018-05-29 00:34 GluttonousSnake\GluttonousSnake\bin\Debug\netcoreapp2.0\GluttonousSnake.dll
文件 3804 2018-05-29 00:34 GluttonousSnake\GluttonousSnake\bin\Debug\netcoreapp2.0\GluttonousSnake.pdb
文件 248 2018-05-29 00:34 GluttonousSnake\GluttonousSnake\bin\Debug\netcoreapp2.0\GluttonousSnake.runtimeconfig.dev.json
文件 154 2018-05-29 00:34 GluttonousSnake\GluttonousSnake\bin\Debug\netcoreapp2.0\GluttonousSnake.runtimeconfig.json
目录 0 2018-05-29 00:34 GluttonousSnake\GluttonousSnake\obj\
目录 0 2018-05-28 20:15 GluttonousSnake\GluttonousSnake\obj\Debug\
目录 0 2018-05-28 20:15 GluttonousSnake\GluttonousSnake\obj\Debug\netcoreapp2.0\
文件 1028 2018-05-27 10:34 GluttonousSnake\GluttonousSnake\obj\Debug\netcoreapp2.0\GluttonousSnake.AssemblyInfo.cs
文件 42 2018-05-27 10:34 GluttonousSnake\GluttonousSnake\obj\Debug\netcoreapp2.0\GluttonousSnake.AssemblyInfoInputs.cache
............此处省略10个文件信息
- 上一篇:C#星号密码查看器
- 下一篇:asp.net(增删改查)
相关资源
- C#星号密码查看器
- winform C# 实现百度地图
- C#调用摄像头拍照录像保存
- 带进度条的C#软件启动特效,类似Wo
- MyIE_V1.0_最终版源代码
- C# 抓取数据
- 多窗口应用程序(C#源代码编写)
- C#词频统计
- c#基于颜色特征的求解两张图片的相似
- C# API 大全
- 用C#语言实现的教务管理系统
- C#制作IP地址控件(IP、子网掩码、网
- C#远程桌面实时监控源码
- 基于UDP的文件传输DEMOC#编程实现,可
- C# 画流程图49290
- C# lua库 支持中文函数名中文变量
- C#二维码生成及批量打印
- C#毕业设计管理系统带论文
- 自制C#财物管理系统
- C#获取微信小程序openid等用户信息(前
- CLR via C# 第4版.pdf
- c# 视频播放的分屏算法分享给大家
- C# 坐标正反算
- ArcGIS Mobile 开发 Visual Studio 2008 C#
- UDP异步通讯SocketAsyncEventArgs
- 台达PLC modbus通信上位机64位C#
- Tamir.SharpSS、访问sftp库
- 纯C#绘图控件 支持各种几何图形绘制
- C#实现滚动字幕完整源码_100.rar
- 例8_IO.zip雷赛运动控制卡C#案例
评论
共有 条评论