首页 > 编程语言 >C#贪吃蛇小游戏源码

C#贪吃蛇小游戏源码

时间:2024-06-19 21:31:36浏览次数:14  
标签:f1 score C# System CreateGraphics 小游戏 using 源码 sender

using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using System.Windows.Forms;

namespace 贪吃蛇游戏
{
    
    public partial class Start : Form
    {
        private Floor f1;
        //Bean b1;
        //Block block;
        Snake s1;
        public Start()
        {
            InitializeComponent();
        }

        private void button1_Click(object sender, EventArgs e)
        {
            // b1 = new Bean();
            //b1.Origin = new Point(50, 50);
            //b1.Display(this.CreateGraphics());

            //block = new Block();
            //block.IsHead = false;
            //block.Origin = new Point(100, 100);
            //block.Display(this.CreateGraphics());

            Point p1 = new Point(50, 50);
            s1 = new Snake(p1, 10);
            //s1.Display(this.CreateGraphics());
            timer1.Enabled=true;
            button1.Enabled = false;
            button2.Enabled = false;
        }

        private void button2_Click(object sender, EventArgs e)
        {
            
            s1.UnDisplay(this.CreateGraphics());
        }

        private void timer1_Tick(object sender, EventArgs e)
        {
            f1.Display(this.CreateGraphics());
            lblScore.Text = f1.score.ToString();
            if (f1.score >= 100 && f1.score < 200)
            { 
            入门ToolStripMenuItem_Click(sender, e);
            }
           else if (f1.score >= 200 && f1.score < 300)
            {
                高手ToolStripMenuItem_Click( sender, e);
            }
            else if (f1.score >=300)
            {
                大神ToolStripMenuItem_Click(sender, e);
            }
            if (f1.score >= 550)
            {
                this.timer1.Enabled = false;//结束游戏
                MessageBox.Show("恭喜你通关了");
            }
            if (f1.CheckSnake())
            {
                timer1.Enabled = false;
                MessageBox.Show("GameOver");
            }
        }

        private void Form1_KeyDown(object sender, KeyEventArgs e)
        {
            f1.Display(this.CreateGraphics());
            if (f1.CheckSnake())
            {
                timer1.Enabled = false;
                MessageBox.Show("游戏已经结束");
            }
            int k, d = 0;
            k = e.KeyValue;
            if (k == 37)
                d = 3;
            else if (k == 40)
                d = 2;
            else if (k == 38)
                d = 0;
            else if (k == 39)
                d = 1;
            f1.S.TurnDirection(d);
           
        }

        private void 暂停F2ToolStripMenuItem_Cl

标签:f1,score,C#,System,CreateGraphics,小游戏,using,源码,sender
From: https://blog.csdn.net/2402_83809362/article/details/139813267

相关文章

  • CSS(4)盒子模型
    盒子模型(CSS重点)其实,CSS就三个大模块:盒子模型、浮动、定位,其余的都是细节。要求这三部分,无论如何也要学的非常精通。1.看透网页布局的本质网页布局中,我们是如何把里面的文字,图片,按照美工给我们的效果图排列的整齐有序呢?看透网页布局的本质:把网页元素比如文字图片等......
  • 《我的世界》HMCL下载
     首先,先确定你想下载的版本。如果你想下载Java的话,你就可以继续往下看了。    先在浏览器上搜: HMCL 找到上面这个界面向下,一直看到“下载HelloMinecraftLauncher” 看到后点击它。选择你想下载的版本即可。[注意电脑的品牌]          ......
  • colmap重建 指定内参和自动去畸变
     run.sh1指定内参--ImageReader.camera_params"1451.7946523730436,1438.2609968095967,960,540,0,0,0,0"\#!/bin/bashcalibDataRoot="/home/xx/2project/0data/house3/100/colmap100ori_and_100render/res/"imagePath="/home/xx/2project/0da......
  • vue3的computed计算属性返回值注解
    //语法结构:computed<返回值的类型>()列子//定义数据constcuont=ref(0)typeItem={id:stringname:stringprice:number}constlist=ref<Item[]>([{id:'1001',name:'男鞋',price:888},{id:'1002',name:'女鞋......
  • npm ERR! network request to https://registry.npmmirror.com/create-vite failed,
    npmERR!networkrequesttohttps://registry.npmmirror.com/create-vitefailed,  npmverbnpmv9.5.1npmERR!codeETIMEDOUTnpmERR!syscallconnectnpmERR!errnoETIMEDOUTnpmERR!networkrequesttohttps://registry.npmmirror.com/create-vitefailed,reas......
  • 【JavaScript脚本宇宙】终极对决:JavaScript表单库比较指南
    简化你的表单开发:六种流行JavaScript库的深入比较前言在现代网页开发中,表单处理是一个常见的任务。为了简化这个过程并提供更好的用户体验,许多开发人员使用JavaScript库来管理表单数据、验证和提交。本文将介绍六种流行的JavaScript表单库,它们具有不同的功能和适用场景。......
  • C++ Windows Hook使用
    GitHub-microsoft/Detours:DetoursisasoftwarepackageformonitoringandinstrumentingAPIcallsonWindows.Itisdistributedinsourcecodeform./*挂载钩子setdll/d:C:\Users\g\source\repos\LotTest\Release\lotDll.dllC:\Users\g\source\repo......
  • 【漏洞复现】Zyxel NAS设备 setCookie 未授权命令注入漏洞(CVE-2024-29973)
    0x01产品简介Zyxel-NAS是指由ZyxelCommunicationsCorporation(合勤科技股份有限公司)开发和生产的网络附加存储(NetworkAttachedStorage,简称NAS)设备。NAS是一种专门用于存储和共享文件的设备,它通过网络连接到计算机、服务器或其他设备,提供集中式的文件存储和访问功能......
  • 基于SpringBoot+Vue+uniapp的社区门诊管理系统的详细设计和实现(源码+lw+部署文档+讲
    文章目录前言详细视频演示具体实现截图技术栈后端框架SpringBoot前端框架Vue持久层框架MyBaitsPlus系统测试系统测试目的系统功能测试系统测试结论为什么选择我代码参考数据库参考源码获取前言......
  • 基于SpringBoot+Vue+uniapp的校园二手交易平台的详细设计和实现(源码+lw+部署文档+讲
    文章目录前言详细视频演示具体实现截图技术栈后端框架SpringBoot前端框架Vue持久层框架MyBaitsPlus系统测试系统测试目的系统功能测试系统测试结论为什么选择我代码参考数据库参考源码获取前言......