请用PYTHON编一个小游戏,如五子棋,连连看,贪吃蛇,扫雷,计算器等等
这些游戏都不小啊,很体现功力的。贪吃蛇好象看到过C语言版本的,python的应该了有。
连连看游戏源码 连连看小游戏代码
连连看游戏源码 连连看小游戏代码
不过很多需要先安装py包的。
五子棋、贪吃蛇、扫雷、方块、坦克大战、FlappyBird,
求“连连看”flash在线小游戏的源代码
默认登陆账号:Admin
默 认 密 码: 123456
,等级不到
可以给我吗连连看JAVA源代码是什么?
importjax.swing.;x0dx0aimportja.awt.;x0dx0aimportja.awt.nt.;x0dx0apublicclasslianliankanimplementsActionListenerx0dx0a{x0dx0aJFramemainFrame;//主面板x0dx0aContainerthisContainer;x0dx0aJPanelcenterPanel,southPanel,northPanel;//子面板x0dx0aJButtondiamondsButton[][]=newJButton[6][5];//游戏按钮数组x0dx0aJButtonexitButton,resetButton,newlyButton;//退出,重列,重新开始按钮x0dx0aJLabelfractionLable=newJLabel("0");//分数标签x0dx0aJButtonfirstButton,secondButton;//分别记录两次被选中的按钮x0dx0aintgrid[][]=newint[8][7];//储存游戏按钮位置x0dx0astaticbooleanpressInformation=false;//判断是否有按钮被选中x0dx0aintx0=0,y0=0,x=0,y=0,fristMsg=0,secondMsg=0,validateLV;//游戏按钮的位置坐标x0dx0ainti,j,k,n;//消除方法控制x0dx0apublicvoidinit(){x0dx0amainFrame=newJFrame("JKJ连连看");x0dx0athisContainer=mainFrame.getContentPane();x0dx0athisContainer.setLayout(newBorderLayout());x0dx0acenterPanel=newJPanel();x0dx0asouthPanel=newJPanel();x0dx0anorthPanel=newJPanel();x0dx0athisContainer.add(centerPanel,"Center");x0dx0athisContainer.add(southPanel,"South");x0dx0athisContainer.add(northPanel,"North");x0dx0acenterPanel.setLayout(newGridLayout(6,5));x0dx0afor(intcols=0;cols=0){x0dx0acols=(int)(Math.random()6+1);x0dx0arows=(int)(Math.random()5+1);x0dx0awhile(grid[cols][rows]!=0){x0dx0acols=(int)(Math.random()6+1);x0dx0arows=(int)(Math.random()5+1);x0dx0a}x0dx0athis.grid[cols][rows]=se[n];x0dx0an--;x0dx0a}x0dx0amainFrame.setVisible(false);x0dx0apressInformation=false;//这里一定要将按钮点击信息归为初始x0dx0ainit();x0dx0afor(inti=0;ij){//如果第二个按钮的Y坐标大于空按钮的Y坐标说明按钮在第二按钮左边x0dx0afor(i=y-1;i>=j;i--){//判断第二按钮左侧直到按钮中间有没有按钮x0dx0aif(grid[x][i]!=0){x0dx0ak=0;x0dx0abreak;x0dx0a}x0dx0aelse//K=1说明通过了次验证x0dx0a}x0dx0aif(k==1){x0dx0alinePassOne();x0dx0a}x0dx0a}x0dx0aif(yx){x0dx0afor(n=x0;n>=x+1;n--){x0dx0aif(grid[n][j]!=0){x0dx0ak=0;x0dx0abreak;x0dx0a}x0dx0aif(grid[n][j]==0&&n==x+1){x0dx0aremove();x0dx0a}x0dx0a}x0dx0a}x0dx0a}x0dx0a}x0dx0afor(i=0;ii){x0dx0afor(j=x-1;j>=i;j--){x0dx0aif(grid[j][y]!=0){x0dx0ak=0;x0dx0abreak;x0dx0a}x0dx0aelsex0dx0a}x0dx0aif(k==1){x0dx0arowPassOne();x0dx0a}x0dx0a}x0dx0aif(xy){x0dx0afor(n=y0;n>=y+1;n--){x0dx0aif(grid[i][n]!=0){x0dx0ak=0;x0dx0abreak;x0dx0a}x0dx0aif(grid[i][n]==0&&n==y+1){x0dx0aremove();x0dx0a}x0dx0a}x0dx0a}x0dx0a}x0dx0a}x0dx0a}x0dx0a}x0dx0apublicvoidlinePassOne(){x0dx0aif(y0>j){//按钮同行空按钮在左边x0dx0afor(i=y0-1;i>=j;i--){//判断按钮同左侧空按钮之间有没按钮x0dx0aif(grid[x0][i]!=0){x0dx0ak=0;x0dx0abreak;x0dx0a}x0dx0aelse//K=2说明通过了第二次验证x0dx0a}x0dx0a}x0dx0aif(y0i){x0dx0afor(j=x0-1;j>=i;j--){x0dx0aif(grid[j][y0]!=0){x0dx0ak=0;x0dx0abreak;x0dx0a}x0dx0aelsex0dx0a}x0dx0a}x0dx0aif(x0给个连连看算法或源码,C#,或JAV的都可以?
/
连连看游戏C语言源代码
/#include
#include
#include
#include
#include
#define false 0/ ---------------------全局变量------------------------------------ /
int BkGndColor=BLACK;
int BorderColor=LIGHTGRAY;
int LineColor=LIGHTBLUE;/ 消除一对方块时时候的连线颜色 /
/ Pb - ProgressBar /
int PbColor=LIGHTGREEN;
int PbY=4;
int PbHeight=4;
int PbValue; / 进度条百分比,初始值为100./
long StartTime; / 开始时间的秒数,只统计分钟,秒 /
long TotalTime; / 游戏总共的秒数!,// BoardDatas: a all-size board /
/ Board[x][y][0] - 0:empty, 1:filled /
/ Board[x][y][1] - cell's key; /
unsigned char Board[10][10][2];
int CellSize=30;
int BoardX=20;
int BoardY=60;
int BoardWidth=10;
int BoardHeight=10;
int CellColor=WHITE;
int SelColor=BLUE; / selCell's border rect color /
int CurColor=RED; / curCell's border rect color /
int EraColor=CYAN; / 用于擦除cell的颜色!/
int PairsCount; / how much pairs we he put on board // 用于存储逻辑坐标(索引) /
typedef struct _tagCELL
{char x;
char y;
} CELL;CELL selCell,curCell;/缓存前一个被选中的位置以及当前所处位置!//Scan Codes Define/
enum KEYCODES
{K_ESC =0x011b,
K_UP =0x4800, / upward arrow /
K_LEFT =0x4b00,
K_DOWN =0x5000,
K_RIGHT =0x4d00,
K_SPACE =0x3920,
K_P =0x1970,
K_RETURN =0x1c0d, / Enter /
}; / ---------------------函数列表------------------------------------ /
void InitGame(char bgiPath);
void PlayGame();
void QuitGame();
void InitProgressBar();
void UpdateProgressBar(int percent);
void DrawCell(int key,int x,int y,int color);
void EraseCell(int x,int y);
void DrawBorderRect(CELL c,int color);
void DrawGameOver(char );
int GetKeyCode();
int FindPath(CELL c1,CELL c2);
/绘制消除方块时候的连接路径!,用指定颜色!/
void DrawPath(int x1,int y1,int x2,int y2,int x3,int y3,int x4,int y4,int color);/ ----------------------函数实现----------------------------------- // ----------------------[ 核心算法 ]---------------------------------
先进行水平方向判断,找出两点所在的水平直线活动范围,
算出这两条线段在垂直方向的共同区域!!!,
遍历该区域判断能否在两线段间架起公垂线,能则两点连接上;
接着进行垂直方向判断,类同。无论两点在不在一条直线上,
都能使用该算法,因为两点同线只是两点作为矩形对角点的特例而已。
// 找到两个CELL之间的路径,成功返回true /
int FindPath(CELL c1,CELL c2)
{int i,j,path,min1,max1,min2,max2,left,right,top,bottom;
/---------------(0)判断是否点中相同块! ------------/
if(Board[c1->x][c1->y][1] != Board[c2->x][c2->y][1])
return false;
/---------------(1)查找水平方向公共区域!-----------/
min1=max1=c1->x;
min2=max2=c2->x;
while(min1-1>=0 && Board[min1-1][c1->y][0]==0) min1--;
while(min2-1>=0 && Board[min2-1][c2->y][0]==0) min2--;
left=max(min1,min2); / 左边界 /
while(max1+1
while(max2+1
right=min(max1,max2); / 右边界 / / 检查两条水平线之间是否有公垂线连通!/
/ 可以在边缘连通 /
if(left==0)
{/ 左边缘连通 /
DrawPath(c1->x,c1->y, -1,c1->y, -1,c2->y, c2->x,c2->y, LineColor);
delay(6000);
DrawPath(c1->x,c1->y, -1,c1->y, -1,c2->y, c2->x,c2->y, BkGndColor);/插除线条!/
return true;
}if(right==(BoardWidth-1))
{DrawPath(c1->x,c1->y, BoardWidth,c1->y, BoardWidth,c2->y, c2->x,c2->y, LineColor);
delay(6000);
DrawPath(c1->x,c1->y, BoardWidth,c1->y, BoardWidth,c2->y, c2->x,c2->y, BkGndColor);/插除线条!/
return true;
} for(i=left;i<=right;i++)
{path=0;/统计垂直的公垂线长度!/
for(j=min(c1->y,c2->y)+1;j
{path+=Board[i][j][0];
if(path>0) break;
}if(path==0)
{DrawPath(c1->x,c1->y, i,c1->y, i,c2->y, c2->x,c2->y, LineColor);
delay(6000);
DrawPath(c1->x,c1->y, i,c1->y, i,c2->y, c2->x,c2->y, BkGndColor);/插除线条!/
return true;
}} /---------------(2)查找垂直方向公共区域!-----------/
min1=max1=c1->y;
min2=max2=c2->y;
while(min1-1>=0 && Board[c1->x][min1-1][0]==0) min1--;
while(min2-1>=0 && Board[c2->x][min2-1][0]==0) min2--;
top=max(min1,min2);
while(max1+1
while(max2+1
bottom=min(max1,max2); / 检查两条垂直线之间是否有公垂线连通!/
/ 可以在边缘连通 /
if(top==0)
{/ 同在顶端消除 /
DrawPath(c1->x,c1->y, c1->x,-1, c2->x,-1, c2->x,c2->y, LineColor);
delay(6000);
DrawPath(c1->x,c1->y, c1->x,-1, c2->x,-1, c2->x,c2->y, BkGndColor);/插除线条!/
return true;
}if(bottom==(BoardHeight-1))
{DrawPath(c1->x,c1->y, c1->x,BoardHeight, c2->x,BoardHeight, c2->x,c2->y, LineColor);
delay(6000);
DrawPath(c1->x,c1->y, c1->x,BoardHeight, c2->x,BoardHeight, c2->x,c2->y, BkGndColor);/插除线条!/
return true;
} for(j=top;j<=bottom;j++)
{path=0;/统计水平的公垂线长度!/
for(i=min(c1->x,c2->x)+1; i
{path+=Board[i][j][0];
if(path>0) break;
}if(path==0)
{/ 水平公垂线 /
DrawPath(c1->x,c1->y, c1->x,j, c2->x,j, c2->x,c2->y, LineColor);
delay(6000);
DrawPath(c1->x,c1->y, c1->x,j, c2->x,j, c2->x,c2->y, BkGndColor);/插除线条!/
return true;
}} / 到达这里说明没有任何通路 /
return false;
}/Get Key Code /
int GetKeyCode()
{int key=0;
if(bioskey(1))
{key=bioskey(0);
}return key;
}/绘制消除方块时候的连接路径!,用指定颜色!,坐标是CELL逻辑坐标!/
void DrawPath(int x1,int y1,int x2,int y2,int x3,int y3,int x4,int y4,int color)
{setcolor(color);
moveto(BoardX+CellSize/2+CellSizex1,BoardY+CellSize/2+CellSizey1);
lineto(BoardX+CellSize/2+CellSizex2,BoardY+CellSize/2+CellSizey2);
lineto(BoardX+CellSize/2+CellSizex3,BoardY+CellSize/2+CellSizey3);
lineto(BoardX+CellSize/2+CellSizex4,BoardY+CellSize/2+CellSizey4);
}/ congratulations ,the user has success finish the ! /
void DrawGameOver(char )
{/计算棋盘的中心点/
int cx=BoardX+CellSizeBoardWidth/2;
int cy=BoardY+CellSizeBoardHeight/2;
struct textsettingstype textInfos;
/获取此前的文字信息/
gettextsettings(&textInfos);
setcolor(DARKGRAY);
setfillstyle(SOLID_FILL,BLUE);
/ 文字居中 /
rectangle(cx-102,cy-22,cx+102,cy+22);
floodfill(cx,cy,DARKGRAY);
rectangle(cx-100,cy-20,cx+100,cy+20);
settextjustify(CENTER_TEXT,CENTER_TEXT);
setcolor(LIGHTBLUE);
outtextxy(cx,cy,);
/restore orignal text settings /
settextjustify(textInfos.horiz, textInfos.vert);
}/ draw a focus rect on the cell with the color /
/ 用制定颜色绘制一个选中的外边框 /
void DrawBorderRect(CELL c,int color)
{setcolor(color);
rectangle(BoardX+(c->x)CellSize+1, BoardY+(c->y)CellSize+1, BoardX+(c->x+1)CellSize-2, BoardY+(c->y+1)CellSize-2);
rectangle(BoardX+(c->x)CellSize, BoardY+(c->y)CellSize, BoardX+(c->x+1)CellSize-1, BoardY+(c->y+1)CellSize-1);
}/ 在x,y处用指定颜色绘制键为key的 CELL,key在2,3,4,5,6,7,8,9,10,11之间随机 /
void DrawCell(int key,int x,int y,int color)
{setcolor(color);
rectangle(BoardX+xCellSize+2, BoardY+yCellSize+2, BoardX+(x+1)CellSize-3, BoardY+(y+1)CellSize-3);
setfillstyle(key, color);
floodfill(BoardX+xCellSize+3, BoardY+yCellSize+3,color);
}/ 擦除CELL /
void EraseCell(int x,int y)
{setcolor(EraColor);
rectangle(BoardX+xCellSize+2, BoardY+yCellSize+2, BoardX+(x+1)CellSize-3, BoardY+(y+1)CellSize-3);
setfillstyle(SOLID_FILL, BkGndColor);
floodfill(BoardX+xCellSize+3, BoardY+yCellSize+3,EraColor);
setcolor(BkGndColor);
rectangle(BoardX+xCellSize+2, BoardY+yCellSize+2, BoardX+(x+1)CellSize-3, BoardY+(y+1)CellSize-3);
}/ 初始化进度条 /
void InitProgressBar()
{int width=CellSizeBoardWidth;
/ progress bar border rect /
setcolor(BorderColor);
rectangle(BoardX-2,PbY-2,BoardX+width+2,PbY+PbHeight+2); / draw a value = progress bar /
setcolor(PbColor);
rectangle(BoardX,PbY,BoardX+width,PbY+PbHeight);
setfillstyle(SOLID_FILL,PbColor);
floodfill(BoardX+1,PbY+1,PbColor);
}
求html5 canvas制作的连连看源代码。详细分析一下 物体间如何判断连线的
为了用DOM做2D游戏,你基本上要动态地调整元素风格,以便在页面上移动它。虽然有些时候DOM修改是很好的,但这一次我将重点介绍使用HTML5Canvas来制作图像,因为对于现代浏览器,它是灵活的。页面设置首先,你要创建一个HTML页面,其中包含如下canvas标签:如果你载入以上代码,当然什么也不会出现。那是因为虽然我们有一个canvas标签,但我们还没在上面绘制任何东西。我们来添加一些简单的canvas命令来绘制小箱子吧。