没有合适的资源?快使用搜索试试~ 我知道了~
c# 小游戏代码
3星 · 超过75%的资源 需积分: 35 9 下载量 27 浏览量
2011-09-23
11:15:20
上传
评论 2
收藏 7KB TXT 举报
温馨提示
试读
8页
适合初学者哦,赶紧过来看看吧,做任务中,怎么还还差几个字呢
资源推荐
资源详情
资源评论
using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Text;
using System.Windows.Forms;
using System.Collections;
namespace WindowsApplication1
{
public partial class Form1 : Form
{
public Form1()
{
InitializeComponent();
}
private bool i;//开关
snake a_snake = new snake(5);//实例化个长度为5的蛇
food afood = new food();//实例化一个食物
private void pictureBox1_Paint(object sender, PaintEventArgs e)
{
Graphics g = e.Graphics;
if (i)//点击了开始button
{
a_snake.drawsnake(g);//画出蛇
afood.drawfood(g);//画出来食物
}
if (a_snake.deadsnake())//如果蛇死亡事件为真
{
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Text;
using System.Windows.Forms;
using System.Collections;
namespace WindowsApplication1
{
public partial class Form1 : Form
{
public Form1()
{
InitializeComponent();
}
private bool i;//开关
snake a_snake = new snake(5);//实例化个长度为5的蛇
food afood = new food();//实例化一个食物
private void pictureBox1_Paint(object sender, PaintEventArgs e)
{
Graphics g = e.Graphics;
if (i)//点击了开始button
{
a_snake.drawsnake(g);//画出蛇
afood.drawfood(g);//画出来食物
}
if (a_snake.deadsnake())//如果蛇死亡事件为真
{
timer1.Enabled = false;//timer控件停止
if (DialogResult.Yes ==
MessageBox.Show("GAME OVER", "是否重新开始?", MessageBoxButtons.YesNo))
//messagebox消息
{
//点击确定后重新开始游戏
button1.Enabled = true;
a_snake = new snake(5);//初始化蛇
afood = new food();//初始化食物
i = false;//开关为假
g.Clear(pictureBox1.BackColor);//清理picturebox
}
else
Application.Exit();//关闭程序
}
}
private void button1_Click(object sender, EventArgs e)
{
i = true; //开关为真
afood.F_point = afood.getpoint();//产生一个食物的随机坐标
pictureBox1.Refresh();//刷新picturebox
timer1.Enabled = true;//开启timer控件
timer1.Interval = 100; //时间间隔为0.1秒
button1.Enabled = false;
}
private void timer1_Tick(object sender, EventArgs e)
{
pictureBox1.Refresh();//刷新picturebox
a_snake.extendsnake();//蛇伸长一节
if (a_snake.headpoint == afood.F_point)
if (DialogResult.Yes ==
MessageBox.Show("GAME OVER", "是否重新开始?", MessageBoxButtons.YesNo))
//messagebox消息
{
//点击确定后重新开始游戏
button1.Enabled = true;
a_snake = new snake(5);//初始化蛇
afood = new food();//初始化食物
i = false;//开关为假
g.Clear(pictureBox1.BackColor);//清理picturebox
}
else
Application.Exit();//关闭程序
}
}
private void button1_Click(object sender, EventArgs e)
{
i = true; //开关为真
afood.F_point = afood.getpoint();//产生一个食物的随机坐标
pictureBox1.Refresh();//刷新picturebox
timer1.Enabled = true;//开启timer控件
timer1.Interval = 100; //时间间隔为0.1秒
button1.Enabled = false;
}
private void timer1_Tick(object sender, EventArgs e)
{
pictureBox1.Refresh();//刷新picturebox
a_snake.extendsnake();//蛇伸长一节
if (a_snake.headpoint == afood.F_point)
剩余7页未读,继续阅读
资源评论
- 坚_持2012-10-27资源还不错,值得参考
ition1
- 粉丝: 0
- 资源: 1
上传资源 快速赚钱
- 我的内容管理 展开
- 我的资源 快来上传第一个资源
- 我的收益 登录查看自己的收益
- 我的积分 登录查看自己的积分
- 我的C币 登录后查看C币余额
- 我的收藏
- 我的下载
- 下载帮助
安全验证
文档复制为VIP权益,开通VIP直接复制
信息提交成功