1. 求一个C#简单小游戏的源代码
http://www.51aspx.com/S/游戏.html
看看这里,51aspx免费的游戏源码,希望可以专帮助到楼主属哦!
2. 求用C#写的小游戏源码,比如(记忆翻牌,连连看,。。。。。)路过的大哥帮忙啊!
我有个代码
是用C#写的小游戏//
O(∩_∩)O哈哈~ 要嚒 我也是学习C#的哦!!!加精嘛 ,楼主~!~
3. c# 小游戏代码
贪吃蛇
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;
}
}
}
下一百层
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();
}
lift alift = new lift();//梯子实例化
people man = new people();//人物实例化
bool i;//开关
int j =1;//人物移动方向
private void pictureBox1_Paint(object sender, PaintEventArgs e)
{
Graphics g = e.Graphics;
if (i)
{
alift.drawlift(g);//画梯子
man.drawpeople(g);//画人物
}
if (man.mandead())//人物死亡为真
{
timer1.Enabled = false;
timer2.Enabled = false;
timer3.Enabled = false;
timer4.Enabled = false;
if (DialogResult.Yes ==
MessageBox.Show("Game Over", "重新开始游戏?", MessageBoxButtons.YesNo))
{ //重新开始游戏
button1.Enabled = true;
man.Footpoint = new Point(alift.downmost.X + 50, alift.downmost.Y - 20);
}
else
Application.Exit();//退出游戏
}
}
private void button1_Click(object sender, EventArgs e)
{
i = true;//打开开关
pictureBox1.Refresh();//刷新
timer1.Interval = 2;
timer1.Enabled = true;
timer3.Interval = 1;
timer3.Enabled = true;
man.Footpoint = new Point(alift.downmost.X + 50, alift.downmost.Y -20);
//初始化任务的坐标
button1.Enabled = false;//Button1被锁
}
private void timer1_Tick(object sender, EventArgs e)
{
alift.liftrise();//伸梯子
if (alift.downmost.Y <= 260)
alift.addstep();//加梯子
pictureBox1.Refresh();
}
private void Form1_KeyDown(object sender, KeyEventArgs e)
{
//用A控制向左,S控制向右
if (e.KeyCode == Keys.A)
{
timer2.Interval = 1;
timer2.Enabled = true;
j = 2;
}
if (e.KeyCode == Keys.S)
{
timer2.Interval = 1;
timer2.Enabled = true;
j = 3;
}
}
private void Form1_KeyUp(object sender, KeyEventArgs e)
{
//KeyUp事件控制人物左右移动的停止
if (e.KeyCode == Keys.A)
{
timer2.Enabled = false ;
j = 1;
}
if (e.KeyCode == Keys.S)
{
timer2.Enabled = false ;
j = 1;
}
}
private void timer2_Tick(object sender, EventArgs e)
{
if (j == 2)
man.moveleft();//人物向左移动
else if (j == 3)
man.moveright();//人物向右移动
}
private void timer3_Tick(object sender, EventArgs e)
{
man.movedown();//人物下落
if (alift.manland(man))
{
timer3.Enabled = false;
timer4.Interval = 2;
timer4.Enabled = true;
}
}
private void timer4_Tick(object sender, EventArgs e)
{
man.moverise();//人物随梯子上升
if (alift.manout(man))
{
timer3.Enabled = true;
timer4.Enabled = false;
}
}
}
public class step//台阶类是梯子的一个单位
{
private Point safep;//台阶的坐标
public Point Safep
{
get
{
return safep;
}
set
{
safep = value;
}
}
public void drawstep(Graphics g)//画台阶[实心长方形]
{
SolidBrush b = new SolidBrush(Color.DarkSlateBlue);
Rectangle rect = new Rectangle(safep.X, safep.Y, 100, 10);
g.FillRectangle(b, rect);
}
public int getpointx(int i)//台阶的随机X坐标
{
Random rdm = new Random(System.DateTime.Now.Millisecond+i);
return rdm.Next(0,240);
}
public Point risepoint()//新伸起来的台阶坐标
{
Random rdm = new Random(System.DateTime.Now.Millisecond*123456 );
int x= rdm.Next(0, 240);
Point p = new Point(x, 340);
return p;
}
}
public class lift//梯子类
{
public ArrayList alist = new ArrayList(5);//先进先出表
public Point downmost;//最下面台阶的坐标
public lift()//构造函数
{
step astep;
int x=1,y=10;
for (int i = 0; i < 5; i++)
{
astep = new step();
x = astep.getpointx(x);
astep = new step();
astep.Safep =new Point(x, y);
alist.Add(astep);
y = y + 80;
if (i == 4)
downmost = astep.Safep;
}
}
public void drawlift(Graphics g)//画梯子
{
for (int i=0;i<5;i++)
{
step astep=(step) alist[i];
astep.drawstep (g);
}
}
public void liftrise()//梯子上升
{
//表中的每个Y坐标加1
//并把新的台阶存在表的尾部
for (int i = 0; i < 5; i++)
{
step astep = (step)alist[i];
Point p = new Point(astep.Safep.X, astep.Safep.Y - 1);
astep.Safep = p;
alist.Add(astep);
if (i == 4)
downmost = astep.Safep;
}
for (int i = 0; i < 5; i++)//删除表的前5个数据
{
alist.Remove(alist[i]);
}
}
public void addstep()//伸起来的一节梯子
{
step astep=new step ();
astep.Safep=astep.risepoint();
alist.Add(astep);
alist.Remove(alist[0]);
downmost = astep.Safep; //始终保证最下面的一节为downmost
}
public bool manland(people man)//人物登陆事件
{
step s;
for (int a = 0; a < 5; a++)
{
s = (step)alist[a];
if (Math.Abs( s.Safep.Y -(man.Footpoint.Y+10))<2&&
s.Safep.X <= man.Footpoint.X+10 &&
man.Footpoint.X <= s.Safep.X + 100)
return true;
}
return false;
}
public bool manout(people man)//人物冲出事件
{
step s;
for (int a = 0; a < 5; a++)
{
s = (step)alist[a];
if (Math.Abs(s.Safep.Y - (man.Footpoint.Y + 10)) < 3)
{
if (s.Safep.X-10 > man.Footpoint.X ||
man.Footpoint.X > s.Safep.X + 100)
return true;
}
}
return false;
}
}
public class people//人物类
{
private Point footpoint;//人物的坐标
public Point Footpoint
{
get
{
return footpoint;
}
set
{
footpoint = value;
}
}
public void drawpeople(Graphics g)//画个实心圆代表人物
{
SolidBrush b = new SolidBrush(Color.IndianRed);
Rectangle rect = new Rectangle(footpoint.X, footpoint.Y, 10, 10);
g.FillEllipse(b, rect);
}
public void moveleft()//人物向左移动
{
Point p = new Point(footpoint.X - 2, footpoint.Y);
footpoint = p;
}
public void moveright()//人物向右移动
{
Point p = new Point(footpoint.X + 2, footpoint.Y);
footpoint = p;
}
public void moverise()//人物随梯子上升
{
Point p = new Point(footpoint.X, footpoint.Y-1);
footpoint = p;
}
public void movedown()//人物下落
{
Point p = new Point(footpoint.X, footpoint.Y + 1);
footpoint = p;
}
public bool mandead()//人物死亡
{
if ( footpoint.Y<0 ||footpoint.Y>340)
return true ;
return false ;
}
}
}
发两个玩玩吧。 都测试过可行的
4. 求c#窗口体应用小游戏代码 最好要有图片和按钮等等控件,可以打开存档的话更好。 游戏可以是贪吃蛇、
using System;
using System.Collections.Generic;
using System.Text;
using System.Drawing;
namespace EngorgeSerpent
{
/// <summary>
/// 节点
/// </summary>
class Node
{
#region 字段
private int x;
private int y;
private int width = 10;
private bool isFood = false;
private bool isPass = true;//是否可通过
private Color bgColor = Color.FromArgb(224, 224, 224);
private Color foodColor = Color.Green;
private Color hinderColor = Color.Black;
private Color thisColor;
private Color serpentColor = Color.Chocolate;
#endregion
/// <summary>
/// 设置食物参数
/// </summary>
/// <param name="_isFood"></param>
public void SetFood(bool _isFood)
{
IsFood = _isFood;
if (_isFood)
{
ThisColor = FoodColor;
}
else
{
ThisColor = BgColor;
}
}
/// <summary>
/// 设置障碍物参数
/// </summary>
/// <param name="_isHinder">是否为障碍物</param>
public void SetHinder(bool _isHinder)
{
IsPass =! _isHinder;
if (_isHinder)
{
ThisColor = HinderColor;
}
else
{
ThisColor = BgColor;
}
}
/// <summary>
/// 设置蛇颜色
/// </summary>
/// <param name="_isSerpent"></param>
public void SetSerpent(bool _isSerpent)
{
IsPass = !_isSerpent;
if (_isSerpent)
{
ThisColor = SerpentColor;
}
else
{
ThisColor = BgColor;
}
}
#region 构造函数
public Node()
{
thisColor = bgColor;
}
/// <summary>
/// 有参构造方法
/// </summary>
/// <param name="_x">相对x坐标</param>
/// <param name="_y">相对y坐标</param>
/// <param name="_width">边长</param>
/// <param name="_isFood">是否是食物</param>
/// <param name="_isPass">是否可通过</param>
public Node(int _x, int _y, int _width, bool _isFood, bool _isPass)
{
thisColor = bgColor;
X = _x;
Y = _y;
Width = _width;
IsFood = _isFood;
IsPass = _isPass;
}
/// <summary>
/// 有参构造方法
/// </summary>
/// <param name="_x">相对x坐标</param>
/// <param name="_y">相对y坐标</param>
/// <param name="_width">边长</param>
public Node(int _x, int _y, int _width)
{
X = _x;
Y = _y;
Width = _width;
}
/// <summary>
/// 有参构造方法
/// </summary>
/// <param name="_x">相对x坐标</param>
/// <param name="_y">相对y坐标</param>
public Node(int _x, int _y)
{
X = _x;
Y = _y;
}
#endregion
#region 属性
/// <summary>
/// 蛇颜色
/// </summary>
public Color SerpentColor
{
get { return serpentColor; }
}
/// <summary>
/// 背景色
/// </summary>
public Color BgColor
{
get { return bgColor; }
}
/// <summary>
/// 食物颜色
/// </summary>
public Color FoodColor
{
get { return foodColor; }
}
/// <summary>
/// 障碍物颜色
/// </summary>
public Color HinderColor
{
get { return hinderColor; }
}
/// <summary>
/// 当前颜色
/// </summary>
public Color ThisColor
{
get { return thisColor; }
set { thisColor = value; }
}
/// <summary>
/// 获取或设置相对横坐标
/// </summary>
public int X
{
get { return x; }
set { x = value; }
}
/// <summary>
/// 获取或设置相对纵坐标
/// </summary>
public int Y
{
get { return y; }
set { y = value; }
}
/// <summary>
/// 获取或设置节点边长
/// </summary>
public int Width
{
get { return width; }
set { width = value; }
}
/// <summary>
/// 获取或设置是否为食物
/// </summary>
public bool IsFood
{
get { return isFood; }
set { isFood = value; }
}
/// <summary>
/// 获取或设置是否可以通过
/// </summary>
public bool IsPass
{
get { return isPass; }
set { isPass = value; }
}
#endregion
}
}
参考资料:http://www.cnblogs.com/bfyx/archive/2012/11/05/2755569.html
5. C#射击小游戏源码 越简单越好
不住道
大声的
6. 向各位大哥大姐求一点C#编写的小游戏源代码!!(最好新颖一点的)
^using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Text.RegularExpressions;
namespace NumberPuzzle
{
class Program
{
/// <summary>
/// Num Puzzle
/// ^^**
/// </summary>
/// <param name="args"></param>
static void Main(string[] args)
{
string numPazzle = string.Empty;
string numLength = string.Empty;
int count = 0;
int countMax = 0;
Console.WriteLine("How long do you want?[0<n<11] \"Suggestion : 4\"");
while (true)
{
numLength = Console.ReadLine();
if (IsNum(numLength))
{
countMax = Convert.ToInt32(numLength);
if (countMax > 10)
{
Console.WriteLine("Re-inpt e to n>10");
continue;
}
break;
}
else
{
Console.WriteLine("Re-inpt, input is not a num:");
continue;
}
}
while (count < countMax)
{
string strA = GetNum();
if (numPazzle.IndexOf(strA) != -1)
{
continue;
}
numPazzle += strA;
count++;
}
while (true)
{
string input = string.Empty;
string results = string.Empty;
Console.WriteLine("Input what you guess:");
input = Console.ReadLine();
if (!IsNum(input))
{
Console.WriteLine("Re-inpt, input is not a num:");
continue;
}
if (input.Length != countMax)
{
Console.WriteLine("The length of input is error");
continue;
}
if (IsDup(input))
{
Console.WriteLine("Input is a p num");
continue;
}
results = CompareNum(input, numPazzle);
if (results.Split('-')[0].Equals(numPazzle.Length.ToString()))
break;
Console.WriteLine("Results: A-{0} B-{1}", results.Split('-')[0], results.Split('-')[1]);
}
Console.WriteLine("Win! The num is {0}", numPazzle);
Console.ReadKey();
}
public static string GetNum()
{
Random sSeed = new Random();
Random seed = new Random(sSeed.Next());
return seed.Next(10).ToString();
}
public static string CompareNum(string actualStr, string expectedStr)
{
int a = 0;
int b = 0;
string results = string.Empty;
for (int i = 0; i < actualStr.Length; i++)
{
if (expectedStr.IndexOf(actualStr[i]) != -1)
{
b++;
}
if (expectedStr[i].Equals(actualStr[i]))
{
a++;
b--;
}
}
results = a.ToString() + "-" + b.ToString();
return results;
}
public static bool IsDup(string input)
{
bool result = false;
foreach (char aStr in input)
{
if (input.IndexOf(aStr) != input.LastIndexOf(aStr))
{
result = true;
break;
}
}
return result;
}
public static bool IsNum(string numInput)
{
bool result = false;
Regex reg = new Regex(@"^-?\d+$");
result = reg.IsMatch(numInput);
return result;
}
}
}
CMD 猜数字
7. 求一个c#小游戏源代码
已经发送到你邮箱,觉得可以就给分吧
8. 谁能给我一些c#的小游戏代码 或一些小编程代码的,,,谢谢!!!
贪吃蛇
#define N 200
#include <graphics.h>
#include <stdlib.h>
#include <dos.h>
#define LEFT 0x4b00
#define RIGHT 0x4d00
#define DOWN 0x5000
#define UP 0x4800
#define ESC 0x011b
int i,key;
int score=0;/*得分*/
int gamespeed=50000;/*游戏速度自己调整*/
struct Food
{
int x;/*食物的横坐标*/
int y;/*食物的纵坐标*/
int yes;/*判断是否要出现食物的变量*/
}food;/*食物的结构体*/
struct Snake
{
int x[N]; /*蛇可出现的最大节数*/
int y[N];
int node;/*蛇的节数*/
int direction;/*蛇移动方向*/
int life;/* 蛇的生命,0活着,1死亡*/
}snake;
void Init(void);/*图形驱动*/
void Close(void);/*图形结束*/
void DrawK(void);/*开始画面*/
void GameOver(void);/*结束游戏*/
void GamePlay(void);/*玩游戏具体过程*/
void PrScore(void);/*输出成绩*/
/*主函数*/
void main(void)
{
Init();/*图形驱动*/
DrawK();/*开始画面*/
GamePlay();/*玩游戏具体过程*/
Close();/*图形结束*/
}
/*图形驱动*/
void Init(void)
{
int gd=DETECT,gm;
initgraph(&gd,&gm,"c:\\tc");
cleardevice();
}
/*开始画面,左上角坐标为(50,40),右下角坐标为(610,460)的围墙*/
void DrawK(void)
{
/*setbkcolor(LIGHTGREEN);*/
setcolor(11);
setlinestyle(SOLID_LINE,0,THICK_WIDTH);/*设置线型*/
for(i=50;i<=600;i+=10)/*画围墙*/
{
rectangle(i,40,i+10,49); /*上边*/
rectangle(i,451,i+10,460);/*下边*/
}
for(i=40;i<=450;i+=10)
{
rectangle(50,i,59,i+10); /*左边*/
rectangle(601,i,610,i+10);/*右边*/
}
}
/*玩游戏具体过程*/
void GamePlay(void)
{
randomize();/*随机数发生器*/
food.yes=1;/*1表示需要出现新食物,0表示已经存在食物*/
snake.life=0;/*活着*/
snake.direction=1;/*方向往右*/
snake.x[0]=100;snake.y[0]=100;/*蛇头*/
snake.x[1]=110;snake.y[1]=100;
snake.node=2;/*节数*/
PrScore();/*输出得分*/
while(1)/*可以重复玩游戏,压ESC键结束*/
{
while(!kbhit())/*在没有按键的情况下,蛇自己移动身体*/
{
if(food.yes==1)/*需要出现新食物*/
{
food.x=rand()%400+60;
food.y=rand()%350+60;
while(food.x%10!=0)/*食物随机出现后必须让食物能够在整格内,这样才可以让蛇吃到*/
food.x++;
while(food.y%10!=0)
food.y++;
food.yes=0;/*画面上有食物了*/
}
if(food.yes==0)/*画面上有食物了就要显示*/
{
setcolor(GREEN);
rectangle(food.x,food.y,food.x+10,food.y-10);
}
for(i=snake.node-1;i>0;i--)/*蛇的每个环节往前移动,也就是贪吃蛇的关键算法*/
{
snake.x[i]=snake.x[i-1];
snake.y[i]=snake.y[i-1];
}
/*1,2,3,4表示右,左,上,下四个方向,通过这个判断来移动蛇头*/
switch(snake.direction)
{
case 1:snake.x[0]+=10;break;
case 2: snake.x[0]-=10;break;
case 3: snake.y[0]-=10;break;
case 4: snake.y[0]+=10;break;
}
for(i=3;i<snake.node;i++)/*从蛇的第四节开始判断是否撞到自己了,因为蛇头为两节,第三节不可能拐过来*/
{
if(snake.x[i]==snake.x[0]&&snake.y[i]==snake.y[0])
{
GameOver();/*显示失败*/
snake.life=1;
break;
}
}
if(snake.x[0]<55||snake.x[0]>595||snake.y[0]<55||
snake.y[0]>455)/*蛇是否撞到墙壁*/
{
GameOver();/*本次游戏结束*/
snake.life=1; /*蛇死*/
}
if(snake.life==1)/*以上两种判断以后,如果蛇死就跳出内循环,重新开始*/
break;
if(snake.x[0]==food.x&&snake.y[0]==food.y)/*吃到食物以后*/
{
setcolor(0);/*把画面上的食物东西去掉*/
rectangle(food.x,food.y,food.x+10,food.y-10);
snake.x[snake.node]=-20;snake.y[snake.node]=-20;
/*新的一节先放在看不见的位置,下次循环就取前一节的位置*/
snake.node++;/*蛇的身体长一节*/
food.yes=1;/*画面上需要出现新的食物*/
score+=10;
PrScore();/*输出新得分*/
}
setcolor(4);/*画出蛇*/
for(i=0;i<snake.node;i++)
rectangle(snake.x[i],snake.y[i],snake.x[i]+10,
snake.y[i]-10);
delay(gamespeed);
setcolor(0);/*用黑色去除蛇的的最后一节*/
rectangle(snake.x[snake.node-1],snake.y[snake.node-1],
snake.x[snake.node-1]+10,snake.y[snake.node-1]-10);
} /*endwhile(!kbhit)*/
if(snake.life==1)/*如果蛇死就跳出循环*/
break;
key=bioskey(0);/*接收按键*/
if(key==ESC)/*按ESC键退出*/
break;
else
if(key==UP&&snake.direction!=4)
/*判断是否往相反的方向移动*/
snake.direction=3;
else
if(key==RIGHT&&snake.direction!=2)
snake.direction=1;
else
if(key==LEFT&&snake.direction!=1)
snake.direction=2;
else
if(key==DOWN&&snake.direction!=3)
snake.direction=4;
}/*endwhile(1)*/
}
/*游戏结束*/
void GameOver(void)
{
cleardevice();
PrScore();
setcolor(RED);
settextstyle(0,0,4);
outtextxy(200,200,"GAME OVER");
getch();
}
/*输出成绩*/
void PrScore(void)
{
char str[10];
setfillstyle(SOLID_FILL,YELLOW);
bar(50,15,220,35);
setcolor(6);
settextstyle(0,0,2);
sprintf(str,"score:%d",score);
outtextxy(55,20,str);
}
/*图形结束*/
void Close(void)
{
getch();
closegraph();
}
另外,虚机团上产品团购,超级便宜
9. 谁有没有C#小游戏的源代码啊
恩,有个扫雷...好像还写过一个 俄罗斯方块..忘记给扔哪儿去了
10. 求C#单击小游戏源代码
我原来用写抄过一个五子棋的小程序,可惜现在人在外地出差,源码在家里的电脑上面。
不过我推荐你一个网站,上面有好多源码,其中也包括一些小游戏的源码,最重要的是下载不需要积分的。
http://51aspx.com/
这个是我在该站点搜索“游戏”关键字查询出来的结果,希望可以找到你喜欢的小游戏。
http://51aspx.com/S/%E6%B8%B8%E6%88%8F.html