为了正常的体验网站,请在浏览器设置里面开启Javascript功能!

自己做得C#控制台程序 贪吃蛇 DOS界面 测试通过

2017-12-07 8页 doc 19KB 71阅读

用户头像

is_729658

暂无简介

举报
自己做得C#控制台程序 贪吃蛇 DOS界面 测试通过自己做得C#控制台程序 贪吃蛇 DOS界面 测试通过 using System; using System.Collections.Generic; using System.Linq; using System.Text; using System.Threading;namespace ConsoleApplication2{ class Program { static void Main(string[] args) { 棋盘 q=new 棋盘(); q.snake(); } } } public struct 坐盘...
自己做得C#控制台程序  贪吃蛇  DOS界面  测试通过
自己做得C#控制台程序 贪吃蛇 DOS界面 测试通过 using System; using System.Collections.Generic; using System.Linq; using System.Text; using System.Threading;namespace ConsoleApplication2{ class Program { static void Main(string[] args) { 棋盘 q=new 棋盘(); q.snake(); } } } public struct 坐盘 { public int sx; public int sy; } class 棋盘 { public string[,] fg = new string[35, 35]; 坐盘[] a = new 坐盘[100]; int n = 0; int 食物x, 食物y; public void hua() { int i, j; for (i = 0; i < 35;i++ ) { for (j = 0; j < 35; j++) { fg[i, j] = " "; } } for (i = 0; i < 35; i++) { if (i == 0 || i == 34) { for (j = 0; j < 35; j++) { fg[i, j] = "*"; } } fg[i, 0] = "*"; fg[i, 34] = "*"; } } public void snake() { int x = 0; hua(); ConsoleKeyInfo cki = new ConsoleKeyInfo(); a[0].sx = 20; a[0].sy = 20; 食物x = 食物(); 食物y = 食物(); fg[食物x, 食物y]="$"; while(true) { if (判断() == 0) { break; } 判断2(); if (System.Console.KeyAvailable) { cki = Console.ReadKey(true); if (cki.Key == ConsoleKey.UpArrow) { if (x == 2) x = 2; else x = 1; } if (cki.Key == ConsoleKey.DownArrow) { if (x == 1) x = 1; else x = 2; } if (cki.Key == ConsoleKey.LeftArrow) { if (x == 0) x = 0; else x = 3; } if (cki.Key == ConsoleKey.RightArrow) { if (x == 3) x = 3; else x = 0; } } switch (x) { case 0: 移盘(); a[0].sy++; break; case 1: 移盘(); a[0].sx--; break; case 2: 移盘 (); a[0].sx++; break; case 3: 移盘 (); a[0].sy--; break; } 盘示(); Thread.Sleep(300); } } public int 判断() { if (a[0].sx == 1 || a[0].sx == 34 || a[0].sy == 1 || a[0].sy == 34) { Console.WriteLine("游盘盘束"); Console.ReadLine(); return 0; } else return 1; } public void 判断2() { int i=1; while(i<=n) { if ((a[0].sx == a[i].sx) && (a[0].sy == a[i].sy)) { Console.WriteLine("游盘盘束"); Console.ReadLine(); } else i++; } } public int 食物() { Random ra=new Random(); return ra.Next(1,34); } public void 盘示() { int i, j; hua(); fg[食物x, 食物y] = "$"; fg[a[0].sx, a[0].sy] = "@"; for (i = n; i >0; i--) { Console.WriteLine("ssssss" + i); fg[a[i].sx, a[i].sy] = "#"; } Console.Clear(); for (i = 0; i < 35; i++) { for (j = 0; j < 35; j++) { Console.Write(fg[i,j]); } Console.WriteLine(); } } public int 判食物断() { if (食物x == a[0].sx && 食物y == a[0].sy) { return 1; } else return 0; } public void 移盘() { int i; if (判食物断() == 1) { n++; 食物x = 食物(); 食物y = 食物(); } for (i = n; i > 0; i--) { a[i].sx = a[i - 1].sx; a[i].sy = a[i - 1].sy; } } }
/
本文档为【自己做得C#控制台程序 贪吃蛇 DOS界面 测试通过】,请使用软件OFFICE或WPS软件打开。作品中的文字与图均可以修改和编辑, 图片更改请在作品中右键图片并更换,文字修改请直接点击文字进行修改,也可以新增和删除文档中的内容。
[版权声明] 本站所有资料为用户分享产生,若发现您的权利被侵害,请联系客服邮件isharekefu@iask.cn,我们尽快处理。 本作品所展示的图片、画像、字体、音乐的版权可能需版权方额外授权,请谨慎使用。 网站提供的党政主题相关内容(国旗、国徽、党徽..)目的在于配合国家政策宣传,仅限个人学习分享使用,禁止用于任何广告和商用目的。

历史搜索

    清空历史搜索