2048游戲源碼
Ⅰ 誰會製作2048這樣的游戲勒,只是把數字換成文字,誰有源碼可以分享嗎
2048游戲高分必看攻略技巧圖文教程
http://iphone.18183.com/xinwen/yxxw/201405/118121.html
數字游戲2048怎麼玩超詳細規則玩法攻略說明
http://iphone.18183.com/xinwen/yxxw/201405/118118.html
2048通關技巧必備攻略圖文教程破紀錄SO EASY
http://iphone.18183.com/xinwen/yxxw/201405/114907.html
2048玩家最高分及游戲最大數字是多少詳解
http://iphone.18183.com/xinwen/yxxw/201405/114893.html
2048攻略開局及補救方法技巧圖文教程
http://iphone.18183.com/xinwen/yxxw/201405/112280.html
2048數字游戲怎麼玩技巧攻略玩法介紹
http://iphone.18183.com/xinwen/yxxw/201405/112278.html
Ⅱ 2048游戲(自己做2048)
每次控制所有方塊向同一個方向運動,兩個相同數字的方塊撞在一起之後合並成為他們的和,每次操作之後會在空白的方格處隨機生成一個2或者4,最終得到一個「2048」的方塊就算勝利了。如果16個格子全部填滿並且相鄰的格子都不相同也就是無法移動的話,那就是失敗了。
Ⅲ 求2048朝代版的源代碼
import javax.swing.*;
import java.awt.*;
@SuppressWarnings("serial")
public class Game_block extends JLabel {
private int value;
public Game_block() {
super("go!");
value = 0;
setFont(new Font("font", Font.PLAIN, 40));
setBackground(Color.black);
}
public int getValue() {
return value;
}
public void setValue(int value) {
this.value = value;
String Text = String.valueOf(value);
if (value != 0){
if(value == 2)
setText("夏");
}
if (value != 0){
if(value == 4)
setText("商");
}
if (value != 0){
if(value == 8)
setText("周");
}
if (value != 0){
if(value == 16)
setText("秦");
}
if (value != 0){
if(value == 32)
setText("漢");
}
if (value != 0){
if(value == 64)
setText("三國");
}
if (value != 0){
if(value == 128)
setText("南北朝");
}
if (value != 0){
if(value == 256)
setText("隋");
}
if (value != 0){
if(value == 1024)
setText("五代十國");
}
if (value != 0){
if(value == 2048)
setText("宋遼");
}
if (value != 0){
if(value == 4096)
setText("宋金");
}
if (value != 0){
if(value == 8192)
setText("元");
}
if (value != 0){
if(value == 16384)
setText("明");
}
if (value != 0){
if(value == 32768)
setText("清");
}
if (value != 0){
if(value == 65536)
setText("現代");
}
else
setText("2048");
setColor();
}
public void setColor() {
if (this.value == 0)
setBackground(Color.black);
else if (this.value == 2)
setBackground(new Color(238, 228, 218));
else if (this.value == 4)
setBackground(new Color(248, 232, 248));
else if (this.value == 8)
setBackground(new Color(243, 177, 116));
else if (this.value == 16)
setBackground(new Color(243, 177, 126));
else if (this.value == 32)
setBackground(new Color(248, 149, 90));
else if (this.value == 64)
setBackground(new Color(249, 94, 50));
else if (this.value == 128)
setBackground(new Color(239, 207, 108));
else if (this.value == 256)
setBackground(new Color(239, 207, 99));
else if (this.value == 512)
setBackground(new Color(239, 203, 82));
else if (this.value == 1024)
setBackground(new Color(239, 199, 57));
else if (this.value == 2048)
setBackground(new Color(239, 195, 41));
else if (this.value == 4096)
setBackground(new Color(255, 60, 57));
else if (this.value == 8192)
setBackground(new Color(258, 60, 59));
else if (this.value == 16384)
setBackground(new Color(262, 62, 59));
else if (this.value == 32768)
setBackground(new Color(262, 64, 62));
else if (this.value == 65536)
setBackground(new Color(264, 64, 66));
}
}
______________________________________________________
import java.awt.*;
import java.awt.event.KeyEvent;
import java.awt.event.KeyListener;
import java.awt.event.MouseAdapter;
import java.awt.event.MouseEvent;
import javax.swing.*;
@SuppressWarnings("serial")
public class Game_my2048 extends JFrame implements KeyListener {
Game_block[] block;
JPanel panel;
boolean numFlag;
int moveFlag;
int a ;//a 的引入是為了防止連加的情況出現
public Game_my2048() {
numFlag = true;
moveFlag = 0;
block = new Game_block[16];
setTitle("2048朝代版");
setSize(400, 400);
setLocation(500, 200);
setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
panel = (JPanel) getContentPane();
panel.setLayout(new GridLayout(4, 4, 5, 5));
addBlock();
for (int i = 0; i < 2; i++)
appearBlock();
this.addKeyListener(this);
this.setVisible(true);
}
public void addBlock() {
for (int i = 0; i < 16; i++) {
block[i] = new Game_block();
block[i].setHorizontalAlignment(JLabel.CENTER);
// 不透明
block[i].setOpaque(true);
panel.add(block[i]);
}
}
public void appearBlock() {
while(numFlag) {
int index = (int) (Math.random() * 16);
if (block[index].getValue() == 0) {
if (Math.random() < 0.5)
block[index].setValue(2);
else
block[index].setValue(4);
break;
}
}
}
public void judgeAppear() {
int sum = 0;
for (int i = 0; i < 16; i++) {
if (block[i].getValue() != 0)
sum++;
}
if (sum == 16)
numFlag = false;
}
public void upBlock() {
for (int i = 12; i < 16; i++) {
int index = i;
for (int j = i - 4; j >= i - 12; j -= 4) {
int valueI = block[index].getValue(), valueJ = block[j]
.getValue();
if (valueJ == 0) {
block[index].setValue(0);
block[j].setValue(valueI);
} else {
if (valueI == valueJ) {
block[index].setValue(0);
block[j].setValue(valueI + valueJ);
if (valueI + valueJ == 4096)
win();
numFlag = true;
moveFlag = 0;
} else if (numFlag == false)
moveFlag += 1;
}
index = j;
}
}
}
public void downBlock() {
for (int i = 0; i < 4; i++) {
a = 5;
int index = i;
for (int j = i + 4; j <= i + 12; j += 4) {
int valueI = block[index].getValue(), valueJ = block[j]
.getValue();
if (valueJ == 0) {
block[index].setValue(0);
block[j].setValue(valueI);
} else {
if (valueI == valueJ) {
block[index].setValue(0);
block[j].setValue(valueI + valueJ);
if (valueI + valueJ == 4096)
win();
numFlag = true;
moveFlag = 0;
} else if (numFlag == false)
moveFlag += 1;
}
index = j;
}
}
}
public void rightBlock() {
for (int i = 0; i <= 12; i += 4) {
int index = i;
for (int j = i + 1; j <= i + 3; j++) {
int valueI = block[index].getValue(), valueJ = block[j]
.getValue();
if (valueJ == 0) {
block[index].setValue(0);
block[j].setValue(valueI);
} else {
if (valueI == valueJ) {
block[index].setValue(0);
block[j].setValue(valueI + valueJ);
if (valueI + valueJ == 4096)
win();
numFlag = true;
moveFlag = 0;
} else if (numFlag == false)
moveFlag += 1;
}
index = j;
}
}
}
public void leftBlock() {
for (int i = 3; i <= 15; i += 4) {
int index = i;
for (int j = i - 1; j >= i - 3; j--) {
int valueI = block[index].getValue(), valueJ = block[j]
.getValue();
if (valueJ == 0) {
block[index].setValue(0);
block[j].setValue(valueI);
} else {
if (valueI == valueJ) {
block[index].setValue(0);
block[j].setValue(valueI + valueJ);
if (valueI + valueJ == 4096)
win();
numFlag = true;
moveFlag = 0;
} else if (numFlag == false)
moveFlag += 1;
}
index = j;
}
}
}
@Override
public void keyPressed(KeyEvent e) {
switch (e.getKeyCode()) {
case KeyEvent.VK_UP:
upBlock();
judgeAppear();
appearBlock();
over();
break;
case KeyEvent.VK_DOWN:
downBlock();
judgeAppear();
appearBlock();
over();
break;
case KeyEvent.VK_LEFT:
leftBlock();
judgeAppear();
appearBlock();
over();
break;
case KeyEvent.VK_RIGHT:
rightBlock();
judgeAppear();
appearBlock();
over();
break;
}
}
public void over() {
if (!numFlag && moveFlag >= 36) {
block[4].setText("G");
block[5].setText("A");
block[6].setText("M");
block[7].setText("E");
block[8].setText("O");
block[9].setText("V");
block[10].setText("E");
block[11].setText("R");
block[11].addMouseListener(new MouseAdapter() {
@Override
public void mousePressed(MouseEvent e) {
reStart();
}
});
}
}
public void win() {
block[0].setText("Y");
block[1].setText("O");
block[2].setText("U");
block[13].setText("W");
block[14].setText("I");
block[15].setText("N");
block[15].addMouseListener(new MouseAdapter() {
@Override
public void mousePressed(MouseEvent e) {
reStart();
}
});
}
public void reStart(){
numFlag=true;
moveFlag=0;
for(int i=0;i< 16;i++)
block[i].setValue(0);
for (int i = 0; i < 2; i++)
appearBlock();
}
@Override
public void keyTyped(KeyEvent e) {
}
@Override
public void keyReleased(KeyEvent e) {
}
public static void main(String args[]) {
JFrame.(true);
new Game_my2048();
}
}
__________________________________________________________________________
這個代碼卻少很多功能的
Ⅳ 2048這個游戲怎麼玩
游戲規則很簡單,每次可以選擇上下左右其中一個方向去滑動,每滑動一次,所有的數字方塊都會往滑動的方向靠攏外,系統也會在空白的地方亂數出現一個數字方塊,相同數字的方塊在靠攏、相撞時會相加。系統給予的數字方塊不是2就是4,玩家要想辦法在這小小的16格範圍中湊出「2048」這個數字方塊。
一、游戲界面介紹:
1、點擊「?」幫助按鈕,顯示游戲的幫助信息
2、游戲操作界面很簡潔
二:游戲技巧:
1、最大數和次大數所在的列/行全滿
如下圖所示,最上一排四個格子中存在最大數和次大數,此四個格子要全滿,不要留灰色的空方格
2、最大數和次大數固定到一邊
如下圖所示,最大數和次大數固定到一邊,比如固定到上邊,可以向左,向右,向上操作,不要向下操作即可實現。
3、大的數字堆上層,盡量只操作下兩層
如下圖所示,大的數字堆上層,盡量只操作下兩層,不要向下操作。
4、最上兩層保持U形排列順序
最上兩層保持如下圖所示的排列順序,這上點最為重要,是多次失敗後的經驗總結。
總結:通過以上四個技巧基本上可以通關了,通關界面如下
Ⅳ 2048游戲用vb怎麼編程
vb6.0寫的 還是vb.net寫的哦?
Ⅵ 有沒有Android版的 2048(俄羅斯方塊版本、消消樂版本) 游戲的源代碼
你到CSDN上邊查一下,一大把,都是源碼。
Ⅶ 這是一段2048小游戲的java代碼,請加上詳細的注釋,非常感謝!
代碼??????
Ⅷ 怎麼在開發板上編寫2048游戲代碼
這樣說法是對的
但實際實現比較難
因為涉及到界面處理,這個實際是比較麻煩的。
如果只是實現核心模型,確實數組就可以
用16個元素的數組,表示16個位置的值,0表示沒有
或者用4*4的二維數組
不考慮圖形界面的話,可以用命令行編的,操作起來麻煩一些而已。
Ⅸ c語言猜數字游戲源代碼
小游戲2048:
#include<stdio.h>
#include<stdlib.h>
#include<conio.h>
#include<time.h>
#include<windows.h>
int jsk( ); //計算空格數
void rsgm( ); //重置游戲
void inkey( ); //按鍵輸入
void left( ); //向左移動
void right( ); //向右移動
void up( ); //向上移動
void down( ); //向下移動
void show( ); //輸出界面
void adnum( ); //添加隨機數
void yes( ); //游戲是否結束(1是0否)
void gtxy(int x, int y); //控制游標位置的函數
int a[4][4]; //存儲16個格子中的數字
int score = 0; //每局得分
int best = 0; //最高得分
int ifnum; //是否需要添加數字(1是0否)
int over; //游戲結束標志(1是0否)
int i,j,k;
int main( )
{ rsgm( ); //重置游戲
inkey( ); //按鍵輸入
return 0;
}
void Color(int a) //設定字元顏色的函數(a應為1-15)
{ SetConsoleTextAttribute(GetStdHandle(STD_OUTPUT_HANDLE),a); }
void rsgm( ) //重置游戲
{ score = 0; ifnum = 1; over = 0; srand((unsigned)time(0)); //啟動隨機數發生器
int n = rand( ) % 16; //隨機函數產生0-15的數字
for (i = 0; i < 4; i++)
{for (j = 0; j < 4; j++)
{ if (n == 0) { int k = rand( ) % 3; if (k == 0 || k == 1) { a[i][j] = 2; }
else { a[i][j] = 4; } n--; }
else { a[i][j] = 0; n--; }
}
}
adnum( );
system("cls");
CONSOLE_CURSOR_INFO gb={1,0}; //以下兩行是隱藏游標的設置,gb代指游標
SetConsoleCursorInfo( GetStdHandle(STD_OUTPUT_HANDLE), &gb );
Color(14); //設置字體淡黃色
printf(" 2048小游戲"); Color(7); //恢復白字黑底
printf(" ┌──────┬──────┬──────┬──────┐");
printf(" │ │ │ │ │");
printf(" ├──────┼──────┼──────┼──────┤");
printf(" │ │ │ │ │");
printf(" ├──────┼──────┼──────┼──────┤");
printf(" │ │ │ │ │");
printf(" ├──────┼──────┼──────┼──────┤");
printf(" │ │ │ │ │");
printf(" └──────┴──────┴──────┴──────┘");
show( );
}
void show( ) //輸出界面
{ for(i=0;i<4;i++)
for(j=0;j<4;j++)
{ gtxy(7*j+9,2*i+4); //gtxy(7*j+9, 2*i+4)是游標到指定位置輸出數字
if(a[i][j]==0){printf(" "); Color(7); printf("│");}
else if(a[i][j]<10){ if (a[i][j] == 2) { Color(14); }
else if (a[i][j] == 4) { Color(13); }
else if (a[i][j] == 8) { Color(12); }
printf(" %d ", a[i][j]); Color(7 ); printf("│");
}
else if (a[i][j] < 100){if (a[i][j] == 16) { Color(12); }
else if (a[i][j] == 32) { Color(10); }
else if (a[i][j] == 64) { Color(2 ); }
printf(" %d ", a[i][j]); Color(7); printf("│");
}
else if (a[i][j] < 1000) {if (a[i][j] == 128) { Color(9); }
else if (a[i][j] == 256) { Color(1); }
else if (a[i][j] == 512) { Color(13); }
printf(" %d ", a[i][j]); Color(7); printf("│");
}
else if (a[i][j] < 10000) {if (a[i][j] == 1024) { Color(5); }
else { Color(15); }
printf(" %d ", a[i][j]); Color(7); printf("│");
}
}
if (jsk( ) == 0)
{ yes( ); if (over) { gtxy(9,12); Color(10);
printf(" 游戲結束!是否繼續? [ Y/N ]:"); }
}
}
void inkey( ) //按鍵輸入
{ int key;
while (1)
{ key = getch( );
if (over) { if (key == 89|| key == 121) { rsgm( ); continue; }
else if (key == 78|| key == 110) { return; }
else continue; }
ifnum = 0;
if(key==224)key=getch( );
switch (key)
{ case 75: left( ); break;
case 77: right( ); break;
case 72: up( ); break;
case 80: down( );break;
}
if (score > best) { best = score; }
if (ifnum) { adnum( ); show( ); }
}
}
int jsk( ) //計算空格數
{ int n = 0;
for (i = 0; i < 4; i++)
{ for (j = 0; j < 4; j++) { if ( a[i][j] == 0) {n++;} } }
return n;
}
void left( ) //向左移動
{ for (i = 0; i < 4; i++)
{for (j = 1, k = 0; j < 4; j++)
{ if (a[i][j] > 0)
{ if ( a[i][k] == a[i][j])
{ a[i][k] *= 2; k++;
score = score + 2 * a[i][j];
a[i][j] = 0; ifnum = 1; }
else if ( a[i][k] == 0) { a[i][k] = a[i][j]; a[i][j] = 0; ifnum = 1; }
else { a[i][k + 1] = a[i][j]; if ((k + 1) != j) { a[i][j] = 0; ifnum = 1; }
k++; }
}
}
}
}
void right( ) //向右移動
{for (i = 0; i < 4; i++)
{for (j = 2, k = 3; j >= 0; j--)
{if (a[i][j] > 0)
{ if (a[i][k] == a[i][j])
{a[i][k] *= 2; k--; score = score + 2 * a[i][j]; a[i][j] = 0; ifnum = 1; }
else if ( a[i][k] == 0) {a[i][k] = a[i][j]; a[i][j] = 0; ifnum = 1; }
else { a[i][k - 1] = a[i][j]; if ((k - 1) != j) { a[i][j] = 0; ifnum = 1; } k--; }
}
}
}
}
void up( ) //向上移動
{for (i = 0; i < 4; i++)
{for (j = 1, k = 0; j < 4; j++)
{if (a[j][i] > 0)
{if ( a[k][i] == a[j][i]) { a[k][i] *= 2; k++;score = score + 2 * a[j][i];
a[j][i] = 0; ifnum = 1; }
else if ( a[k][i] == 0) { a[k][i] = a[j][i]; a[j][i] = 0; ifnum = 1; }
else { a[k + 1][i] = a[j][i]; if ((k + 1) != j) { a[j][i] = 0; ifnum = 1; }
k++; }
}
}
}
}
void down( ) //向下移動
{ for (i = 0; i < 4; i++)
{for (j = 2, k = 3; j >= 0; j--)
{if (a[j][i] > 0)
{if (a[k][i] == a[j][i])
{a[k][i] *= 2; k--;score = score + 2 * a[j][i]; a[j][i] = 0; ifnum = 1; }
else if (a[k][i] == 0) {a[k][i] = a[j][i]; a[j][i] = 0; ifnum = 1; }
else {a[k - 1][i] = a[j][i];
if ((k - 1) != j) {a[j][i] = 0; ifnum = 1; } k--; }
}
}
}
}
void adnum( ) //添加隨機數
{ srand(time(0)); int n = rand( ) % jsk( );
for (int i = 0; i < 4; i++)
{for (int j = 0; j < 4; j++)
{ if (a[i][j] == 0) {if (n != 0) { n--; }
else {int k = rand( ) % 3;
if (k == 0 || k == 1) {a[i][j] = 2; return; }
else {a[i][j] = 4; return; } }
}
}
}
}
void yes( ) //游戲是否結束
{ for (int i = 0; i < 4; i++)
{for (int j = 0; j < 3; j++)
{if (a[i][j] == a[i][j + 1] || a[j][i] == a[j + 1][i]) {over = 0; return; }}
}
over = 1;
}
void gtxy(int x, int y) //控制游標位置的函數
{ COORD zb; //zb代指坐標
zb.X = x;
zb.Y = y;
SetConsoleCursorPosition(GetStdHandle(STD_OUTPUT_HANDLE), zb);
}
Ⅹ 那個大神有完整的java,eclipse,2048游戲的源代碼,全部拷貝粘貼就能用的,給一個,在線等,急!!!
網上的java代碼在eclipse里運行方法:
1.打開eclipse,點擊項目的空白處,選擇import;
2.選擇Existing Project into Workspace,點擊next,找到的java代碼,導入到eclipse中;
3.導入成功之後,選擇項目,滑鼠右鍵,選擇run as,選擇一個運行方式,然後運行即可。