• 大小: 0.06M
    文件类型: .zip
    金币: 1
    下载: 0 次
    发布日期: 2024-05-02
  • 语言: C#
  • 标签: 贪吃蛇  

资源简介

贪吃蛇

资源截图

代码片段和文件信息

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 Form1 : Form
    {
        public Form1()
        {
            InitializeComponent();
        }

        public static bool ifStart = false;//判断是否开始
        public static int career = 400;//移动的速度
        Snake snake = new Snake();//实例化Snake类
        int snake_W = 20;//骨节的宽度
        int snake_H = 20;//骨节的高度
        public static bool pause = false;//是否暂停游戏

        /// 
        /// 绘制游戏场景
        /// 

        /// 封装一个GDI+绘图图面
        public void ProtractTable(Graphics g)
        {
            for (int i = 0; i <= panel1.Width / snake_W; i++)//绘制单元格的纵向线
            {
                g.DrawLine(new Pen(Color.Black 1) new Point(i * snake_W 0) new Point(i * snake_W panel1.Height));
            }
            for (int i = 0; i <= panel1.Height / snake_H; i++)//绘制单元格的横向线
            {
                g.DrawLine(new Pen(Color.Black 1) new Point(0 i * snake_H) new Point(panel1.Width i * snake_H));
            }
        }

        private void panel1_Paint(object sender PaintEventArgs e)
        {
            Graphics g = panel1.CreateGraphics();//创建panel1控件的Graphics类
            ProtractTable(g);//绘制游戏场景
            if (!ifStart)//如是没有开始游戏
            {
                Snake.timer = timer1;
                Snake.label = label2;
                snake.Ophidian(panel1 snake_W);//初始化场地及贪吃蛇信息
            }
            else
            {
                for (int i = 0; i < Snake.List.Count; i++)//绘制蛇身
                {
                    e.Graphics.FillRectangle(Snake.SolidB ((Point)Snake.List[i]).X + 1 ((Point)Snake.List[i]).Y + 1 snake_W - 1 snake_H - 1);
                }
                e.Graphics.FillRectangle(Snake.SolidF Snake.Food.X + 1 Snake.Food.Y + 1 snake_W - 1 snake_H - 1);//绘制食物
                if (Snake.ifGame)//如果游戏结束
                    //绘制提示文本
                    e.Graphics.DrawString(“Game Over“ new Font(“宋体“ 30 Fontstyle.Bold) new SolidBrush(Color.DarkSlateGray) new PointF(150 130));
            }
        }

        private void 开始ToolStripMenuItem_Click(object sender EventArgs e)
        {
            NoviceCortrol(Convert.ToInt32(((ToolStripMenuItem)sender).Tag.ToString()));
            snake.BuildFood();
            textBox1.Focus();
        }

        /// 
        /// 控制游戏的开始、暂停和结束
        /// 

        /// 标识
        public void NoviceCortrol(int n)
        {
            switch (n)
            {
                case 1://开始游戏
                    {
                        ifStart = false;
                        Graphics g = panel1.CreateGraphics();//创建panel1控件的Graphics类
                        g.FillRectangle(Snake.Soli

 属性            大小     日期    时间   名称
----------- ---------  ---------- -----  ----
     目录           0  2013-07-13 16:32  贪吃蛇\
     目录           0  2013-07-13 16:32  贪吃蛇\贪吃蛇\
     文件         917  2008-12-25 08:54  贪吃蛇\贪吃蛇.sln
     文件       14848  2009-01-14 16:17  贪吃蛇\贪吃蛇.suo
     目录           0  2012-05-02 09:58  贪吃蛇\贪吃蛇\bin\
     目录           0  2013-07-13 16:32  贪吃蛇\贪吃蛇\bin\Debug\
     文件       16384  2009-01-13 14:24  贪吃蛇\贪吃蛇\bin\Debug\贪吃蛇.exe
     文件       32256  2009-01-13 14:24  贪吃蛇\贪吃蛇\bin\Debug\贪吃蛇.pdb
     文件       14328  2009-01-14 11:24  贪吃蛇\贪吃蛇\bin\Debug\贪吃蛇.vshost.exe
     文件         490  2007-07-21 01:33  贪吃蛇\贪吃蛇\bin\Debug\贪吃蛇.vshost.exe.manifest
     文件        7889  2009-01-13 14:24  贪吃蛇\贪吃蛇\Form1.cs
     文件       10290  2008-12-26 09:04  贪吃蛇\贪吃蛇\Form1.Designer.cs
     文件        6207  2008-12-26 09:04  贪吃蛇\贪吃蛇\Form1.resx
     目录           0  2012-05-02 09:58  贪吃蛇\贪吃蛇\obj\
     目录           0  2013-07-13 16:32  贪吃蛇\贪吃蛇\obj\Debug\
     目录           0  2013-07-14 18:09  贪吃蛇\贪吃蛇\obj\Debug\Refactor\
     目录           0  2013-07-14 18:09  贪吃蛇\贪吃蛇\obj\Debug\TempPE\
     文件         882  2009-01-14 11:24  贪吃蛇\贪吃蛇\obj\Debug\贪吃蛇.csproj.FileListAbsolute.txt
     文件         847  2009-01-13 14:24  贪吃蛇\贪吃蛇\obj\Debug\贪吃蛇.csproj.GenerateResource.Cache
     文件       16384  2009-01-13 14:24  贪吃蛇\贪吃蛇\obj\Debug\贪吃蛇.exe
     文件         180  2009-01-13 14:24  贪吃蛇\贪吃蛇\obj\Debug\贪吃蛇.Form1.resources
     文件       32256  2009-01-13 14:24  贪吃蛇\贪吃蛇\obj\Debug\贪吃蛇.pdb
     文件         180  2009-01-13 14:24  贪吃蛇\贪吃蛇\obj\Debug\贪吃蛇.Properties.Resources.resources
     文件         490  2008-12-25 08:53  贪吃蛇\贪吃蛇\Program.cs
     目录           0  2013-07-13 16:32  贪吃蛇\贪吃蛇\Properties\
     文件        1350  2010-08-18 17:51  贪吃蛇\贪吃蛇\Properties\AssemblyInfo.cs
     文件        2868  2008-12-25 08:53  贪吃蛇\贪吃蛇\Properties\Resources.Designer.cs
     文件        5612  2008-12-25 08:53  贪吃蛇\贪吃蛇\Properties\Resources.resx
     文件        1094  2008-12-25 08:53  贪吃蛇\贪吃蛇\Properties\Settings.Designer.cs
     文件         249  2008-12-25 08:53  贪吃蛇\贪吃蛇\Properties\Settings.settings
     文件        9638  2009-01-13 11:45  贪吃蛇\贪吃蛇\Snake.cs
............此处省略1个文件信息

评论

共有 条评论