基本信息
源码名称:C#开发的贪吃蛇游戏 完整源码实例下载
源码大小:2.16M
文件格式:.RAR
开发语言:C#
更新时间:2013-01-09
友情提示:(无需注册或充值,赞助后即可获取资源下载链接)
嘿,亲!知识可是无价之宝呢,但咱这精心整理的资料也耗费了不少心血呀。小小地破费一下,绝对物超所值哦!如有下载和支付问题,请联系我们QQ(微信同号):813200300
本次赞助数额为: 2 元×
微信扫码支付:2 元
×
请留下您的邮箱,我们将在2小时内将文件发到您的邮箱
源码介绍
用C#开发的最经典的贪吃蛇游戏源码
public partial class Frm_GameZone : Form { private Snake mySnake = new Snake(); private bool isnew = true; private bool gameover = false; public Frm_GameZone() { InitializeComponent(); } private void Frm_GameZone_Load(object sender, EventArgs e) { GameZone.Width = 25; GameZone.Height = 21; GameZone.winHandle = pictureBox1.Handle; } protected override bool ProcessDialogKey(Keys keyData) { switch (keyData) { case Keys.Up: if (mySnake.snk_movedirect == Snake.movedirect.DOWN || gameover) break; mySnake.snk_movedirect = Snake.movedirect.Up; if (!mySnake.move()) GameOver(); break; case Keys.Left: if (mySnake.snk_movedirect == Snake.movedirect.RIGHT || gameover) break; mySnake.snk_movedirect = Snake.movedirect.LEFT; if (!mySnake.move()) GameOver(); break; case Keys.Down: if (mySnake.snk_movedirect == Snake.movedirect.Up || gameover) break; mySnake.snk_movedirect = Snake.movedirect.DOWN; if (!mySnake.move()) GameOver(); break; case Keys.Right: if (mySnake.snk_movedirect == Snake.movedirect.LEFT || gameover) break; mySnake.snk_movedirect = Snake.movedirect.RIGHT; if (!mySnake.move()) GameOver(); break; } if (keyData == Keys.Up || keyData == Keys.Down || keyData == Keys.Left || keyData == Keys.Right) return false; else return base.ProcessDialogKey(keyData); } public void GameOver() { timer1.Stop(); timer2.Stop(); isnew = true; gameover = true; pictureBox1.BackgroundImage = linxfeng.Properties.Resources.gameover; pictureBox1.Refresh(); } private void timer2_Tick(object sender, EventArgs e) { if (GameZone.foodVisible) { GameZone.food.Erase(GameZone.winHandle); } else { GameZone.food.Draw(GameZone.winHandle); } GameZone.foodVisible = !GameZone.foodVisible; } private void timer1_Tick(object sender, EventArgs e) { if (!mySnake.move()) { GameOver(); btn_start.Enabled = true; button2.Enabled = false; groupBox1.Enabled = true; } label2.Text = ((mySnake.snake.Count) * (mySnake.snake.Count (40 - timer1.Interval / 10))).ToString(); } private void rb_ease_CheckedChanged(object sender, EventArgs e) { if (rb_ease.Checked) timer1.Interval = 350; } private void btn_start_Click(object sender, EventArgs e) { if (isnew) { pictureBox1.BackgroundImage = Resources.gameback; pictureBox1.Refresh(); mySnake = new Snake(); mySnake.Draw(GameZone.winHandle); gameover = false; GameZone.createFood(mySnake); GameZone.foodVisible = true; } btn_start.Enabled = false; button2.Enabled = true; timer1.Start(); timer2.Start(); groupBox1.Enabled = false; } private void button4_Click(object sender, EventArgs e) { this.Close(); System.Diagnostics.Process.Start("iexplore.exe", "http://nj.fenlei168.com"); } private void rb_middle_CheckedChanged(object sender, EventArgs e) { if (rb_middle.Checked) timer1.Interval = 250; } private void rb_hard_CheckedChanged(object sender, EventArgs e) { if (rb_hard.Checked) timer1.Interval = 160; } private void radioButton1_CheckedChanged(object sender, EventArgs e) { if (radioButton1.Checked) timer1.Interval = 100; } private void button2_Click(object sender, EventArgs e) { if (button2.Text == "暂停(&P)") { timer1.Stop(); timer2.Stop(); button2.Text = "继续(&C)"; } else { timer1.Start(); timer2.Start(); button2.Text = "暂停(&P)"; } } private void button3_Click(object sender, EventArgs e) { AboutMe Frm_am = new AboutMe(); Frm_am.ShowDialog(); } }