├── README.md
├── .gitignore
├── GreedySnake
├── bin
│ └── Release
│ │ ├── GreedySnake.exe
│ │ ├── GreedySnake.pdb
│ │ ├── GreedySnake.vshost.exe
│ │ ├── GreedySnake.exe.config
│ │ ├── GreedySnake.vshost.exe.config
│ │ └── GreedySnake.vshost.exe.manifest
├── App.config
├── Properties
│ ├── Settings.settings
│ ├── AssemblyInfo.cs
│ ├── Settings.Designer.cs
│ ├── Resources.Designer.cs
│ └── Resources.resx
├── GreedySnake.csproj.user
├── Program.cs
├── Form1.Designer.cs
├── Form1.cs
├── GreedySnake.csproj
└── Form1.resx
└── GreedySnake.sln
/README.md:
--------------------------------------------------------------------------------
1 | #A simple greedy snake game
2 | Development environment: visual studio 2015 community version
--------------------------------------------------------------------------------
/.gitignore:
--------------------------------------------------------------------------------
1 | obj/
2 | /.vs
3 |
4 | # 去掉debug版本 留下发行版本
5 | [Dd]ebug/
6 | [Rr]elease/*
7 |
8 | # 去掉临时的文件
9 | *.TMP
10 | *.tmp
--------------------------------------------------------------------------------
/GreedySnake/bin/Release/GreedySnake.exe:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/CodFrm/GreedySnake/master/GreedySnake/bin/Release/GreedySnake.exe
--------------------------------------------------------------------------------
/GreedySnake/bin/Release/GreedySnake.pdb:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/CodFrm/GreedySnake/master/GreedySnake/bin/Release/GreedySnake.pdb
--------------------------------------------------------------------------------
/GreedySnake/bin/Release/GreedySnake.vshost.exe:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/CodFrm/GreedySnake/master/GreedySnake/bin/Release/GreedySnake.vshost.exe
--------------------------------------------------------------------------------
/GreedySnake/App.config:
--------------------------------------------------------------------------------
1 |
2 |
3 |
4 |
5 |
6 |
--------------------------------------------------------------------------------
/GreedySnake/bin/Release/GreedySnake.exe.config:
--------------------------------------------------------------------------------
1 |
2 |
3 |
4 |
5 |
6 |
--------------------------------------------------------------------------------
/GreedySnake/bin/Release/GreedySnake.vshost.exe.config:
--------------------------------------------------------------------------------
1 |
2 |
3 |
4 |
5 |
6 |
--------------------------------------------------------------------------------
/GreedySnake/Properties/Settings.settings:
--------------------------------------------------------------------------------
1 |
2 |
3 |
4 |
5 |
6 |
7 |
8 |
--------------------------------------------------------------------------------
/GreedySnake/GreedySnake.csproj.user:
--------------------------------------------------------------------------------
1 |
2 |
3 |
4 |
5 |
6 |
7 |
8 |
9 |
10 | zh-CN
11 | false
12 |
13 |
--------------------------------------------------------------------------------
/GreedySnake/bin/Release/GreedySnake.vshost.exe.manifest:
--------------------------------------------------------------------------------
1 |
2 |
3 |
4 |
5 |
6 |
7 |
8 |
9 |
10 |
11 |
12 |
--------------------------------------------------------------------------------
/GreedySnake/Program.cs:
--------------------------------------------------------------------------------
1 | using System;
2 | using System.Collections.Generic;
3 | using System.Linq;
4 | using System.Threading.Tasks;
5 | using System.Windows.Forms;
6 |
7 | namespace GreedySnake
8 | {
9 | static class Program
10 | {
11 | ///
12 | /// 应用程序的主入口点。
13 | ///
14 | [STAThread]
15 | static void Main()
16 | {
17 | Application.EnableVisualStyles();
18 | Application.SetCompatibleTextRenderingDefault(false);
19 | Application.Run(new GreedySnakeGameMainWindow());
20 | }
21 | }
22 | }
23 |
--------------------------------------------------------------------------------
/GreedySnake.sln:
--------------------------------------------------------------------------------
1 |
2 | Microsoft Visual Studio Solution File, Format Version 12.00
3 | # Visual Studio 14
4 | VisualStudioVersion = 14.0.25420.1
5 | MinimumVisualStudioVersion = 10.0.40219.1
6 | Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "GreedySnake", "GreedySnake\GreedySnake.csproj", "{D0DB842F-B566-495D-BEA1-6EFD469EDB3F}"
7 | EndProject
8 | Global
9 | GlobalSection(SolutionConfigurationPlatforms) = preSolution
10 | Debug|Any CPU = Debug|Any CPU
11 | Release|Any CPU = Release|Any CPU
12 | EndGlobalSection
13 | GlobalSection(ProjectConfigurationPlatforms) = postSolution
14 | {D0DB842F-B566-495D-BEA1-6EFD469EDB3F}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
15 | {D0DB842F-B566-495D-BEA1-6EFD469EDB3F}.Debug|Any CPU.Build.0 = Debug|Any CPU
16 | {D0DB842F-B566-495D-BEA1-6EFD469EDB3F}.Release|Any CPU.ActiveCfg = Release|Any CPU
17 | {D0DB842F-B566-495D-BEA1-6EFD469EDB3F}.Release|Any CPU.Build.0 = Release|Any CPU
18 | EndGlobalSection
19 | GlobalSection(SolutionProperties) = preSolution
20 | HideSolutionNode = FALSE
21 | EndGlobalSection
22 | EndGlobal
23 |
--------------------------------------------------------------------------------
/GreedySnake/Properties/AssemblyInfo.cs:
--------------------------------------------------------------------------------
1 | using System.Reflection;
2 | using System.Runtime.CompilerServices;
3 | using System.Runtime.InteropServices;
4 |
5 | // 有关程序集的一般信息由以下
6 | // 控制。更改这些特性值可修改
7 | // 与程序集关联的信息。
8 | [assembly: AssemblyTitle("GreedySnake")]
9 | [assembly: AssemblyDescription("")]
10 | [assembly: AssemblyConfiguration("")]
11 | [assembly: AssemblyCompany("")]
12 | [assembly: AssemblyProduct("GreedySnake")]
13 | [assembly: AssemblyCopyright("Copyright © 2017")]
14 | [assembly: AssemblyTrademark("")]
15 | [assembly: AssemblyCulture("")]
16 |
17 | //将 ComVisible 设置为 false 将使此程序集中的类型
18 | //对 COM 组件不可见。 如果需要从 COM 访问此程序集中的类型,
19 | //请将此类型的 ComVisible 特性设置为 true。
20 | [assembly: ComVisible(false)]
21 |
22 | // 如果此项目向 COM 公开,则下列 GUID 用于类型库的 ID
23 | [assembly: Guid("d0db842f-b566-495d-bea1-6efd469edb3f")]
24 |
25 | // 程序集的版本信息由下列四个值组成:
26 | //
27 | // 主版本
28 | // 次版本
29 | // 生成号
30 | // 修订号
31 | //
32 | //可以指定所有这些值,也可以使用“生成号”和“修订号”的默认值,
33 | // 方法是按如下所示使用“*”: :
34 | // [assembly: AssemblyVersion("1.0.*")]
35 | [assembly: AssemblyVersion("1.0.0.0")]
36 | [assembly: AssemblyFileVersion("1.0.0.0")]
37 |
--------------------------------------------------------------------------------
/GreedySnake/Properties/Settings.Designer.cs:
--------------------------------------------------------------------------------
1 | //------------------------------------------------------------------------------
2 | //
3 | // This code was generated by a tool.
4 | // Runtime Version:4.0.30319.42000
5 | //
6 | // Changes to this file may cause incorrect behavior and will be lost if
7 | // the code is regenerated.
8 | //
9 | //------------------------------------------------------------------------------
10 |
11 | namespace GreedySnake.Properties
12 | {
13 |
14 |
15 | [global::System.Runtime.CompilerServices.CompilerGeneratedAttribute()]
16 | [global::System.CodeDom.Compiler.GeneratedCodeAttribute("Microsoft.VisualStudio.Editors.SettingsDesigner.SettingsSingleFileGenerator", "11.0.0.0")]
17 | internal sealed partial class Settings : global::System.Configuration.ApplicationSettingsBase
18 | {
19 |
20 | private static Settings defaultInstance = ((Settings)(global::System.Configuration.ApplicationSettingsBase.Synchronized(new Settings())));
21 |
22 | public static Settings Default
23 | {
24 | get
25 | {
26 | return defaultInstance;
27 | }
28 | }
29 | }
30 | }
31 |
--------------------------------------------------------------------------------
/GreedySnake/Form1.Designer.cs:
--------------------------------------------------------------------------------
1 | namespace GreedySnake
2 | {
3 | partial class GreedySnakeGameMainWindow
4 | {
5 | ///
6 | /// 必需的设计器变量。
7 | ///
8 | private System.ComponentModel.IContainer components = null;
9 |
10 | ///
11 | /// 清理所有正在使用的资源。
12 | ///
13 | /// 如果应释放托管资源,为 true;否则为 false。
14 | protected override void Dispose(bool disposing)
15 | {
16 | if (disposing && (components != null))
17 | {
18 | components.Dispose();
19 | }
20 | base.Dispose(disposing);
21 | }
22 |
23 | #region Windows 窗体设计器生成的代码
24 |
25 | ///
26 | /// 设计器支持所需的方法 - 不要修改
27 | /// 使用代码编辑器修改此方法的内容。
28 | ///
29 | private void InitializeComponent()
30 | {
31 | this.components = new System.ComponentModel.Container();
32 | this.MoveSnake = new System.Windows.Forms.Timer(this.components);
33 | this.SuspendLayout();
34 | //
35 | // MoveSnake
36 | //
37 | this.MoveSnake.Interval = 500;
38 | this.MoveSnake.Tick += new System.EventHandler(this.MoveSnake_Tick);
39 | //
40 | // GreedySnakeGameMainWindow
41 | //
42 | this.AutoScaleDimensions = new System.Drawing.SizeF(8F, 15F);
43 | this.AutoScaleMode = System.Windows.Forms.AutoScaleMode.Font;
44 | this.BackColor = System.Drawing.SystemColors.Control;
45 | this.ClientSize = new System.Drawing.Size(820, 573);
46 | this.Name = "GreedySnakeGameMainWindow";
47 | this.Text = "Form1";
48 | this.Load += new System.EventHandler(this.GreedySnakeGameMainWindow_Load);
49 | this.Paint += new System.Windows.Forms.PaintEventHandler(this.GreedySnakeGameMainWindow_Paint);
50 | this.KeyDown += new System.Windows.Forms.KeyEventHandler(this.GreedySnakeGameMainWindow_KeyDown);
51 | this.ResumeLayout(false);
52 |
53 | }
54 |
55 | #endregion
56 |
57 | private System.Windows.Forms.Timer MoveSnake;
58 | }
59 | }
60 |
61 |
--------------------------------------------------------------------------------
/GreedySnake/Properties/Resources.Designer.cs:
--------------------------------------------------------------------------------
1 | //------------------------------------------------------------------------------
2 | //
3 | // 此代码由工具生成。
4 | // 运行时版本: 4.0.30319.42000
5 | //
6 | // 对此文件的更改可能导致不正确的行为,如果
7 | // 重新生成代码,则所做更改将丢失。
8 | //
9 | //------------------------------------------------------------------------------
10 |
11 | namespace GreedySnake.Properties
12 | {
13 |
14 |
15 | ///
16 | /// 强类型资源类,用于查找本地化字符串等。
17 | ///
18 | // 此类是由 StronglyTypedResourceBuilder
19 | // 类通过类似于 ResGen 或 Visual Studio 的工具自动生成的。
20 | // 若要添加或删除成员,请编辑 .ResX 文件,然后重新运行 ResGen
21 | // (以 /str 作为命令选项),或重新生成 VS 项目。
22 | [global::System.CodeDom.Compiler.GeneratedCodeAttribute("System.Resources.Tools.StronglyTypedResourceBuilder", "4.0.0.0")]
23 | [global::System.Diagnostics.DebuggerNonUserCodeAttribute()]
24 | [global::System.Runtime.CompilerServices.CompilerGeneratedAttribute()]
25 | internal class Resources
26 | {
27 |
28 | private static global::System.Resources.ResourceManager resourceMan;
29 |
30 | private static global::System.Globalization.CultureInfo resourceCulture;
31 |
32 | [global::System.Diagnostics.CodeAnalysis.SuppressMessageAttribute("Microsoft.Performance", "CA1811:AvoidUncalledPrivateCode")]
33 | internal Resources()
34 | {
35 | }
36 |
37 | ///
38 | /// 返回此类使用的缓存 ResourceManager 实例。
39 | ///
40 | [global::System.ComponentModel.EditorBrowsableAttribute(global::System.ComponentModel.EditorBrowsableState.Advanced)]
41 | internal static global::System.Resources.ResourceManager ResourceManager
42 | {
43 | get
44 | {
45 | if ((resourceMan == null))
46 | {
47 | global::System.Resources.ResourceManager temp = new global::System.Resources.ResourceManager("GreedySnake.Properties.Resources", typeof(Resources).Assembly);
48 | resourceMan = temp;
49 | }
50 | return resourceMan;
51 | }
52 | }
53 |
54 | ///
55 | /// 覆盖当前线程的 CurrentUICulture 属性
56 | /// 使用此强类型的资源类的资源查找。
57 | ///
58 | [global::System.ComponentModel.EditorBrowsableAttribute(global::System.ComponentModel.EditorBrowsableState.Advanced)]
59 | internal static global::System.Globalization.CultureInfo Culture
60 | {
61 | get
62 | {
63 | return resourceCulture;
64 | }
65 | set
66 | {
67 | resourceCulture = value;
68 | }
69 | }
70 | }
71 | }
72 |
--------------------------------------------------------------------------------
/GreedySnake/Form1.cs:
--------------------------------------------------------------------------------
1 | using System;
2 | using System.Collections.Generic;
3 | using System.ComponentModel;
4 | using System.Data;
5 | using System.Drawing;
6 | using System.Linq;
7 | using System.Text;
8 | using System.Threading.Tasks;
9 | using System.Windows.Forms;
10 | using System.Collections;
11 | namespace GreedySnake
12 | {
13 | public partial class GreedySnakeGameMainWindow : Form
14 | {
15 | public GreedySnakeGameMainWindow()
16 | {
17 | InitializeComponent();
18 | //提前画出子格,放入内存
19 | //格子数 10*10 宽高 30*30 边框 1 画布宽度 320*320
20 | //因为要10个格子,所以得画11条线,这个....一直没注意= =
21 | Graphics gdiLattice = Graphics.FromImage(bmpCanvas);
22 | gdiLattice.Clear(BackColor);
23 | for (int i = 0; i <= 10; i++)//画横线
24 | {
25 | gdiLattice.DrawLine(new Pen(Color.Red, 1), 0, i * 30, 300, i * 30);
26 | }
27 | for (int i = 0; i <= 10; i++)//画竖线
28 | {
29 | gdiLattice.DrawLine(new Pen(Color.Red, 1), i * 30, 0, i * 30, 300);
30 | }
31 | }
32 | Graphics gdiWindow;
33 | Bitmap bmpCanvas = new Bitmap(301, 301);//因为笔宽的原因所以画布宽为301
34 | private void GreedySnakeGameMainWindow_Paint(object sender, PaintEventArgs e)
35 | {
36 | //格子已经画出保存在内存中,所以可以直接画出
37 | gdiWindow.DrawImage(bmpCanvas, 30, 30);
38 |
39 | }
40 | public struct ObjectPos
41 | {
42 | public int x;
43 | public int y;
44 | };
45 | public ObjectPos posSnakeHead = new ObjectPos();
46 | public ArrayList posSnakeBody=new ArrayList();
47 | private void MoveSnake_Tick(object sender, EventArgs e)
48 | {
49 | DrawSnake();
50 | }
51 | //画出蛇
52 | private void DrawSnake()
53 | {
54 | Bitmap bmpSnake = new Bitmap(300, 300);
55 | //蛇头
56 | //posSnakeBody.Add(new ObjectPos());
57 | switch (nMoveDirection)
58 | {
59 | case 1:
60 | {
61 | posSnakeHead.x--;
62 | break;
63 | }
64 | case 2:
65 | {
66 | posSnakeHead.y--;
67 | break;
68 | }
69 | case 3:
70 | {
71 | posSnakeHead.x++;
72 | break;
73 | }
74 | case 4:
75 | {
76 | posSnakeHead.y++;
77 | break;
78 | }
79 | }
80 | Graphics gdiSnake = Graphics.FromImage(bmpSnake);
81 | gdiSnake.FillRectangle(new SolidBrush(Color.Blue), posSnakeHead.x * 30 + 1, posSnakeHead.y * 30 + 1, 29, 29);
82 | //蛇身
83 | gdiWindow.DrawImage(bmpCanvas, 30, 30);
84 | gdiWindow.DrawImage(bmpSnake, 30, 30);
85 | }
86 | private void GreedySnakeGameMainWindow_Load(object sender, EventArgs e)
87 | {
88 | gdiWindow = this.CreateGraphics();
89 | posSnakeHead.x = 0;
90 | posSnakeHead.y = 0;
91 | MoveSnake.Start();
92 | }
93 | int nMoveDirection=39;
94 | private void GreedySnakeGameMainWindow_KeyDown(object sender, KeyEventArgs e)
95 | {
96 | switch (e.KeyValue)
97 | {
98 | case 37:
99 | {
100 | nMoveDirection = 1;
101 | break;
102 | }
103 | case 38:
104 | {
105 | nMoveDirection = 2;
106 | break;
107 | }
108 | case 39:
109 | {
110 | nMoveDirection = 3;
111 | break;
112 | }
113 | case 40:
114 | {
115 | nMoveDirection = 4;
116 | break;
117 | }
118 | default:
119 | {
120 | break;
121 | }
122 | }
123 | //MessageBox.Show(e.KeyValue.ToString());
124 | //up 38
125 | //down 40
126 | //left 37
127 | //right 39
128 | }
129 | }
130 | }
131 |
--------------------------------------------------------------------------------
/GreedySnake/GreedySnake.csproj:
--------------------------------------------------------------------------------
1 |
2 |
3 |
4 |
5 | Debug
6 | AnyCPU
7 | {D0DB842F-B566-495D-BEA1-6EFD469EDB3F}
8 | WinExe
9 | Properties
10 | GreedySnake
11 | GreedySnake
12 | v4.5.2
13 | 512
14 | true
15 | publish\
16 | true
17 | Disk
18 | false
19 | Foreground
20 | 7
21 | Days
22 | false
23 | false
24 | true
25 | 0
26 | 1.0.0.%2a
27 | false
28 | false
29 | true
30 |
31 |
32 | AnyCPU
33 | true
34 | full
35 | false
36 | bin\Debug\
37 | DEBUG;TRACE
38 | prompt
39 | 4
40 |
41 |
42 | AnyCPU
43 | pdbonly
44 | true
45 | bin\Release\
46 | TRACE
47 | prompt
48 | 4
49 |
50 |
51 |
52 |
53 |
54 |
55 |
56 |
57 |
58 |
59 |
60 |
61 |
62 |
63 |
64 |
65 | Form
66 |
67 |
68 | Form1.cs
69 |
70 |
71 |
72 |
73 | Form1.cs
74 |
75 |
76 | ResXFileCodeGenerator
77 | Resources.Designer.cs
78 | Designer
79 |
80 |
81 | True
82 | Resources.resx
83 |
84 |
85 | SettingsSingleFileGenerator
86 | Settings.Designer.cs
87 |
88 |
89 | True
90 | Settings.settings
91 | True
92 |
93 |
94 |
95 |
96 |
97 |
98 |
99 | False
100 | Microsoft .NET Framework 4.5.2 %28x86 和 x64%29
101 | true
102 |
103 |
104 | False
105 | .NET Framework 3.5 SP1
106 | false
107 |
108 |
109 |
110 |
117 |
--------------------------------------------------------------------------------
/GreedySnake/Properties/Resources.resx:
--------------------------------------------------------------------------------
1 |
2 |
3 |
62 |
63 |
64 |
65 |
66 |
67 |
68 |
69 |
70 |
71 |
72 |
73 |
74 |
75 |
76 |
77 |
78 |
79 |
80 |
81 |
82 |
83 |
84 |
85 |
86 |
87 |
88 |
89 |
90 |
91 |
92 |
93 |
94 |
95 |
96 |
97 |
98 |
99 |
100 |
101 |
102 |
103 |
104 |
105 |
106 | text/microsoft-resx
107 |
108 |
109 | 2.0
110 |
111 |
112 | System.Resources.ResXResourceReader, System.Windows.Forms, Version=2.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089
113 |
114 |
115 | System.Resources.ResXResourceWriter, System.Windows.Forms, Version=2.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089
116 |
117 |
--------------------------------------------------------------------------------
/GreedySnake/Form1.resx:
--------------------------------------------------------------------------------
1 |
2 |
3 |
62 |
63 |
64 |
65 |
66 |
67 |
68 |
69 |
70 |
71 |
72 |
73 |
74 |
75 |
76 |
77 |
78 |
79 |
80 |
81 |
82 |
83 |
84 |
85 |
86 |
87 |
88 |
89 |
90 |
91 |
92 |
93 |
94 |
95 |
96 |
97 |
98 |
99 |
100 |
101 |
102 |
103 |
104 |
105 |
106 |
107 |
108 |
109 | text/microsoft-resx
110 |
111 |
112 | 2.0
113 |
114 |
115 | System.Resources.ResXResourceReader, System.Windows.Forms, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089
116 |
117 |
118 | System.Resources.ResXResourceWriter, System.Windows.Forms, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089
119 |
120 |
121 | 17, 17
122 |
123 |
--------------------------------------------------------------------------------