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