fill小游戏153m的简单介绍
求C语言编写的壁球小游戏的源代码,谢谢。
速度和 接板 长度不能改
所以比较难玩
#include "graphics.h"
#include "stdio.h"
#include "conio.h" /*所需的头文件*/
int on; /*声明具有开关作用的全局变量*/
static int score; /*声明静态的记分器变量*/
/* 定义开始界面函数*/
int open()
{
setviewport(100,100,500,380,1); /*设置图形窗口区域*/
setcolor(4); /*设置作图色*/
rectangle(0,0,399,279); /*以矩形填充所设的图形窗口区域*/
setfillstyle(SOLID_FILL,7); /*设置填充方式*/
floodfill(50,50,4); /*设置填充范围*/
setcolor(8);
settextstyle(0,0,9); /*文本字体设置*/
outtextxy(90,80,"BALL"); /*输出文本内容*/
settextstyle(0,0,1);
outtextxy(110,180,"version 1.0");
outtextxy(110,190,"made by ddt");
setcolor(128);
settextstyle(0,0,1);
outtextxy(120,240,"Press any key to continue......");
}
/*定义退出界面函数*/
int quitwindow()
{
char s[100]; /*声明用于存放字符串的数组*/
setviewport(100,150,540,420,1);
setcolor(YELLOW);
rectangle(0,0,439,279);
setfillstyle(SOLID_FILL,7);
floodfill(50,50,14);
setcolor(12);
settextstyle(0,0,8);
outtextxy(120,80,"End");
settextstyle(0,0,2);
outtextxy(120,200,"quit? Y/N");
sprintf(s,"Your score is:%d",score);/*格式化输出记分器的值*/
outtextxy(120,180,s);
on=1; /*初始化开关变量*/
}
/*主函数*/
main()
{
int gdriver,gmode;
gdriver=DETECT; /*设置图形适配器*/
gmode=0; /*设置图形模式*/
registerbgidriver(EGAVGA_driver);/* 注册BGI驱动后可以不需要.BGI文件的支持运行 */
initgraph(gdriver,gmode,"");
setbkcolor(14);
open(); /*调用开始界面函数*/
getch(); /*暂停*/
while(1) /*此大循环体控制游戏的反复重新进行*/
{
int driver,mode,l=320,t=400,r,a,b,dl=5,n,x=200,y=400,r1=10,dx=-2,dy=-2;/*初始化小球相关参数*/
int left[100],top[100],right[100],bottom[100],i,j,k,off=1,m,num[100][100];/*方砖阵列相关参数*/
static int pp;
static int phrase; /*一系列起开关作用的变量*/
int oop=15;
pp=1;
score=0;
driver=DETECT;
mode=VGA;
registerbgidriver(EGAVGA_driver);
initgraph(driver,mode,"");
setbkcolor(10);
cleardevice(); /*图形状态下清屏*/
clearviewport(); /*清除现行图形窗口内容*/
b=t+6;
r=l+60;
setcolor(1);
rectangle(0,0,639,479);
setcolor(4);
rectangle(l,t,r,b);
setfillstyle(SOLID_FILL,1);
floodfill(l+2,t+2,4);
for(i=0,k=0;i=6;i++) /*此循环绘制方砖阵列*/
{
top[i]=k;
bottom[i]=top[i]+20;
k=k+21;
oop--;
for(j=0,m=0;j=7;j++)
{
left[j]=m;
right[j]=left[j]+80;
m=m+81;
setcolor(4);
rectangle(left[j],top[i],right[j],bottom[i]);
setfillstyle(SOLID_FILL,j+oop);
floodfill(left[j]+1,top[i]+1,4);
num[i][j]=pp++;
}
}
while(1) /*此循环控制整个动画*/
{
while(!kbhit())
{
x=x+dx; /*小球运动的圆心变量控制*/
y=y+dy;
if(x+r1r||x+r1r)
{ phrase=0;}
if((x-r1=r||x+r1=r)x+r1=l)
{
if(yt)
phrase=1;
if(y+r1=tphrase==1)
{dy=-dy;y=t-1-r1;}
}
if(off==0)
continue;
for(i=0;i=6;i++) /*此循环用于判断、控制方砖阵列的撞击、擦除*/
for(j=0;j=7;j++)
{
if((x+r1=right[j]x+r1=left[j])||(x-r1=right[j]x-r1=left[j]))
{
if(( y-r1top[i]y-r1=bottom[i])||(y+r1=top[i]y+r1=bottom[i] ))
{
if(num[i][j]==0)
{continue; }
setcolor(10);
rectangle(left[j],top[i],right[j],bottom[i]);
setfillstyle(SOLID_FILL,10);
floodfill(left[j]+1,top[i]+1,10);
dy=-dy;
num[i][j]=0;
score=score+10;
printf("%d\b\b\b",score);
}
}
if((y+r1=top[i]y+r1=bottom[i])||(y-r1=top[i]y-r1=bottom[i]))
{
if((x+r1=left[j]x+r1right[j])||(x-r1=right[j]x-r1left[j]))
{
if(num[i][j]==0)
{ continue;}
setcolor(10);
rectangle(left[j],top[i],right[j],bottom[i]);
setfillstyle(SOLID_FILL,10);
floodfill(left[j]+1,top[i]+1,10);
dx=-dx;
num[i][j]=0;
score=score+10;
printf("%d\b\b\b",score);
}
}
}
if(x+r1639) /*控制小球的弹射范围*/
{dx=-dx;x=638-r1;}
if(x=r1)
{dx=-dx;x=r1+1;}
if(y+r1=479)
{off=0;quitwindow();break;}
if(y=r1)
{dy=-dy;y=r1+1;}
if(score==560)
{off=0;quitwindow();break;}
setcolor(6);
circle(x,y,r1);
setfillstyle(SOLID_FILL,14);
floodfill(x,y,6);
delay(1000);
setcolor(10);
circle(x,y,r1);
setfillstyle(SOLID_FILL,10);
floodfill(x,y,10);
}
a=getch();
setcolor(10);
rectangle(l,t,r,b);
setfillstyle(SOLID_FILL,10);
floodfill(l+2,t+2,10);
if(a==77l=565) /*键盘控制设定*/
{dl=20;l=l+dl;}
if(a==75l=15)
{dl=-20;l=l+dl;}
if(a=='y'on==1)
break;
if(a=='n'on==1)
break;
if(a==27)
{quitwindow();off=0;}
r=l+60;
setcolor(4);
rectangle(l,t,r,b);
setfillstyle(SOLID_FILL,1);
floodfill(l+5,t+5,4);
delay(100);
}
if(a=='y'on==1) /*是否退出游戏*/
{break;}
if(a=='n'on==1)
{ continue;}
}
closegraph();
}
你不是要求在TC里运行么
C++和C不同的
如果要在C++里
你前面要写函数的声明的
C里就不用
修改过了,试一试吧。
我这里可以
一闪而过那个是图形界面的问题
驱动没安装好
vb小游戏代码 急求。。。。。
Option Explicit
'五子棋程序 人机对战版本
'需要2个Label控件 2个CommandButton控件
Private Declare Function SetWindowRgn Lib "user32" (ByVal hWnd As Long, ByVal hRgn As Long, ByVal bRedraw As Boolean) As Long
Private Declare Function CreateRoundRectRgn Lib "gdi32" (ByVal X1 As Long, ByVal Y1 As Long, ByVal X2 As Long, ByVal Y2 As Long, ByVal X3 As Long, ByVal Y3 As Long) As Long
'Dim PlayStep() As String '记录棋谱的数组
'Dim Label2Cap As String
Private Const BoxL As Single = 50, BoxT As Single = 50, BoxW As Single = 25, BoxN As Integer = 18
Dim Table() As Long '棋盘(0-BoxN,0-BoxN) 0-空 1-黑子 2-白子
Dim PsCore() As Long '定义当前玩家桌面空格的分数
Dim CsCore() As Long '定义当前电脑桌面空格的分数
Dim pWin() As Boolean '定义玩家的获胜组合
Dim cWin() As Boolean '定义电脑的获胜组合
Dim pFlag() As Boolean '定义玩家的获胜组合标志
Dim cFlag() As Boolean '定义电脑的获胜组合标志
Dim ThePlayFlag As Boolean '定义游戏有效标志
Private Sub Command1_Click()
If Not ThePlayFlag Then Call InitPlayEnvironment: Exit Sub
If MsgBox("本局还没有下完,是否重新开始?(Y/N)", vbYesNo) = vbNo Then Exit Sub
Call InitPlayEnvironment
End Sub
Private Sub Command2_Click()
End
End Sub
Private Sub Form_Load()
MsgBox "五子棋之人机对战系统,作者:杨海", vbOKOnly, "杨海作品"
Dim i As Long, lw As Long, lh As Long
'Label2Cap = "000 黑方 行 00 列 00"
Me.Width = 10815: Me.Height = 8200: Me.Caption = "五子棋 - 人机对战 作者:卢霞": Me.Show
lw = Me.Width \ Screen.TwipsPerPixelX: lh = Me.Height \ Screen.TwipsPerPixelY
SetWindowRgn Me.hWnd, CreateRoundRectRgn(0, 0, lw, lh, 10, 10), True
With Label1
.Alignment = vbCenter: .FontSize = 12: .FontBold = True
.ForeColor = vbRed: .BackStyle = 0: .AutoSize = True: .Move 8910, 510
End With
Label2.AutoSize = True: Label2.WordWrap = True
Label2.BackStyle = 0: Label2.Move 8040, 1050, 2280
Command1.Move 8025, 7035, 1020, 435: Command1.Caption = "再来一局"
Command2.Move 9300, 7035, 1020, 435: Command2.Caption = "不玩了"
Call DrawChessBoard: Me.FillStyle = 0: Call InitPlayEnvironment
End Sub
Private Sub Form_QueryUnload(Cancel As Integer, UnloadMode As Integer)
End
End Sub
Private Sub Form_MouseDown(Button As Integer, Shift As Integer, X As Single, Y As Single)
Dim iRow As Long, iCol As Long, i As Long, k As Long, t As String
If Not ThePlayFlag Then Exit Sub
If Button = vbLeftButton Then '左键下棋
iRow = -1: iCol = -1
For i = 0 To BoxN '鼠标必须落在交叉点 半径10以内 若是则给出行列号
If (Y + 10) (BoxT + i * BoxW) And (Y - 10) = (BoxT + i * BoxW) Then iRow = i
If (X + 10) (BoxL + i * BoxW) And (X - 10) = (BoxL + i * BoxW) Then iCol = i
Next
If (iRow = -1) Or (iCol = -1) Then Beep: Exit Sub
If Table(iCol, iRow) 0 Then Exit Sub
Table(iCol, iRow) = 2: Label1.Caption = "下一步 黑方"
Me.FillColor = vbWhite: Me.Circle (iCol * BoxW + BoxT, iRow * BoxW + BoxL), 8
For i = 0 To UBound(cWin, 3)
If cWin(iCol, iRow, i) = True Then cFlag(i) = False
Next
Call CheckWin: Call DianNao '检查当前玩家是否获胜 调用电脑算法
End If
End Sub
Public Sub InitPlayEnvironment()
'*****************************************************************************
' 模块名称: InitPlayEnvironment [初始化过程]
'
' 描述: 1. 设置背景音乐。 2. 设置游戏状态有效。
' 3. 初始化游戏状态标签。 4. 直接指定电脑的第一步走法。
' 5. 初始化基本得分桌面。 6. 电脑和玩家获胜标志初始化。
' 7. 初始化所有获胜组合。 8. 重新设定玩家的获胜标志。
'*****************************************************************************
Dim i As Long, j As Long, m As Long, n As Long
ThePlayFlag = True: Label1.Caption = "下一步 白方": Label2.Caption = ""
Me.FillColor = vbBlack: Me.FillStyle = 0: Me.AutoRedraw = True
Me.Cls: Me.Circle (9 * BoxW + BoxL, 9 * BoxW + BoxT), 8
ReDim Table(0 To BoxN, 0 To BoxN) As Long
ReDim pFlag(NumsWin(BoxN + 1) - 1) As Boolean
ReDim cFlag(UBound(pFlag)) As Boolean
ReDim PsCore(BoxN, BoxN) As Long, CsCore(BoxN, BoxN) As Long
ReDim pWin(BoxN, BoxN, UBound(pFlag)) As Boolean
ReDim cWin(BoxN, BoxN, UBound(pFlag)) As Boolean
For i = 0 To UBound(pFlag): pFlag(i) = True: cFlag(i) = True: Next
Table(9, 9) = 1 '假定电脑先手 并下了(9, 9)位 将其值设为1
'******** 初始化获胜组合 ****************************************
For i = 0 To BoxN: For j = 0 To BoxN - 4
For m = 0 To 4
pWin(j + m, i, n) = True: cWin(j + m, i, n) = True
Next
n = n + 1
Next: Next
For i = 0 To BoxN: For j = 0 To BoxN - 4
For m = 0 To 4
pWin(i, j + m, n) = True: cWin(i, j + m, n) = True
Next
n = n + 1
Next: Next
For i = 0 To BoxN - 4: For j = 0 To BoxN - 4
For m = 0 To 4
pWin(j + m, i + m, n) = True: cWin(j + m, i + m, n) = True
Next
n = n + 1
Next: Next
For i = 0 To BoxN - 4: For j = BoxN To 4 Step -1
For m = 0 To 4
pWin(j - m, i + m, n) = True: cWin(j - m, i + m, n) = True
Next
n = n + 1
Next: Next
'******** 初始化获胜组合结束 *************************************
For i = 0 To UBound(pWin, 3) '由于电脑已下了(9, 9)位 所以需要重新设定玩家的获胜标志
If pWin(9, 9, i) = True Then pFlag(i) = False
Next
End Sub
Public Function DrawChessBoard() As Long
'容器的(BoxL, BoxT)为左上角坐标画一个 BoxN*BoxN, 每格边长为 BoxW 象素的棋盘
Dim i As Long, j As Long, cx As Long, cy As Long
Me.ScaleMode = 3: Me.FillStyle = 1: Me.AutoRedraw = True: Me.Cls
For i = 0 To BoxN '画棋盘
Me.Line (BoxL + i * BoxW, BoxT)-(BoxL + i * BoxW, BoxT + BoxN * BoxW)
Me.Line (BoxL, BoxT + i * BoxW)-(BoxL + BoxN * BoxW, BoxT + i * BoxW)
Me.CurrentX = BoxL + i * BoxW - IIf(i 9, 6, 2)
Me.CurrentY = BoxT - 20: Me.Print Format(i)
Me.CurrentX = BoxL - IIf(i 9, 23, 20)
Me.CurrentY = BoxT + i * BoxW - 6: Me.Print Format(i)
Next
For i = 3 To 16 Step 6: For j = 3 To 16 Step 6 '画小标志
cx = BoxL + j * BoxW - 3: cy = BoxT + i * BoxW - 3
Me.Line (cx, cy)-(cx + 6, cy + 6), , B
Next: Next
Me.AutoRedraw = False: Set Me.Picture = Me.Image
End Function
Public Sub CheckWin()
'*****************************************************************************
' 模块名称: CheckWin [获胜检查算法]
'
' 描述: 1. 检查是否和棋。 2. 检查电脑是否获胜。 3. 检查玩家是否获胜。
'*****************************************************************************
Dim i As Long, j As Long, k As Long, m As Long, n As Long
Dim cA As Long, pA As Long, cN As Long
For i = 0 To UBound(cFlag): cN = IIf(cFlag(i) = False, cN + 1, cN): Next
If cN = UBound(cFlag) - 1 Then '设定和棋规则
Label1.Caption = "双方和棋!": ThePlayFlag = False: Exit Sub
End If
For i = 0 To UBound(cFlag) '检查电脑是否获胜
If cFlag(i) = True Then
cA = 0: For j = 0 To BoxN: For k = 0 To BoxN
If Table(j, k) = 1 And cWin(j, k, i) = True Then cA = cA + 1
Next: Next
If cA = 5 Then Label1.Caption = "电脑获胜!": ThePlayFlag = False: Exit Sub
End If
Next
For i = 0 To UBound(pFlag) '检查玩家是否获胜
If pFlag(i) = True Then
pA = 0: For j = 0 To BoxN: For k = 0 To BoxN
If Table(j, k) = 2 And pWin(j, k, i) = True Then pA = pA + 1
Next: Next
If pA = 5 Then Label1.Caption = "玩家获胜!": ThePlayFlag = False: Exit Sub
End If
Next
End Sub
Public Sub DianNao()
'*****************************************************************************
' 模块名称: DianNao [电脑算法]
' 描述: 1. 初始化赋值系统。 2. 赋值加强算法。 3. 计算电脑和玩家的最佳攻击位。
' 4. 比较电脑和玩家的最佳攻击位并决定电脑的最佳策略。 5. 执行检查获胜函数。
'*****************************************************************************
Dim i As Long, j As Long, k As Long, m As Long, n As Long
Dim Dc As Long, cAb As Long, pAb As Long
ReDim PsCore(BoxN, BoxN) As Long, CsCore(BoxN, BoxN) As Long '初始化赋值数组
'******** 电脑加强算法 ********
For i = 0 To UBound(cFlag)
If cFlag(i) = True Then
cAb = 0
For j = 0 To BoxN: For k = 0 To BoxN
If Table(j, k) = 1 And cWin(j, k, i) = True Then cAb = cAb + 1
Next: Next
Select Case cAb
Case 3
For m = 0 To BoxN: For n = 0 To BoxN
If Table(m, n) = 0 And cWin(m, n, i) = True Then CsCore(m, n) = CsCore(m, n) + 5
Next: Next
Case 4
For m = 0 To BoxN: For n = 0 To BoxN
If Table(m, n) = 0 And cWin(m, n, i) = True Then
Table(m, n) = 1: Label1.Caption = "下一步 白方"
Me.FillColor = vbBlack: Me.Circle (m * BoxW + BoxL, n * BoxW + BoxT), 8
For Dc = 0 To UBound(pWin, 3)
If pWin(m, n, Dc) = True Then pFlag(Dc) = False: Call CheckWin: Exit Sub
Next
End If
Next: Next
End Select
End If
Next
For i = 0 To UBound(pFlag)
If pFlag(i) = True Then
pAb = 0
For j = 0 To BoxN: For k = 0 To BoxN
If Table(j, k) = 2 And pWin(j, k, i) = True Then pAb = pAb + 1
Next: Next
Select Case pAb
Case 3
For m = 0 To BoxN: For n = 0 To BoxN
If Table(m, n) = 0 And pWin(m, n, i) = True Then PsCore(m, n) = PsCore(m, n) + 30
Next: Next
Case 4
For m = 0 To BoxN: For n = 0 To BoxN
If Table(m, n) = 0 And pWin(m, n, i) = True Then
Table(m, n) = 1: Label1.Caption = "下一步 白方"
Me.FillColor = vbBlack: Me.Circle (m * BoxW + BoxL, n * BoxW + BoxT), 8
For Dc = 0 To UBound(pWin, 3)
If pWin(m, n, Dc) = True Then pFlag(Dc) = False: Call CheckWin: Exit Sub
Next
End If
Next: Next
End Select
End If
Next
'******** 电脑加强算法结束 ********
'******** 赋值系统 ****************
For i = 0 To UBound(cFlag)
If cFlag(i) = True Then
For j = 0 To BoxN: For k = 0 To BoxN
If (Table(j, k) = 0) And cWin(j, k, i) Then
For m = 0 To BoxN: For n = 0 To BoxN
If (Table(m, n) = 1) And cWin(m, n, i) Then CsCore(j, k) = CsCore(j, k) + 1
Next: Next
End If
Next: Next
End If
Next
For i = 0 To UBound(pFlag)
If pFlag(i) = True Then
For j = 0 To BoxN: For k = 0 To BoxN
If (Table(j, k) = 0) And pWin(j, k, i) Then
For m = 0 To BoxN: For n = 0 To BoxN
If (Table(m, n) = 2) And pWin(m, n, i) Then PsCore(j, k) = PsCore(j, k) + 1
Next: Next
End If
Next: Next
End If
Next
'******** 赋值系统结束 ************
'******** 分值比较算法 ************
Dim a As Long, b As Long, c As Long, d As Long
Dim cS As Long, pS As Long
For i = 0 To BoxN: For j = 0 To BoxN
If CsCore(i, j) cS Then cS = CsCore(i, j): a = i: b = j
Next: Next
For i = 0 To BoxN: For j = 0 To BoxN
If PsCore(i, j) pS Then pS = PsCore(i, j): c = i: d = j
Next: Next
If cS pS Then
Table(a, b) = 1: Label1.Caption = "下一步 白方"
Me.FillColor = vbBlack: Me.Circle (a * BoxW + BoxL, b * BoxW + BoxT), 8
For i = 0 To UBound(pWin, 3)
If pWin(a, b, i) = True Then pFlag(i) = False
Next
Else
Table(c, d) = 1: Label1.Caption = "下一步 白方"
Me.FillColor = vbBlack: Me.Circle (c * BoxW + BoxL, d * BoxW + BoxL), 8
For i = 0 To UBound(pWin, 3)
If pWin(c, d, i) = True Then pFlag(i) = False
Next
End If
'******** 分值比较算法结束 ********
Call CheckWin
End Sub
Public Function NumsWin(ByVal n As Long) As Long
'根据输入的棋盘布局 n*n 计算总共有多少种获胜组合
'假定棋盘为 10 * 10 相应的棋盘数组就是 Table(9, 9)
'水平方向 每一列获胜组合是6 共10列 6*10=60
'垂直方向 每一行获胜组合是6 共10行 8*10=60
'正对角线方向 6 + (5 + 4 + 3 + 2 + 1) * 2 = 36
'反对角线方向 6 + (5 + 4 + 3 + 2 + 1) * 2 = 36
'总的获胜组合数为 60 + 60 + 36 + 36 = 192
Dim i As Long, t As Long
For i = n - 5 To 1 Step -1: t = t + i: Next
NumsWin = 2 * (2 * t + n - 4) + 2 * n * (n - 4)
End Function
求易语言写小游戏的源码
哇,C语言直接写屏小游戏,这样写屏比较累啊。
.版本 2
.程序集 窗口程序集1
.程序集变量 电脑得分, 整数型
.程序集变量 自己得分, 整数型
.程序集变量 电脑出, 整数型, , , 1剪刀2布3石头
.子程序 __启动窗口_创建完毕
置随机数种子 (取启动时间 ())
_启动窗口.获取焦点 ()
.子程序 _按钮石头_被单击
电脑出 = 取随机数 (1, 3)
标签自己.标题 = “石头”
.如果 (电脑出 = 3)
标签对手.标题 = “石头”
信息框 (“平了!”, 0, )
.否则
.如果 (电脑出 = 1)
标签对手.标题 = “剪刀”
信息框 (“赢了!”, 0, )
自己得分 = 自己得分 + 1
.否则
标签对手.标题 = “布”
信息框 (“输了!”, 0, )
电脑得分 = 电脑得分 + 1
.如果结束
.如果结束
标签分.标题 = “比分 : ” + 到文本 (电脑得分) + “-” + 到文本 (自己得分)
标签自己.标题 = “”
标签对手.标题 = “”
_启动窗口.获取焦点 ()
.子程序 _按钮剪刀_被单击
电脑出 = 取随机数 (1, 3)
标签自己.标题 = “剪刀”
.如果 (电脑出 = 3)
标签对手.标题 = “石头”
信息框 (“输了!”, 0, )
电脑得分 = 电脑得分 + 1
.否则
.如果 (电脑出 = 1)
标签对手.标题 = “剪刀”
信息框 (“平了!”, 0, )
.否则
标签对手.标题 = “布”
信息框 (“赢了!”, 0, )
自己得分 = 自己得分 + 1
.如果结束
.如果结束
标签分.标题 = “比分 : ” + 到文本 (电脑得分) + “-” + 到文本 (自己得分)
标签自己.标题 = “”
标签对手.标题 = “”
_启动窗口.获取焦点 ()
.子程序 _按钮布_被单击
电脑出 = 取随机数 (1, 3)
标签自己.标题 = “布”
.如果 (电脑出 = 3)
标签对手.标题 = “石头”
信息框 (“赢了!”, 0, )
自己得分 = 自己得分 + 1
.否则
.如果 (电脑出 = 1)
标签对手.标题 = “剪刀”
信息框 (“输了!”, 0, )
电脑得分 = 电脑得分 + 1
.否则
标签对手.标题 = “布”
信息框 (“平了!”, 0, )
.如果结束
.如果结束
标签分.标题 = “比分 : ” + 到文本 (电脑得分) + “-” + 到文本 (自己得分)
标签自己.标题 = “”
标签对手.标题 = “”
_启动窗口.获取焦点 ()
.子程序 __启动窗口_放开某键, 逻辑型
.参数 键代码, 整数型
.参数 功能键状态, 整数型
.判断开始 (键代码 = #Z键)
_按钮石头_被单击 ()
.判断 (键代码 = #X键)
_按钮剪刀_被单击 ()
.判断 (键代码 = #C键)
_按钮布_被单击 ()
.默认
.判断结束
用C语言设计小游戏的程序??急!!!
用c++实现的"贪吃蛇"游戏源码
// greedsnake.cpp
#include bios.h
#include conio.h
#include dos.h
#include graphics.h
#include stdlib.h
#include time.h
#include "conf.h"
typedef struct node
{
int x,y;
struct node *next;
}Node;
typedef struct
{
Node *head,*tail;
int length;
}Snake;
typedef struct
{
int left,top,right,bottom;
}Frame;
typedef enum //四个方向
{
up,down,left,right
}Direction;
typedef enum
{
false,true
}bool;//*/
void InitGraphMode(); //初始化图形驱动
void CloseGraphMode();
void Foot(int,int);
void Head(int,int);
void CreateFrame(); //完成整个游戏框架的绘制
void CreateSnake(); //创建一条两个节点的蛇,蛇的每一节是队列中的一个节点
bool PlayGame(); //游戏的主体函数,
int Hit(int,int); //判断是否越界,或者撞到自身,两个参数分别是新的头接点的x,y坐标
bool GameOver(); //绘制游戏结束时弹出的对话框
void Enqueue(Node); //入队函数
Node Dequeue(); //出队函数
void ClearKeyBuf(); //清除键盘缓冲,此函数可以消除不停的按无效键的影响
Snake snake;
Frame frame;
void main()
{
InitGraphMode();
do
{
CreateFrame();
}while(PlayGame());
CloseGraphMode();
}
void InitGraphMode()
{
int gdriver=DETECT,gmode;
initgraph(gdriver,gmode,"../bgi/");
cleardevice();
}
void CloseGraphMode()
{
cleardevice();
closegraph();
}
void CreateFrame()
{
setbkcolor(CYAN);
//下面的四行代码用于计算主框架的左上角和右下角的坐标
frame.left=(getmaxx()+1-BlockWidth*RowOfFrame)/2;
frame.top=(getmaxy()+1-BlockHeight*ColumnOfFrame)/2;
frame.right=frame.left+BlockWidth*RowOfFrame;
frame.bottom=frame.top+BlockHeight*ColumnOfFrame;
Head(frame.left+100,frame.top-20);
setfillstyle(SOLID_FILL,LIGHTGRAY);
bar(frame.left,frame.top,frame.right,frame.bottom);
setlinestyle(SOLID_LINE,1,1);
setcolor(DARKGRAY);
line(frame.left,frame.top,frame.right,frame.top);
line(frame.left,frame.top,frame.left,frame.bottom);
setlinestyle(SOLID_LINE,1,1);
setcolor(WHITE);
line(frame.left,frame.bottom,frame.right,frame.bottom);
line(frame.right,frame.top,frame.right,frame.bottom);
setlinestyle(DOTTED_LINE,1,1);
setcolor(BLUE);
for(int row=1;rowRowOfFrame;row++)
line(frame.left+row*BlockWidth,frame.top,frame.left+row*BlockWidth,frame.bottom);
for(int column=1;columnColumnOfFrame;column++)
line(frame.left,frame.top+column*BlockHeight,frame.right,frame.top+column*BlockHeight);
Foot(frame.left,frame.bottom+20);
}
void CreateSnake()
{
Node *node1=new Node;
Node *node2=new Node;
node1-x=frame.left+BlockWidth;
node1-y=frame.top;
node1-next=NULL;
snake.tail=node1;
node2-x=frame.left;
node2-y=frame.top;
node2-next=snake.tail;
snake.head=node2;
snake.length=2;
setfillstyle(SOLID_FILL,BLUE);
bar(snake.head-x+1,snake.head-y+1,snake.head-x+BlockWidth-1,snake.head-y+BlockHeight-1);
bar(snake.tail-x+1,snake.tail-y+1,snake.tail-x+BlockWidth-1,snake.tail-y+BlockHeight-1);
}
bool PlayGame()
{
int speed=300,key;
Direction CurrentDirection=right;
Node randomNode;
Node newNode,outNode;
bool neednode=true;
bool overlap=false;
int randx,randy;
CreateSnake();
while(true)
{
if(neednode==true)
{
randomize();
do
{
randx=frame.left+rand()%RowOfFrame*BlockWidth;
randy=frame.top+rand()%ColumnOfFrame*BlockHeight;
for(Node *p=snake.head;p!=NULL;p=p-next)//hit itself
if(randx==p-xrandy==p-y)
{overlap=true;break;}
}
while(overlap==true);
randomNode.x=randx;
randomNode.y=randy;
randomNode.next=NULL;
setfillstyle(SOLID_FILL,RED);
bar(randomNode.x+1,randomNode.y+1,randomNode.x+BlockWidth-1,randomNode.y+BlockHeight-1);
neednode=false;
}
if((key=bioskey(1))!=0)
{
switch(key)
{
case ESC: return false;
case UP:
if(CurrentDirection!=down)
CurrentDirection=up;
ClearKeyBuf();
break;
case DOWN:
if(CurrentDirection!=up)
CurrentDirection=down;
ClearKeyBuf();
break;
case LEFT:
if(CurrentDirection!=right)
CurrentDirection=left;
ClearKeyBuf();
break;
case RIGHT:
if(CurrentDirection!=left)
CurrentDirection=right;
ClearKeyBuf();
break;
case PAGEUP:speed=speed-100;
if(speed100)
speed=100;
ClearKeyBuf();
break;
case PAGEDOWN:speed=speed+100;
if(speed500)
speed=500;
ClearKeyBuf();
break;
default :break;
}
}
int headx=snake.tail-x;
int heady=snake.tail-y;
switch(CurrentDirection)
{
case up: heady-=BlockHeight;break;
case down: heady+=BlockHeight;break;
case left: headx-=BlockWidth;break;
case right: headx+=BlockWidth;break;
}
if(Hit(headx,heady)) //whether the snake hit the wall or itself
return GameOver();
else
{ //eat
if(headx==randomNode.xheady==randomNode.y)
{
Enqueue(randomNode);
setfillstyle(SOLID_FILL,BLUE);
bar(randomNode.x+1,randomNode.y+1,randomNode.x-1+BlockWidth,randomNode.y-1+BlockHeight);
neednode=true;
}
else //no eat
{
newNode.x=headx;
newNode.y=heady;
newNode.next=NULL;
Enqueue(newNode);
outNode=Dequeue();
setfillstyle(SOLID_FILL,LIGHTGRAY);
bar(outNode.x+1,outNode.y+1,outNode.x+BlockWidth-1,outNode.y+BlockHeight-1);
setfillstyle(SOLID_FILL,BLUE);
bar(newNode.x+1,newNode.y+1,newNode.x-1+BlockWidth,newNode.y-1+BlockHeight);
}
}
delay(speed);
}
}
void ClearKeyBuf()
{
do
bioskey(0);
while(bioskey(1));
}
void Foot(int x,int y)
{
setcolor(BLUE);
outtextxy(x,y,"writer:[T]RealXL E-MAIL:realgeneral@hotmail.com");
}
void Head(int x,int y)
{
setcolor(RED);
outtextxy(x,y,"GREEDY SNAKE");
}
void Enqueue(Node inNode)
{
Node *p=new Node;
p-x=inNode.x;
p-y=inNode.y;
p-next=inNode.next;
snake.tail-next=p;
snake.tail=p;
snake.length++;
}
Node Dequeue()
{
Node *p=snake.head;
Node outNode=*p;
snake.head=p-next;
snake.length--;
delete p;
return outNode;
}
int Hit(int x,int y)
{
if(xframe.left||x=frame.right||yframe.top||y=frame.bottom)//hit the wall
return 1;
Node *p=snake.head-next;
for(int i=snake.length-1;i3;i--,p=p-next)//hit itself
if(x==p-xy==p-y)
return 1;
return 0;
}
bool GameOver()
{
int x=getmaxx()/2-50;
int y=getmaxy()/2-20;
setfillstyle(SOLID_FILL,DARKGRAY);
bar(x+3,y+3,x+103,y+43);
setfillstyle(SOLID_FILL,MAGENTA);
bar(x,y,x+100,y+40);
setlinestyle(0,3,1);
setcolor(RED);
rectangle(x,y,x+100,y+40);
outtextxy(x+20,y+10,"GAGE OVER!");
char c;
while(true) //按q或Q表示退出程序,按r或R表示重新开始游戏
{
c=getch();
if(c=='q'||c=='Q')
return false;
else if(c=='r'||c=='R')
return true;
}
}
C++五子棋源程序:
#include
#include
#include
#define backcolor CYAN
#define defaultcolor BLACK
#define linecolor MAGENTA
#define player1_color RED
#define player2_color WHITE
#define error_color RED
#define winner_color RED
const int left=40;
const int top=390;
const int d=30;
const int line_num=9;
const int turn=0;
const int r=d/3;
const int j=10;
int x,y,k=1,step=(line_num+1)*(line_num+1);
union REGS regs1,regs2;
class player1;
class player2;
class qipan{
public:
qipan();
~qipan(){};
void init_qipan();
friend void fall(player1 num1,player2 num2,qipan num);
friend void input(player1 num1,player2 num2,qipan num);
private:
int point[line_num+1][line_num+1];
};
class player1{
public:
player1();
~player1(){};
friend void fall(player1 num1,player2 num2,qipan num);
friend void input(player1 num1,player2 num2);
friend int judge_winner(player1 num1,player2 num2);
private:
int point1[line_num+1][line_num+1];
};
class player2{
public:
player2();
~player2(){};
friend void fall(player1 num1,player2 num2,qipan num);
friend void input(player1 num1,player2 num2,qipan num);
friend int judge_winner(player1 num1,player2 num2);
private:
int point2[line_num+1][line_num+1];
};
void input(player1 num1,player2 num2);
void fall(player1 num1,player2 num2,qipan num);
int judge_winner(qipan num,player1 num1,player2 num2);
void inputerror();
void display_winner(int);
void main()
{
int driver=DETECT,mode;
initgraph(driver,mode,"e:\tc30\bgi");
qipan num;
player1 num1;
player2 num2;
while(step--)
{
input(num1,num2,num);
fall(num1,num2,num);
if(judge_winner(num1,num2))
{
display_winner(k);
}
}
// getchar();
}
qipan::qipan(void)
{ int j,i;
char ch[2]="0";
setbkcolor(backcolor);
setcolor(linecolor);
for(i=0;i=line_num;i++)
{
line(left,top-i*d,left+line_num*d,top-i*d);
}
for(i=0;i=line_num;i++)
{
line(left+i*d,top,left+i*d,top-line_num*d);
}
for(i=0;i=line_num;i++)
{ if(*ch=='9'+1) *ch='a';
settextstyle(DEFAULT_FONT,HORIZ_DIR,1);
outtextxy(left+i*d-2,top+r+3,ch);
(*ch)=(*ch)+1;
}
*ch='0';
for(i=0;i=line_num;i++)
{if(*ch=='9'+1) *ch='a';
settextstyle(DEFAULT_FONT,HORIZ_DIR,1);
outtextxy(left-r-10,top-d*i-3,ch);
(*ch)=(*ch)+1;
}
setcolor(defaultcolor);
for(i=0;i=line_num;i++)
{
for(j=0;j=line_num;j++)
point[i][j]=0;
}
}
void fall(player1 num1,player2 num2,qipan num)
{
int flag=k%2;
if(flag)
{ setcolor(player2_color);
num2.point2[x][y]=1;
num.point[x][y]=2;
circle(left+d*x,top-d*y,r);
setfillstyle(1,player2_color);
floodfill(left+d*x,top-d*y,player2_color);
}
else
{ num1.point1[x][y]=1;
num.point[x][y]=1;
setcolor(player1_color);
circle(left+d*x,top-d*y,r);
setfillstyle(1,player1_color);
floodfill(left+d*x,top-d*y,player1_color);
}
setcolor(defaultcolor);
}
void input(player1 num1,player2 num2,qipan num)
{ char xx,yy;
k++;
while(1)
{
regs1.h.ah=0;
xx=int86(22,®s1,®s1)-'0';
if(xx==('q'-'0')||xx==('Q'-'0'))
{ step=0;
return;
}
regs1.h.ah=0;
yy=int86(22,®s1,®s1)-'0';
if(yy==('q'-'0')||yy==('Q'-'0'))
{
step=0;
return ;
}
if(xx0||xxline_num)
{ inputerror();
continue;
}
if(yy0||yyline_num)
{inputerror();
continue;
}
if(num.point[xx][yy]==0)
{
break;
}
else
{
inputerror();
continue;
}
}
x=(int)xx;
y=(int)yy;
setcolor(backcolor);
settextstyle(DEFAULT_FONT,HORIZ_DIR,1);
outtextxy(left+d*line_num/3,top+d*2,"Input error");
setcolor(defaultcolor);
}
player1::player1()
{
int i,j;
for(i=0;i=line_num;i++)
{
for(j=0;j=line_num;j++)
point1[i][j]=0;
}
}
player2::player2()
{ int i,j;
for(i=0;i=line_num;i++)
{
for(j=0;j=line_num;j++)
point2[i][j]=0;
}
}
void inputerror(void)
{ setcolor(error_color);
settextstyle(DEFAULT_FONT,HORIZ_DIR,1);
outtextxy(left+d*line_num/3,top+d*2,"Input error");
setcolor(defaultcolor);
}
int judge_winner(player1 num1,player2 num2)
{
int count=0,m=0,n=0,a=0,b=0,xx0,yy0;
int flag=k%2;
xx0=x; yy0=y;
if(!flag)
{ //left ------- right
while(xx0=1m4) {xx0--;m++;}
while(n9xx0=line_num)
{
if(num1.point1[xx0][y]==1)
{
count++;
if(count==5) return 1;
}
else
{
count=0;
}
n++;
xx0++;
}
//up ------ down
count=0; xx0=x; m=0; n=0;
while(yy0=1m4){yy0--;m++;}
while(n9yy0=line_num)
{
if(num1.point1[x][yy0]==1)
{
count++;
if(count==5)
return 1;
}
else
{
count=0;
}
n++;
yy0++;
}
//left up ----- right down
xx0=x;
yy0=y;
m=0;
n=0;
count=0;
while(xx0=1m4){ xx0--; a++; m++;} m=0;
while(yy0=line_numm4){ yy0++; b++; m++;}
if(a=b)
{
xx0=x-a; yy0=y+a;
}
else
{
xx0=x-b; yy0=y+b;
}
while(xx0=line_numyy0=0n9)
{
if(num1.point1[xx0][yy0]==1)
{
count++;
if(count==5)
return 1;
}
else
{
count=0;
}
xx0++;
yy0--;
n++;
}
//right up ----- left down
count=0;
a=0;
b=0;
n=0;
m=0;
xx0=x;
yy0=y;
while(xx0while(yy0if(a=b)
{
xx0=x+a;
yy0=y+a;
}
else
{
xx0=x+b;
yy0=y+b;
}
while(xx0=0yy0=0n9)
{
if(num1.point1[xx0][yy0]==1)
{
count++;
if(count==5)
return 1;
}
else
count=0;
xx0--;
yy0--;
n++;
}
//no winer
return 0;
}
else
{
//left ------- right
while(xx0=1m4) {xx0--;m++;}
while(n9xx0=line_num)
{
if(num1.point1[xx0][y]==1)
{
count++;
if(count==5) return 1;
}
else
{
count=0;
}
n++;
xx0++;
}
//up ------ down
count=0; xx0=x; m=0; n=0;
while(yy0=1m4){yy0--;m++;}
while(n9yy0=line_num)
{
if(num2.point2[x][yy0]==1)
{
count++;
if(count==5)
return 1;
}
else
{
count=0;
}
n++;
yy0++;
}
//left up ----- right down
xx0=x;
yy0=y;
m=0;
n=0;
count=0;
while(xx0=1m4){ xx0--; a++; m++;} m=0;
while(yy0=line_numm4){ yy0++; b++; m++;}
if(a=b)
{
xx0=x-a; yy0=y+a;
}
else
{
xx0=x-b; yy0=y+b;
}
while(xx0=line_numyy0=0n9)
{
if(num2.point2[xx0][yy0]==1)
{
count++;
if(count==5)
return 1;
}
else
{
count=0;
}
xx0++;
yy0--;
n++;
}
//right up ----- left down
count=0;
a=0;
b=0;
n=0;
m=0;
xx0=x;
yy0=y;
while(xx0while(yy0if(a=b)
{
xx0=x+a;
yy0=y+a;
}
else
{
xx0=x+b;
yy0=y+b;
}
while(xx0=0yy0=0n9)
{
if(num2.point2[xx0][yy0]==1)
{
count++;
if(count==5)
return 1;
}
else
count=0;
xx0--;
yy0--;
n++;
}
//no winer
return 0;
}
}
void display_winner(int k)
{
int flag=k%2;
if(!flag)
{ setcolor(winner_color);
settextstyle(DEFAULT_FONT,HORIZ_DIR,2);
outtextxy(left+d*2,top+40,"Red is winner");
setcolor(defaultcolor);
step=0;
getchar();
}
else
{ setcolor(winner_color);
settextstyle(DEFAULT_FONT,HORIZ_DIR,2);
outtextxy(left+2*d,top+40,"White is winner");
setcolor(defaultcolor);
step=0;
}
}
小游戏的C++代码
/*一个火柴人游戏,亲自验证,可运行*/
/*在编译时添加如下命令:-std=c++11,否则会编译错误*/
#include cstdio
#include cstdlib
#include Windows.h
#include thread
#include conio.h
using namespace std;
const unsigned char CTRL_KEY = 0XE0;
const unsigned char LEFT = 0X4B;
const unsigned char RIGHT = 0X4D;
const unsigned char DOWN = 0X50;
const unsigned char UP = 0X48;
int men2[2] = {0,0};
int women2[2]={10,10};
int Game();
void gotoxy( int x, int y ) //光标移动到(x,y)位置
{
HANDLE handle = GetStdHandle(STD_OUTPUT_HANDLE);
COORD pos;
pos.X = x;
pos.Y = y;
SetConsoleCursorPosition(handle,pos);
}
int clean( int mm, int nn )
{
gotoxy ( mm, nn );
printf ( " " );
gotoxy ( mm,nn+1);
printf ( " " );
gotoxy ( mm,nn+2);
printf (" ");
}
int men( int x, int y )
{
SetConsoleTextAttribute(GetStdHandle(STD_OUTPUT_HANDLE),FOREGROUND_INTENSITY|FOREGROUND_BLUE|FOREGROUND_GREEN);
gotoxy( x, y );
printf(" O");
gotoxy( x, y+1 );
printf("H");
gotoxy( x, y+2 );
printf("I I");
}
int women( int i, int j )
{
SetConsoleTextAttribute(GetStdHandle(STD_OUTPUT_HANDLE),FOREGROUND_INTENSITY|FOREGROUND_RED);
gotoxy( i+1,j );
printf(" O");
gotoxy( i+1,j+1 );
printf("H");
gotoxy( i,j+2 );
printf("/I I\\");
}
int m=10, n=10;
int x=0;int y=0;
int TorF()
{
if ( x == m y == n ) return 1;
else return 0;
}
int womenmove()
{
int turn;
int YNbreak=0;
while( YNbreak == 0 )
{
YNbreaak = TorF();
turn=rand()%3;
clean( m, n );
if( m x ) m++;
else m--;
if( m == x )
{
if( n y ) n++;
else n--;
}
if ( m 0 ) m = 0;
if ( m = 75 ) m = 75;
if ( n 0 ) n = 0;
if ( n = 22 ) n = 22;
women( m,n );
women2[0]=m;
women2[1]=n;
Sleep(100);
}
system ( "cls" );
gotoxy ( 28, 10 );
printf ( "You died!!!\n" );
SetConsoleTextAttribute(GetStdHandle(STD_OUTPUT_HANDLE),FOREGROUND_INTENSITY|FOREGROUND_GREEN|FOREGROUND_RED|FOREGROUND_BLUE);
system ( "pause" );
exit(0);
return 0;
}
int menmove()
{
system( "cls" );
while (1)
{
switch( getch())
{
case UP:y--;break;
case DOWN:y++;break;
case LEFT:x--;break;
case RIGHT:x++;break;
}
system( "cls" );
if ( x 0 ) x = 0;
if ( x 77 ) x = 77;
if ( y 0 ) y = 0;
if ( y 22 ) y = 22;
men( x, y );
men2[0] = x;
men2[1] = y;
}
}
int Game()
{
women( 10, 10 );
men( 0, 0 );
int t = 0;
thread qq( womenmove );
menmove();
qq.join();
return 0;
}
int main()
{
system( "mode con cols=80 lines=25" );
printf ( "游戏开始后,随机按下一个键,唤醒你的蓝色小人.如果你被红色的老女人碰到了,那么你就死了\n" );
printf ( "方向键操控小人\n" );
system ( "pause" );
system ( "cls" );
Game();
return 0;
}
/*留下您的赞再拿走,谢谢!*/
武装原型小游戏,武装原型在线玩,武装原型怎么玩
应该不行,我也在纠结,不过习惯就好了我都玩单人操控我压力,如果要双人的话,建议去一个单机版的 武装原形 单机版的操控不一样的
P1 P2
w 小键盘旁边的上下左右键
a s d 打右ctrl 炸弹右Shift 打左ctrl 炸弹左Shift
这样的操控应该会简单一些,版和小游戏版是不同的哦!
iphone好玩的小游戏有哪些
我很爱的是后面带@的
unblock me@@@
mr.ninja@@@
ninjump@@@@@
stylish sprint@@@
smurfs@@@@@
money pig@@@
glow hockey@@@
nuts!@
sky burger@@@
cut the rope@@@
angry birds@
talking Tom 2
talking Ben
frisbee@@@
doodle plane@
Burger queen world@
more food@
doodle jump hop the movie@
pocket frogs
blupt
harbor havoc 3d free@
create shake Xmas tree@
hungry shark@
virtual table tennis pro@
diamond
maker系列
UNO free@
pop gems
bumpling free
jump and fly@
super world adventures
mega jump
line birds
pop star lite
coin dozer@
僵尸农场@
五子棋
小熊推金币
爱死祖马
fruit ninja lite
黄金矿工2免费
qq斗地主@@@
qq餐厅
水果连连看
破坏者2
run,run,chiken
city story
turtle fly
愤怒的船长
萝莉快跑@
十滴水
一起动手做美食@
拯救种子
极品GT跑车
曲奇制作
愤怒的小球
高比快乐屋
doodle fill
clowning around
shape shift
fall down 3d
paracute
around the world in 80 days
the flufies
jewel battle
pickn stix classic@
canimal triple@
meon
super sheep tap
smack gugl@
bacterial war hd
the rainy day 2
time geeks find all!
graffiti ball
we are hungry
kosmo spin
ninjatown trees...@
sneak out@
to-Fu the trials of chi@
spidey riley
supersonic hd
有一些名字不全,有一些我可能是在限免时下的,这些都望楼主谅解啦。。。还有,特别推荐的名字后有3个"@",那些是非常值得试试玩的!!!5个"@",就是绝对好玩的的了!!!!!
望对楼主有帮助。