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