android连连看游戏源码
㈠ 连连看的游戏,用的是什么原理算法,求指教一二
连连看核心算法如下:
#include <iostream>
using namespace std;
int board[102][102];
int nRowCount, nColCount;
bool isHorizontalLineValid(int c1, int c2, int r)
{
if(c1>c2) // 交换 C1, C2
{
c1 ^= c2 ^= c1 ^= c2;
}
for(int i=c1+1; i<=c2-1; i++)
{
if(board[r][i]!=0)
return false;
}
return true;
}
bool isVerticalLineValid(int r1, int r2, int c)
{
if(r1>r2) // 交换 r1, r2
{
r1 ^= r2 ^= r1 ^= r2;
}
for(int i=r1+1; i<=r2-1; i++)
{
if(board[i][c]!=0)
return false;
}
return true;
}
bool check(int r1, int c1, int r2, int c2)
{
// 如果该位置没有棋子或者两棋子不一致,则返回假
if(board[r1][c1]==0 || board[r2][c2]==0 || board[r1][c1]!=board[r2][c2])
return false;
// 两条水平线和一条垂直线
for(int i=0; i<=nColCount+1; i++)
{
if( (i!=c1 && board[r1][i]!=0) || (i!=c2 && board[r2][i]!=0) )
continue;
if( isHorizontalLineValid(i, c1, r1) &&
isVerticalLineValid(r1, r2, i) &&
isHorizontalLineValid(i, c2, r2))
{
board[r1][c1] = board[r2][c2] = 0;
return true;
}
}
// 两条垂直线和一条水平线
for(int i=0; i<=nRowCount+1; i++)
{
if( (i!=r1 && board[i][c1]!=0) || (i!=r2 && board[i][c2]!=0) )
continue;
if( isVerticalLineValid(i, r1, c1) &&
isHorizontalLineValid(c1, c2, i) &&
isVerticalLineValid(i, r2, c2))
{
board[r1][c1] = board[r2][c2] = 0;
return true;
}
}
return false;
}
int main(int argc, char** argv)
{
int nRound, nSuccess;
int x1, y1, x2, y2;
// 输入棋盘数据
cin >> nRowCount >> nColCount;
for(int i = 1; i <= nRowCount; ++i)
for(int j = 1; j <= nColCount; ++j)
cin >> board[i][j];
cin >> nRound;
for(int i = 0; i < nRound; ++i)
{
cin >> x1 >> y1 >> x2 >> y2;
if( check(x1, y1, x2, y2) )
cout << "Yes\n";
else
cout << "No\n";
}
system("pause");
return 0;
}
测试数据:
3 4
1 1 2 2
3 3 4 4
2 2 1 1
6
1 1 1 2
1 3 1 4
2 1 2 2
2 3 2 4
3 1 3 2
3 3 3 4
c1 ^= c2 ^= c1 ^= c2;语句中对于a^=b就相当于a=a^b,即代表a与b取位异或运算之后再把值赋给a的。楼主如果觉得还行的话请加点分的哦。
㈡ 求大神给一份android studio的连连看游戏的源代码
网页链接 这里很多自己找找
㈢ 求一个安卓开发小游戏源代码,临时交作业用
package com.fiveChess;
import android.app.Activity;
import android.os.Bundle;
import android.view.Display;
import android.view.Menu;
import android.view.MenuItem;
import android.view.Window;
import android.view.WindowManager;
public class MainActivity extends Activity {
GameView gameView = null;
@Override
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
this.getWindow().requestFeature(Window.FEATURE_NO_TITLE);
this.getWindow().setFlags(WindowManager.LayoutParams.FLAG_FULLSCREEN,WindowManager.LayoutParams.FLAG_FULLSCREEN);
Display display = this.getWindowManager().getDefaultDisplay();
gameView = new GameView(this,display.getWidth(),display.getHeight());
setContentView(gameView);
}
@Override
public boolean onCreateOptionsMenu(Menu menu) {
menu.add("重新开始").setIcon(android.R.drawable.ic_menu_myplaces);
menu.add("退出");
return super.onCreateOptionsMenu(menu);
}
@Override
public boolean onOptionsItemSelected(MenuItem item) {
if(item.getTitle().equals("重新开始")){
gameView.canPlay = true;
gameView.chess = new int[gameView.row][gameView.col];
gameView.invalidate();
}else if(item.getTitle().equals("退出")){
finish();
}
return super.onOptionsItemSelected(item);
}
}
package com.fiveChess;
import android.app.AlertDialog;
import android.content.Context;
import android.content.DialogInterface;
import android.graphics.Canvas;
import android.graphics.Color;
import android.graphics.Paint;
import android.graphics.Paint.Style;
import android.view.MotionEvent;
import android.view.View;
public class GameView extends View {
Context context = null;
int screenWidth,screenHeight;
String message = "";//提示轮到哪个玩家
int row,col; //划线的行数和列数
int stepLength = 30;//棋盘每格间距
int[][] chess = null;//0代表没有棋子,1代表是黑棋,2代表白旗
boolean isBlack = true;
boolean canPlay = true;
public GameView(Context context,int screenWidth,int screenHeight) {
super(context);
this.context = context;
this.screenWidth = screenWidth;
this.screenHeight = screenHeight;
this.message = "黑棋先行";
row = (screenHeight-50)/stepLength+1;
col = (screenWidth-10)/stepLength+1;
chess = new int[row][col];
}
@Override
protected void onDraw(Canvas canvas) {
super.onDraw(canvas);
Paint paint = new Paint();
paint.setColor(Color.WHITE);
canvas.drawRect(0, 0, screenWidth, screenHeight, paint);//画背景
paint.setColor(Color.BLUE);
paint.setTextSize(25);
canvas.drawText(message, (screenWidth-100)/2, 30, paint);//画最顶层的字
paint.setColor(Color.BLACK);
//画棋盘
for(int i=0;i<row;i++){
canvas.drawLine(10, 50+i*stepLength, 10+(col-1)*stepLength, 50+i*stepLength, paint);
}
for(int i=0;i<col;i++){
canvas.drawLine(10+i*stepLength,50,10+i*stepLength,50+(row-1)*stepLength, paint);
}
for(int r=0;r<row;r++){
for(int c=0;c<col;c++){
if(chess[r][c] == 1){
paint.setColor(Color.BLACK);
paint.setStyle(Style.FILL);
canvas.drawCircle(10+c*stepLength, 50+r*stepLength, 10, paint);
}else if(chess[r][c] == 2){
//画白棋
paint.setColor(Color.WHITE);
paint.setStyle(Style.FILL);
canvas.drawCircle(10+c*stepLength, 50+r*stepLength, 10, paint);
paint.setColor(Color.BLACK);
paint.setStyle(Style.STROKE);
canvas.drawCircle(10+c*stepLength, 50+r*stepLength, 10, paint);
}
}
}
}
@Override
public boolean onTouchEvent(MotionEvent event) {
if(!canPlay){return false;}
float x = event.getX();
float y = event.getY();
int r = Math.round((y-50)/stepLength);
int c = Math.round((x-10)/stepLength);
if(r<0 || r>row-1 || c<0 || c>col-1){return false;}
if(chess[r][c]!=0){return false;}//若有棋子则不再画棋子了
if(isBlack){
chess[r][c] = 1;
isBlack = false;
message = "轮到白棋";
}else{
chess[r][c] = 2;
isBlack = true;
message = "轮到黑棋";
}
invalidate();
if(judge(r, c,0,1)) return false;
if(judge(r, c,1,0)) return false ;
if(judge(r, c,1,1)) return false;
if(judge(r, c,1,-1)) return false;
return super.onTouchEvent(event);
}
private boolean judge(int r, int c,int x,int y) {//r,c表示行和列,x表示在y方向上的偏移,y表示在x方向上的偏移
int count = 1;
int a = r;
int b = c;
while(r>=0 && r<row && c>=0 && c<col && r+x>=0 && r+x<row && c+y>=0 && c+y<col && chess[r][c] == chess[r+x][c+y]){
count++;
if(y>0){
c++;
}else if(y<0){
c--;
}
if(x>0){
r++;
}else if(x<0){
r--;
}
}
while(a>=0 && a<row && b>=0 && b<col && a-x>=0 && a-x<row && b-y>=0 && b-y<col && chess[a][b] == chess[a-x][b-y]){
count++;
if(y>0){
b--;
}else if(y<0){
b++;
}
if(x>0){
a--;
}else if(x<0){
a++;
}
}
if(count>=5){
String str = "";
if(isBlack){
str = "白棋胜利";
}else{
str = "黑棋胜利";
}
new AlertDialog.Builder(context).setTitle("游戏结束").setMessage(str).setPositiveButton("重新开始", new DialogInterface.OnClickListener() {
@Override
public void onClick(DialogInterface dialog, int which) {
chess = new int[row][col];
invalidate();
}
}).setNegativeButton("观看棋局", new DialogInterface.OnClickListener() {
@Override
public void onClick(DialogInterface dialog, int which) {
canPlay = false;
}
}).show();
return true;
}
return false;
}
}
PS:五子棋,无需图片,直接在程序里画出来的。注意我发的是两个文件,一个activity,一个类文件,别把它当成一个文件了
㈣ 游戏软件怎么查看源代码
游戏都是进行过编译,加密的无法看到源代码。如果你想查看的游戏是开源的,可以到游戏的开源网站进行查看。
查看APP应用的源代码的具体方法步骤如下:
1、首先在电脑内下载并安装获取网页源码app。
2、然后单击打开网页源码APP并在APP中的输入框内输入想要查看的网址,再在界面内找到GO选项单并单击。
3、单击后等待APP最后加载3秒就可以成功的获取APP源代码并查看了。
Android 系统源代码多大
是指sdk的源码,还是android操作系统的源码,不过都有10G左右,另外sdk的源码是用git管理的,一次下载后,用git check就可以切换到各个版本。
Android SDK是用于开发Android上java应用程序的,另外发布Android NDK,可以添加一些C语言写的链接库,至于Linux代码,可以在Android源代码中找到(SDK程序中只有编译好的测试映像)。
应用程序开发用不到Linux代码(搞嵌入式开发才会用到,而SDK不负责底层开发)。
㈤ 如何用JAVA 编写一个连连看游戏全程设计
刚试了。。测试通过。。
importjavax.swing.*;
importjava.awt.*;
importjava.awt.event.*;
publicclass LianLianKan implements ActionListener {
JFrame mainFrame; // 主面板
Container thisContainer;
JPanel centerPanel, southPanel, northPanel; //子面板
JButton diamondsButton[][] = newJButton[6][5];// 游戏按钮数组
JButton exitButton, resetButton, newlyButton;// 退出,重列,重新开始按钮
JLabel fractionLable = newJLabel("0"); // 分数标签
JButton firstButton, secondButton; // 分别记录两次被选中的按钮
// 储存游戏按钮位置(这里其实只要6行,5列。但是我们用了8行,7列。是等于在这个面板按钮的周围还围
//了一层是0的按钮,这样就可以实现靠近面板边缘的两个按钮可以消去)
int grid[][] = new int[8][7];
static boolean pressInformation = false; // 判断是否有按钮被选中
int x0 = 0, y0 = 0, x = 0, y = 0, fristMsg =0, secondMsg = 0, validateLV; // 游戏按钮的位置坐标
int i, j, k, n;// 消除方法控制
public void init() {
mainFrame = new JFrame("JKJ连连看");
thisContainer = mainFrame.getContentPane();
thisContainer.setLayout(new BorderLayout());
centerPanel = new JPanel();
southPanel = new JPanel();
northPanel = new JPanel();
thisContainer.add(centerPanel,"Center");
thisContainer.add(southPanel,"South");
thisContainer.add(northPanel,"North");
centerPanel.setLayout(new GridLayout(6, 5));
for (int cols = 0; cols < 6; cols++) {
for (int rows = 0; rows < 5; rows++) {
diamondsButton[cols][rows] = newJButton(String
.valueOf(grid[cols + 1][rows + 1]));
diamondsButton[cols][rows].addActionListener(this);
centerPanel.add(diamondsButton[cols][rows]);
}
}
exitButton = new JButton("退出");
exitButton.addActionListener(this);
resetButton = new JButton("重列");
resetButton.addActionListener(this);
newlyButton = new JButton("再来一局");
newlyButton.addActionListener(this);
southPanel.add(exitButton);
southPanel.add(resetButton);
southPanel.add(newlyButton);
fractionLable.setText(String.valueOf(Integer.parseInt(fractionLable
.getText())));
northPanel.add(fractionLable);
mainFrame.setBounds(280, 100, 500, 450);
mainFrame.setVisible(true);
mainFrame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
}
public void randomBuild() {
int randoms, cols, rows;
for (int twins = 1; twins <= 15; twins++){//一共15对button,30个
randoms = (int) (Math.random() * 25 +1);//button上的数字
for (int alike = 1; alike <= 2; alike++){
cols = (int) (Math.random() * 6 + 1);
rows = (int) (Math.random() * 5 + 1);
while (grid[cols][rows] != 0) {//等于0说明这个空格有了button
cols = (int) (Math.random() * 6 + 1);
rows = (int) (Math.random() * 5 + 1);
}
this.grid[cols][rows] = randoms;
}
}
}
public void fraction() {
fractionLable.setText(String.valueOf(Integer.parseInt(fractionLable
.getText()) + 100));
}
public void reload() {
int save[] = new int[30];
int n = 0, cols, rows;
int grid[][] = new int[8][7];
for (int i = 0; i <= 6; i++) {
for (int j = 0; j <= 5; j++) {
if (this.grid[i][j] != 0) {
save[n] = this.grid[i][j];//记下每个button的数字
n++;//有几个没有消去的button
}
}
}
n = n - 1;
this.grid = grid;
while (n >= 0) {//把没有消去的button重新放一次
cols = (int) (Math.random() * 6 + 1);
rows = (int) (Math.random() * 5 + 1);
while (grid[cols][rows] != 0) {
cols = (int) (Math.random() * 6 + 1);
rows = (int) (Math.random() * 5 + 1);
}
this.grid[cols][rows] = save[n];
n--;
}
mainFrame.setVisible(false);
pressInformation = false; // 这里一定要将按钮点击信息归为初始
init();
for (int i = 0; i < 6; i++) {
for (int j = 0; j < 5; j++) {
if (grid[i + 1][j + 1] == 0)
diamondsButton[i][j].setVisible(false);
}
}
}
public void estimateEven(int placeX, intplaceY, JButton bz) {
if (pressInformation == false) {
x = placeX;
y = placeY;
secondMsg = grid[x][y];
secondButton = bz;
pressInformation = true;
} else {
x0 = x;
y0 = y;
fristMsg = secondMsg;
firstButton = secondButton;
x = placeX;
y = placeY;
secondMsg = grid[x][y];
secondButton = bz;
if (fristMsg == secondMsg &&secondButton != firstButton) {
xiao();
}
}
}
public void xiao() { // 相同的情况下能不能消去。仔细分析,不一条条注释
if ((x0 == x && (y0 == y + 1 || y0 ==y - 1))
|| ((x0 == x + 1 || x0 == x - 1) &&(y0 == y))) { // 判断是否相邻
remove();
} else {
for (j = 0; j < 7; j++) {
if (grid[x0][j] == 0) { // 判断和第一个按钮同行的哪个按钮为空
//如果找到一个为空的,就按列值的三种情况比较第二个按钮与空按钮的位置
if (y > j) {//第二个按钮在空按钮右边
for (i = y - 1; i >= j; i--) { //检测从第二个按钮横向左边到空格所在列为止是否全是空格
if (grid[x][i] != 0) {
k = 0;
break;//存在非空格的就退出,这一退出就不可能k==2了,所以就会到下而215行出同理的判断列
} else {
k = 1;
} // K=1说明全是空格通过了第一次验证,也就是从第二个按钮横向左边到空格所在列为止全是空格
}
if (k == 1) {
linePassOne();//进入第二次验证,也就是从第一个按钮到它同行的空格之间的空格判断
}
}
if (y < j) { // 第二个按钮在空按钮左边
for (i = y + 1; i <= j; i++) {//检测从第二个按钮横向右边到空格所在列为止是否全是空格
if (grid[x][i] != 0) {
k = 0;
break;
} else {
k = 1;
}
}
if (k == 1) {
linePassOne();
}
}
if (y == j) {//第二个按钮和空按钮同列
linePassOne();
}
}
//第三次检测,检测确定为空的第j列的那个按钮竖向到第二个按钮,看是不是有按钮
if (k == 2) {
if (x0 == x) {//第一,二按钮在同行
remove();
}
if (x0 < x) {//第一按钮在第二按钮下边
for (n = x0; n <= x - 1; n++) {//从空按钮竖向到第二个按钮所在行是否有按钮
if (grid[n][j] != 0) {
k= 0;
break;
}
//没有按钮,说明这条路经就通了
if (grid[n][j] == 0 && n == x -1) {
remove();
}
}
}
if (x0 > x) {//第一按钮在第二按钮上边
for (n = x0; n >= x + 1; n--) {
if (grid[n][j] != 0) {
k = 0;
break;
}
if (grid[n][j] == 0 && n == x +1) {
remove();
}
}
}
}
}//-------------------------------------for
//当上面的检测与第一个按钮同行的空格按钮失败后(不能找到与第二个按钮的相连路经),下面就执行
//检测与第一个按钮同列的空格按钮
for (i = 0; i < 8; i++) {
if (grid[i][y0] == 0) {// 判断和第一个按钮同列的哪个按钮为空
if (x > i) {//第二个按钮在这个空按钮的下面
for (j = x - 1; j >= i; j--) {
if (grid[j][y] != 0) {
k = 0;
break;
} else {
k = 1;
}
}
if (k == 1) {
rowPassOne();
}
}
if (x < i) {//第二个按钮在这个空按钮的上面
for (j = x + 1; j <= i; j++) {
if (grid[j][y] != 0) {
k = 0;
break;
} else {
k = 1;
}
}
if (k == 1) {
rowPassOne();
}
}
if (x == i) {//第二个按钮与这个空按钮同行
rowPassOne();
}
}
if (k == 2) {
if (y0 == y) {//第二个按钮与第一个按钮同列
remove();
}
if (y0 < y) {//第二个按钮在第一个按钮右边
for (n = y0; n <= y - 1; n++) {
if (grid[i][n] != 0) {
k = 0;
break;
}
if (grid[i][n] == 0 && n == y -1) {
remove();
}
}
}
if (y0 > y) {//第二个按钮在第一个按钮左边
for (n = y0; n >= y + 1; n--) {
if (grid[i][n] != 0) {
k = 0;
break;
}
if (grid[i][n] == 0 && n == y +1) {
remove();
}
}
}
}
}//--------------------------------for
}//-------------else
}//------------xiao
public void linePassOne() {
if (y0 > j) { // 第一按钮同行空按钮在左边
for (i = y0 - 1; i >= j; i--) { // 判断第一按钮同左侧空按钮之间有没按钮
if (grid[x0][i] != 0) {
k = 0;
break;
} else {
k = 2;
} // K=2说明通过了第二次验证
}
}
if (y0 < j) { // 第一按钮同行空按钮在右边
for (i = y0 + 1; i <= j; i++) {
if (grid[x0][i] != 0) {
k = 0;
break;
} else {
k = 2;
}
}
}
}
public void rowPassOne() {
if (x0 > i) {//第一个按钮在与它同列的那个空格按钮下面
for (j = x0 - 1; j >= i; j--) {
if (grid[j][y0] != 0) {
k = 0;
break;
} else {
k = 2;
}
}
}
if (x0 < i) {//第一个按钮在与它同列的那个空格按钮上面
for (j = x0 + 1; j <= i; j++) {
if (grid[j][y0] != 0) {
k = 0;
break;
} else {
k = 2;
}
}
}
}
public void remove() {
firstButton.setVisible(false);
secondButton.setVisible(false);
fraction();
pressInformation = false;
k = 0;
grid[x0][y0] = 0;
grid[x][y] = 0;
}
public void actionPerformed(ActionEvent e) {
if (e.getSource() == newlyButton) {
int grid[][] = new int[8][7];
this.grid = grid;
randomBuild();
mainFrame.setVisible(false);
pressInformation = false;
init();
}
if (e.getSource() == exitButton)
System.exit(0);
if (e.getSource() == resetButton)
reload();
for (int cols = 0; cols < 6; cols++) {
for (int rows = 0; rows < 5; rows++) {
if (e.getSource() ==diamondsButton[cols][rows])
estimateEven(cols + 1, rows + 1,diamondsButton[cols][rows]);
}
}
}
public static void main(String[] args) {
LianLianKan llk = new LianLianKan();
llk.randomBuild();
llk.init();
}
}
㈥ 用C++做连连看,要源代码,能看懂的!!!
VS2005平台开发的,能够进行联机对战。
7*12的排列,排列顺序随机。
代码附带十分形象的说明
㈦ 怎样查看 Android APP源代码
将apk文件拷贝至sdcard上。
命令顺序如下:
进入Android sdk文件夹/tools目录下
输入adb shell
输入su
输入cd data
输入cd app
这时就可以看到你安装的所有的apk文件。输入cp 空格 对应的apk 空格 /sdcard/
这样就将apk文件拷贝出来了。
将apk文件后缀直接变成rar格式,可以看到熟悉的目录结构了,
其中xml文件打开后都是二进制的,无法查看。
这时就用到了一个android4me的AXMLPrinter2工具。(请自行网络搜索)
输入以下命令,将xml文件解析出来
java -jar AXMLPrinter2.jar showtimes_list.xml
此命令是在命令行中查看此showtimes_list.xml
将showtimes_list.xml生成xml文件,则输入以下命令:
java -jar AXMLPrinter2.jar showtimes_list.xml > h.xml
目前进行到这一步,只能看到xml文件的内容,其工程中的java源文件还是看不到,看目录结构下有一个classes.dex文件,我们需要将dex文件变为jar文件。
这里用到了另一个工具dex2jar。(自行搜索下载)
在Windows下解压之后的目录如下图所示:
在命令行中,进入到此目录下:
在Windows下,输入以下命令:
dex2jar.bat c:classes.dex
运行完之后,在C盘会多一个classes.dex.dex2jar.jar文件,此文件就是我们需要的jar文件。
利用jd-gui,将jar文件反向工程为java代码。(请自行搜索下载)
它分为Windows、Linux、和max三个版本,这里我下载的是Windows版本的。
解压之后,双击运行exe文件,选择classes.dex.dex2jar.jar文件,相应的jar文件中的Java文件就被反向工程显示出来了!