C#程序员 谁有C#游戏贪食蛇和俄罗斯方块视频呀,还有源码,本人初来咋到希望在以后的交流中大家多多指点,还请各位高手多多帮忙呀! 解决方案 » 免费领取超大流量手机卡,每月29元包185G流量+100分钟通话, 中国电信官方发货 http://download.csdn.net/source/1857640:俄罗斯方块源代码(C#)http://download.csdn.net/source/274539:贪食蛇源代码(C#)希望对LZ有帮助 呵呵,在网上一搜,一堆,CSDN中就有 51aspx上有。上面的源码还是比较全的。可以随便下。不用积分啥的。 csdn.download 51aspx,都是非常不错的代码下载网站 http://d.download.csdn.net/down/1857640/mamiaoquanhttp://d.download.csdn.net/down/274539/youbl打开这两个网址直接下载源码 呵呵 我要分啊。。 我有贪吃蛇的 测试过可以的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())//如果蛇死亡事件为真 { 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) afood.F_point = afood.getpoint();//蛇头坐标与食物相同 //就只伸长 else a_snake.contractsnake();//没吃到食物就缩短一节 } private void Form1_KeyDown(object sender, KeyEventArgs e) { if (e.KeyCode == Keys.W && a_snake.Way != 2) { a_snake.Way = 0; } if (e.KeyCode == Keys.D && a_snake.Way != 3) { a_snake.Way = 1; } if (e.KeyCode == Keys.S && a_snake.Way != 0) { a_snake.Way = 2; } if (e.KeyCode == Keys.A && a_snake.Way != 1) { a_snake.Way = 3; } //设置KeyDown事件,用按件控制方向 } } public class segment//[一节蛇]类 { private int number;//私有成员 public int Number//[一节蛇]的编号 { get { return number; } set { number = value; } } private Point orign; public Point Orign//[一节蛇]的坐标 { get { return orign; } set { orign = value; } } public void drawpart(Graphics g)//画[一节蛇] { Pen p = new Pen(Color.Red); g.DrawEllipse(p, orign.X, orign.Y, 10, 10); //画红色圆圈代表一节蛇 } } public class snake//蛇类 { ArrayList alist;//定义一个先进先出的数据表 public Point headpoint;//蛇头坐标 private int way = 1;//初始方向为右 public int Way { get { return way; } set { way = value; } } public snake(int count)//蛇的构造函数 { segment apart; Point apoint = new Point(30, 30);//初始位置 alist = new ArrayList(count);//初始化数据表 for (int i = 1; i <= count; i++) { apoint.X = apoint.X + 10; apart = new segment(); apart.Number = i; apart.Orign = apoint; alist.Add(apart);//将没节蛇存在表里面 if (i == count)//将最后的一节蛇定为蛇头 headpoint = apoint; } } public void drawsnake(Graphics g)//画蛇 { for (int i = 0; i < alist.Count; i++) { segment seg = (segment)alist[i]; seg.drawpart(g); } } public void extendsnake()//伸长一节蛇 { segment seg = new segment(); seg.Number = alist.Count + 1; Point p; if (way == 0) p = new Point(headpoint.X, headpoint.Y - 10); else if (way == 2) p = new Point(headpoint.X, headpoint.Y + 10); else if (way == 3) p = new Point(headpoint.X - 10, headpoint.Y); else p = new Point(headpoint.X + 10, headpoint.Y); seg.Orign = p; alist.Add(seg);//将新的一节蛇添加到表尾 headpoint = seg.Orign;//重新设蛇头 } public void contractsnake()//蛇缩短一节 { alist.Remove(alist[0]);//删除表的第一个元素 } public bool deadsnake()//射死亡事件 { if (headpoint.X < 0 || headpoint.Y < 0 || headpoint.X > 350 || headpoint.Y > 270) //判断是否撞墙了 return true; for (int i = 0; i < alist.Count - 1; i++) { segment seg = (segment)alist[i]; if (seg.Orign == headpoint)//判断是否咬到自己 return true; } return false; } } public class food//食物类 { private Point f_point; public Point F_point//食物的坐标 { get { return f_point; } set { f_point = value; } } public void drawfood(Graphics g)//画食物 { SolidBrush b = new SolidBrush(Color.Blue); Rectangle rtg = new Rectangle(f_point.X, f_point.Y, 10, 10); g.FillRectangle(b, rtg); //实心的蓝色方块 } public Point getpoint()//获得食物坐标[随机数point] { int i = 10; Random rdm = new Random(System.DateTime.Now.Millisecond + i); i = rdm.Next(0, 27); int j = rdm.Next(0, 27); Point newp = new Point(i * 10, j * 10); return newp; } }} C# winform后台每隔一段时间数据提交,导致界面假死,需要使用线程,以前没用过,用异步的还是怎么弄,求解啊 inkcanvas中画笔的问题? 这样写也是数组吗? treeview生成 托盘程序闪动图标问题! 如何控制另一个窗口的treeview? 散尽家财90分,求C#发送邮件的方案 为什么继承IDisposable会出错?? 怎樣加總 DataGrid 中的某一個 column? 求一个BS结构的工作流引擎 winform实现窗体靠右边隐藏 C#高手请进
http://download.csdn.net/source/274539:贪食蛇源代码(C#)
希望对LZ有帮助
http://d.download.csdn.net/down/274539/youbl打开这两个网址直接下载源码 呵呵 我要分啊。。
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)
afood.F_point = afood.getpoint();//蛇头坐标与食物相同
//就只伸长
else
a_snake.contractsnake();//没吃到食物就缩短一节
}
private void Form1_KeyDown(object sender, KeyEventArgs e)
{
if (e.KeyCode == Keys.W && a_snake.Way != 2)
{
a_snake.Way = 0;
}
if (e.KeyCode == Keys.D && a_snake.Way != 3)
{
a_snake.Way = 1;
}
if (e.KeyCode == Keys.S && a_snake.Way != 0)
{
a_snake.Way = 2;
}
if (e.KeyCode == Keys.A && a_snake.Way != 1)
{
a_snake.Way = 3;
}
//设置KeyDown事件,用按件控制方向
}
}
public class segment//[一节蛇]类
{
private int number;//私有成员
public int Number//[一节蛇]的编号
{
get
{
return number;
}
set
{
number = value;
}
}
private Point orign;
public Point Orign//[一节蛇]的坐标
{
get
{
return orign;
}
set
{
orign = value;
}
}
public void drawpart(Graphics g)//画[一节蛇]
{
Pen p = new Pen(Color.Red);
g.DrawEllipse(p, orign.X, orign.Y, 10, 10);
//画红色圆圈代表一节蛇
}
}
public class snake//蛇类
{
ArrayList alist;//定义一个先进先出的数据表
public Point headpoint;//蛇头坐标
private int way = 1;//初始方向为右
public int Way
{
get
{
return way;
}
set
{
way = value;
}
}
public snake(int count)//蛇的构造函数
{
segment apart;
Point apoint = new Point(30, 30);//初始位置
alist = new ArrayList(count);//初始化数据表
for (int i = 1; i <= count; i++)
{
apoint.X = apoint.X + 10;
apart = new segment();
apart.Number = i;
apart.Orign = apoint;
alist.Add(apart);//将没节蛇存在表里面
if (i == count)//将最后的一节蛇定为蛇头
headpoint = apoint;
}
}
public void drawsnake(Graphics g)//画蛇
{
for (int i = 0; i < alist.Count; i++)
{
segment seg = (segment)alist[i];
seg.drawpart(g);
}
}
public void extendsnake()//伸长一节蛇
{
segment seg = new segment();
seg.Number = alist.Count + 1;
Point p;
if (way == 0)
p = new Point(headpoint.X, headpoint.Y - 10);
else if (way == 2)
p = new Point(headpoint.X, headpoint.Y + 10);
else if (way == 3)
p = new Point(headpoint.X - 10, headpoint.Y);
else
p = new Point(headpoint.X + 10, headpoint.Y);
seg.Orign = p;
alist.Add(seg);//将新的一节蛇添加到表尾
headpoint = seg.Orign;//重新设蛇头
}
public void contractsnake()//蛇缩短一节
{
alist.Remove(alist[0]);//删除表的第一个元素
}
public bool deadsnake()//射死亡事件
{
if (headpoint.X < 0 || headpoint.Y < 0 || headpoint.X > 350 || headpoint.Y > 270)
//判断是否撞墙了
return true;
for (int i = 0; i < alist.Count - 1; i++)
{
segment seg = (segment)alist[i];
if (seg.Orign == headpoint)//判断是否咬到自己
return true;
}
return false;
}
}
public class food//食物类
{
private Point f_point;
public Point F_point//食物的坐标
{
get
{
return f_point;
}
set
{
f_point = value;
}
}
public void drawfood(Graphics g)//画食物
{
SolidBrush b = new SolidBrush(Color.Blue);
Rectangle rtg = new Rectangle(f_point.X, f_point.Y, 10, 10);
g.FillRectangle(b, rtg);
//实心的蓝色方块
}
public Point getpoint()//获得食物坐标[随机数point]
{
int i = 10;
Random rdm = new Random(System.DateTime.Now.Millisecond + i);
i = rdm.Next(0, 27);
int j = rdm.Next(0, 27);
Point newp = new Point(i * 10, j * 10);
return newp;
}
}
}