資源簡介
C# 實現貪吃蛇小游戲的設計編寫,vs2015
鍵盤方向鍵控制。有初、中、高三個級別

代碼片段和文件信息
using?System;
using?System.Collections.Generic;
using?System.ComponentModel;
using?System.Data;
using?System.Drawing;
using?System.Linq;
using?System.Text;
using?System.Windows.Forms;
namespace?貪吃蛇小游戲
{
????public?partial?class?frmMain?:?Form
????{
????????public?static?bool?isStart?=?false;//判斷是否開始
????????public?static?int?speed?=?400;//移動的速度
????????public?static?bool?isPause?=?false;//是否暫停游戲
????????SnakeGame?game?=?new?SnakeGame();
????????private?int?snakeH?=?20;//蛇的一節高度
????????private?int?snakeW?=?20;//蛇的一節寬度
????????public?frmMain()
????????{
????????????InitializeComponent();
????????}
????????private?void?DrawGamePoint(Graphics?g)
????????{
????????????for?(int?i?=?0;?i?<=?panel1.Width?/?snakeW;?i++)
????????????{
????????????????g.DrawLine(new?Pen(Color.Black?1)?new?Point(i?*?snakeW?0)?new?Point(i?*?snakeW?panel1.Height));
????????????}
????????????for?(int?i?=?0;?i?<=?panel1.Height?/?snakeH;?i++)
????????????{
????????????????g.DrawLine(new?Pen(Color.Black?1)?new?Point(0?i?*?snakeH)?new?Point(panel1.Width?i?*?snakeH));
????????????}
????????}
????????private?void?panel1_Paint(object?sender?PaintEventArgs?e)
????????{
????????????Graphics?g?=?panel1.CreateGraphics();
????????????DrawGamePoint(g);
????????????if?(!isStart)
????????????{
????????????????SnakeGame.timer?=?timer1;
????????????????SnakeGame.label?=?label2;
????????????????game.CreateSnake(panel1?snakeH);
????????????}
????????????else
????????????{
????????????????for?(int?i?=?0;?i?????????????????{
????????????????????g.FillRectangle(SnakeGame.SnakeColor?((Point)SnakeGame.List[i]).X?+?1?((Point)SnakeGame.List[i]).Y?+?1?snakeW?-?1?snakeH?-?1);
????????????????}
????????????????g.FillRectangle(SnakeGame.FoodColor?SnakeGame.Food.X?+?1?SnakeGame.Food.Y?+?1?snakeW?-?1?snakeH?-?1);
????????????????if?(SnakeGame.ifGame)
????????????????{
????????????????????e.Graphics.DrawString(“GAME?OVER“?new?Font(“宋體“?30?Fontstyle.Bold)?new?SolidBrush(Color.DarkSlateGray)?new?PointF(150?130));
????????????????}
????????????}
????????}
????????///?
????????///?控制游戲開始,暫停,結束
????????///?
????????///?根據標識位(1=開始,2=暫停,3=結束)
????????private?void?ControlGame(int?tag)
????????{
????????????switch?(tag)
????????????{
????????????????case?1://開始游戲
????????????????????{
????????????????????????isStart?=?false;
????????????????????????Graphics?g?=?panel1.CreateGraphics();
????????????????????????g.FillRectangle(SnakeGame.PlanColor?0?0?panel1.Width?panel1.Height);
????????????????????????DrawGamePoint(g);
????????????????????????isStart?=?true;
????????????????????????game.CreateSnake(panel1?snakeH);
????????????????????????timer1.Interval?=?speed;
????????????????????????timer1.Start();
????????????????????????isPause?=?true;
????????????????????????label2.Text?=?“0“;
????????????????????????break;
??????????????????
?屬性????????????大小?????日期????時間???名稱
-----------?---------??----------?-----??----
?????目錄???????????0??2018-12-12?16:45??貪吃蛇小游戲\
?????目錄???????????0??2018-12-11?16:49??貪吃蛇小游戲\bin\
?????目錄???????????0??2018-12-12?16:39??貪吃蛇小游戲\bin\Debug\
?????文件???????16896??2018-12-12?16:39??貪吃蛇小游戲\bin\Debug\貪吃蛇小游戲.exe
?????文件???????34304??2018-12-12?16:39??貪吃蛇小游戲\bin\Debug\貪吃蛇小游戲.pdb
?????文件???????22688??2018-12-12?16:38??貪吃蛇小游戲\bin\Debug\貪吃蛇小游戲.vshost.exe
?????文件?????????490??2015-10-22?09:54??貪吃蛇小游戲\bin\Debug\貪吃蛇小游戲.vshost.exe.manifest
?????目錄???????????0??2018-12-11?16:49??貪吃蛇小游戲\bin\Release\
?????文件????????8321??2018-12-12?16:45??貪吃蛇小游戲\frmMain.cs
?????文件???????10320??2018-12-12?16:36??貪吃蛇小游戲\frmMain.Designer.cs
?????文件????????6210??2018-12-12?16:36??貪吃蛇小游戲\frmMain.resx
?????目錄???????????0??2018-12-11?16:49??貪吃蛇小游戲\obj\
?????目錄???????????0??2018-12-12?16:39??貪吃蛇小游戲\obj\Debug\
?????文件????????1452??2018-12-12?14:28??貪吃蛇小游戲\obj\Debug\DesignTimeResolveAssemblyReferences.cache
?????文件????????6878??2018-12-11?17:20??貪吃蛇小游戲\obj\Debug\DesignTimeResolveAssemblyReferencesInput.cache
?????目錄???????????0??2018-12-11?16:49??貪吃蛇小游戲\obj\Debug\TempPE\
?????文件?????????648??2018-12-12?16:39??貪吃蛇小游戲\obj\Debug\貪吃蛇小游戲.csproj.FileListAbsolute.txt
?????文件????????1014??2018-12-12?16:39??貪吃蛇小游戲\obj\Debug\貪吃蛇小游戲.csproj.GenerateResource.Cache
?????文件???????16896??2018-12-12?16:39??貪吃蛇小游戲\obj\Debug\貪吃蛇小游戲.exe
?????文件?????????180??2018-12-12?16:39??貪吃蛇小游戲\obj\Debug\貪吃蛇小游戲.frmMain.resources
?????文件???????34304??2018-12-12?16:39??貪吃蛇小游戲\obj\Debug\貪吃蛇小游戲.pdb
?????文件?????????180??2018-12-12?16:39??貪吃蛇小游戲\obj\Debug\貪吃蛇小游戲.Properties.Resources.resources
?????文件?????????501??2018-12-11?17:03??貪吃蛇小游戲\Program.cs
?????目錄???????????0??2018-12-11?16:49??貪吃蛇小游戲\Properties\
?????文件????????1362??2018-12-11?16:49??貪吃蛇小游戲\Properties\AssemblyInfo.cs
?????文件????????2849??2018-12-11?16:49??貪吃蛇小游戲\Properties\Resources.Designer.cs
?????文件????????5612??2018-12-11?16:49??貪吃蛇小游戲\Properties\Resources.resx
?????文件????????1105??2018-12-11?16:49??貪吃蛇小游戲\Properties\Settings.Designer.cs
?????文件?????????249??2018-12-11?16:49??貪吃蛇小游戲\Properties\Settings.settings
?????文件????????9048??2018-12-12?16:33??貪吃蛇小游戲\SnakeGame.cs
?????文件????????3800??2018-12-11?17:42??貪吃蛇小游戲\貪吃蛇小游戲.csproj
............此處省略0個文件信息
評論
共有 條評論