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

  • 13
  • 0
  • 约3.12千字
  • 约 5页
  • 2017-07-09 发布于河南
  • 举报

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

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

using System;using System.Collections.Generic;using System.Linq;using System.Text;using System.Threading;namespace ConsoleApplication2{classProgram {staticvoid Main(string[] args) {棋盘 q=new棋盘(); q.snake(); } } }publicstruct坐标{ publicint sx;publicint sy;}class棋盘{publicstring[,] fg = newstring[35, 35];坐标[] a = new坐标[100];int n = 0;int 食物x, 食物y;publicvoid 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] = *; } }publicvoid snake() {int x = 0; hua();ConsoleKeyInfo cki = newConsoleKeyInfo(); 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); } }publicint 判断() {if (a[0].sx == 1 || a[0].sx == 34 || a[0].sy == 1 || a[0].sy == 34)

文档评论(0)

1亿VIP精品文档

相关文档