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文件就被反向工程顯示出來了!