国产 无码 综合区,色欲AV无码国产永久播放,无码天堂亚洲国产AV,国产日韩欧美女同一区二区

2048小游戲 java版(代碼+注釋)

這篇具有很好參考價(jià)值的文章主要介紹了2048小游戲 java版(代碼+注釋)。希望對(duì)大家有所幫助。如果存在錯(cuò)誤或未考慮完全的地方,請(qǐng)大家不吝賜教,您也可以點(diǎn)擊"舉報(bào)違法"按鈕提交疑問(wèn)。

????????一個(gè)純純小白,想寫點(diǎn)什么,也想學(xué)習(xí)一下怎么在這里寫東西,就簡(jiǎn)單的寫個(gè)2048小游戲。寫的不好,大佬就不用看了,希望和大家交流學(xué)習(xí),有寫的不好或有更好的建議也歡迎提出來(lái)。(需要用的可直接粘貼復(fù)制)(輕噴)

目錄

游戲展示

講解?

代碼


游戲展示

2048小游戲 java版(代碼+注釋)2048小游戲 java版(代碼+注釋)

????????基本上做到了和手機(jī)上一樣。 我會(huì)按照我的思路為大家講解一下,有需要的可以看看,想直接看效果或者需要用的,可以直接滑倒最后粘貼復(fù)制。


講解?

目錄結(jié)構(gòu)如下

2048小游戲 java版(代碼+注釋)

?按照我自己的思路講一下,可能有點(diǎn)亂。

? ? ? ? 1.首先初始化一下畫板,將不會(huì)改變的部分先完成。

private void initPaint(Graphics g) {
        //TODO 畫方塊所造區(qū)域
        g.setColor(new Color(192, 175, 159));
        g.fillRect(10, 120, 360 + 8, 360 + 8);

        //TODO 畫得分區(qū)域以及說(shuō)明區(qū)域
        g.setColor(new Color(209, 132, 102));
        g.fillRect(200, 15, 80, 50);
        g.fillRect(290, 15, 80, 50);

        g.setColor(Color.black);
        g.setFont(new Font("宋體", Font.BOLD, 20));
        g.drawString("得分", 220, 35);
        g.drawString("最高分", 300, 35);
        g.setFont(new Font("宋體", Font.BOLD, 35));
        g.drawString("游戲說(shuō)明:", 15, 55);
        g.setFont(new Font("宋體", Font.BOLD, 20));
        g.drawString("按上下左右鍵控制;按空格鍵重新游戲", 15, 100);
        
        //畫空白方塊
        for (int i = 0; i < 4; i++) {
            for (int j = 0; j < 4; j++) {
                paintBlock(g, new Block(table[i][j]), j, i);
            }
        }
    }

? ? ? ? ?2.創(chuàng)建帶有數(shù)字的方塊,這里創(chuàng)建了一個(gè)block類,主要存儲(chǔ)了,每種方塊所顯示的數(shù)字,數(shù)字顏色,背景顏色等屬性。并且有一個(gè)setAllFont方法,來(lái)設(shè)置這些屬性。

package game_2048;

import java.awt.*;

public class Block {

    int kind;
    Font wFont;
    Color wColor;
    Color bColor;
    String s;

    public Block(int kind) {
        this.kind = kind;
    }

    private final Font font1 = new Font("宋體", Font.BOLD, 46);
    private final Font font2 = new Font("宋體", Font.BOLD, 40);
    private final Font font3 = new Font("宋體", Font.BOLD, 34);
    private final Font font4 = new Font("宋體", Font.BOLD, 28);

    private final Color color1 = new Color(119,108,99);
    private final Color color2 = new Color(254,254,254);

    public void setAllFont() {
        switch (kind) {
            case 0 -> bColor = new Color(206, 194, 180);
            case 1 -> {
                wFont = font1;
                wColor = color1;
                bColor = new Color(237, 229, 218);
                s = 2 + "";
            }
            case 2 -> {
                wFont = font1;
                wColor = color1;
                bColor = new Color(237, 220, 190);
                s = 4 + "";
            }
            case 3 -> {
                wFont = font1;
                wColor = color1;
                bColor = new Color(242, 177, 123);
                s = 8 + "";
            }
            case 4 -> {
                wFont = font2;
                wColor = color2;
                bColor = new Color(246, 147, 92);
                s = 16 + "";
            }
            case 5 -> {
                wFont = font2;
                wColor = color2;
                bColor = new Color(245, 118, 86);
                s = 32 + "";
            }
            case 6 -> {
                wFont = font2;
                wColor = color2;
                bColor = new Color(245, 83, 45);
                s = 64 + "";
            }
            case 7 -> {
                wFont = font3;
                wColor = color2;
                bColor = new Color(237, 206, 115);
                s = 128 + "";
            }
            case 8 -> {
                wFont = font3;
                wColor = color2;
                bColor = new Color(230,209,81);
                s = 256 + "";
            }
            case 9 -> {
                wFont = font3;
                wColor = color2;
                bColor = new Color(207,163,12);
                s = 512 + "";
            }
            case 10 -> {
                wFont = font4;
                wColor = color2;
                bColor = new Color(229,180,6);
                s = 1024 + "";
            }
            case 11 -> {
                wFont = font4;
                wColor = color2;
                bColor = new Color(161,131,115);
                s = 2048 + "";
            }
            default -> {
            }
        }
    }

}

? ? ? ? 3.繪制每個(gè)方塊(這里在1里面已經(jīng)用過(guò)了,當(dāng)時(shí)是畫空白的)

//畫方塊
    private void paintBlock(Graphics g, Block block, int x, int y) {
        block.setAllFont();
        g.setColor(block.bColor);
        g.fillRect(10 + x * 90 + 7, 120 + y * 90 + 7, 83, 83);
        if (block.kind > 0) {
            g.setColor(block.wColor);
            g.setFont(block.wFont);
            FontMetrics fm = getFontMetrics(block.wFont);
            String value = block.s;
            g.drawString(value,
                    10 + x * 90 + 7 + (83 - fm.stringWidth(value)) / 2,
                    120 + y * 90 + 7 + (83 - fm.getAscent() - fm.getDescent()) / 2 + fm.getAscent());
        }
    }

? ? ? ? ?4.初始化界面,包括分?jǐn)?shù),和最開(kāi)始顯示的方塊。

? ? ? ? 用random類來(lái)隨機(jī)刷新方塊存在的位置。

? ? ? ? 這里的getS()和后面的setS()分別是讀、取文件,為了顯示最高分用。(這兩個(gè)方法寫了不是很好,就不講了)

private void init() {
        isOver = false;

        source = 0;
        try {
            best = getS();
        } catch (IOException e) {
            throw new RuntimeException(e);
        }
        for (int i = 0; i < 4; i++) {
            for (int j = 0; j < 4; j++) {
                table[i][j] = 0;
            }
        }
        bX = rand1.nextInt(4);
        bY = rand2.nextInt(4);
        table[bX][bY] = 1;
    }

? ? ? ? 5.?控制所有方塊的移動(dòng)。

? ? ? ? 通過(guò)一系列控制語(yǔ)句,來(lái)決定是否能移動(dòng)或者合并。我這里是為了做滑動(dòng)的效果,可能寫的有點(diǎn)啰嗦,反正能用就行吧。

private void bDown() {
        for (int j = 0; j <= 3; j++) {
            //第一個(gè)if是為了一種稍微特殊的地方
            //后面的每個(gè)方向都一樣
            if (table[0][j] == table[1][j] && table[2][j] == table[3][j]
                    && table[0][j] != 0 && table[2][j] != 0) {
                table[1][j]++;
                table[0][j] = 0;
            }

            for (int i = 2; i >= 0; i--) {
                if (table[i + 1][j] == 0) {
                    table[i + 1][j] = table[i][j];
                    table[i][j] = 0;
                }
                if (table[i][j] != 0 && table[i][j] == table[i + 1][j]) {
                    if (c[j]) {
                        table[i + 1][j]++;
                        table[i][j] = 0;
                        c[j] = false;
                        source += (int) Math.pow(2, table[i + 1][j]);
                    }
                }
            }
        }
    }

? ? ? ? 6.我這里是用線程的方法,來(lái)實(shí)現(xiàn)滑動(dòng)的效果。

? ? ? ? 每次按按鍵后,將改變fx的值,然后啟動(dòng)線程,每次會(huì)執(zhí)行三次方塊的移動(dòng),每次延遲40ms,依次來(lái)達(dá)到滑動(dòng)的效果。

    @Override
    public void run() {
        for (int i = 0; i < 4; i++) {
            c[i] = true;
        }

        int[][] tt = new int[4][4];
        for (int i = 0; i < 4; i++) {
            for (int j = 0; j < 4; j++) {
                tt[i][j] = table[i][j];
            }
        }

        for (int k = 0; k < 3; k++) {
            switch (fx) {
                case 0 -> bUp();
                case 1 -> bRight();
                case 2 -> bDown();
                case 3 -> bLeft();
                default -> {
                }
            }
            try {
                Thread.sleep(40);
            } catch (InterruptedException e) {
                throw new RuntimeException(e);
            }

            if (best < source) {
                best = source;
                try {
                    setS(source);
                } catch (IOException ioException) {
                    ioException.printStackTrace();
                }

            }

            repaint();
        }

        isMove = false;
        loop:
        for (int i = 0; i < 4; i++) {
            for (int j = 0; j < 4; j++) {
                if (tt[i][j] != table[i][j]) {
                    isMove = true;
                    break loop;
                }
            }
        }
        randomBlock();
    }

? ? ? ? 8.隨機(jī)生成新的方塊。?每次移動(dòng)之后,就會(huì)隨機(jī)產(chǎn)生新的方塊,并且也在這里設(shè)置了結(jié)束的條件。

private void randomBlock() {
        v.clear();
        for (int i = 0; i < 4; i++) {
            for (int j = 0; j < 4; j++) {
                if (table[i][j] == 0) {
                    v.add(i);
                    v.add(j);
                }
            }
        }
        if (v.size() > 0 && isMove) {
            int kk = rand.nextInt(v.size() / 2);
            table[v.get(kk * 2)][v.get(kk * 2 + 1)] = (rand.nextInt(7) % 6 == 0) ? 2 : 1;
        }

        if (v.size() == 0) {
            boolean isSame = false;
            loop1:
            for (int i = 0; i < 3; i++) {
                for (int j = 0; j < 4; j++) {
                    if ((table[i][j] == table[i + 1][j]) || (table[j][i] == table[j][i + 1])) {
                        isSame = true;
                        break loop1;
                    }
                }
            }
            if (!isSame) {
                isOver = true;
                repaint();
            }
        }
    }

就這樣吧,,,有啥問(wèn)題也可以問(wèn),我也會(huì)回答。。。。。。


代碼

best.txt

? ? ? ? best.txt主要用來(lái)記錄最高得分,創(chuàng)建時(shí)候需要在里面存儲(chǔ)個(gè)0,不然讀取的時(shí)候會(huì)報(bào)錯(cuò)。

2048小游戲 java版(代碼+注釋)

MPanel

? ? ? ? Panel類,主要的代碼都在這個(gè)類里。?

package game_2048;

import javax.swing.*;
import java.awt.*;
import java.awt.event.*;
import java.io.FileReader;
import java.io.FileWriter;
import java.io.IOException;
import java.util.Random;
import java.util.Vector;

public class MPanel extends JPanel implements KeyListener, Runnable {

    int[][] table = new int[4][4];

    int fx; //上下左右0123

    Random rand1 = new Random();
    Random rand2 = new Random();
    Random rand = new Random();

    int bX;
    int bY;

    Vector<Integer> v = new Vector<>();

    boolean isMove;

    boolean[] c = new boolean[4];

    int source = 0;
    int best;

    boolean isOver;

    public MPanel() {
        setFocusable(true);
        setBackground(new Color(241, 228, 219));
        this.addKeyListener(this);
        init();
    }

    private void init() {
        isOver = false;

        source = 0;
        try {
            best = getS();
        } catch (IOException e) {
            throw new RuntimeException(e);
        }
        for (int i = 0; i < 4; i++) {
            for (int j = 0; j < 4; j++) {
                table[i][j] = 0;
            }
        }
        bX = rand1.nextInt(4);
        bY = rand2.nextInt(4);
        table[bX][bY] = 1;
    }

    @Override
    public void paint(Graphics g) {
        super.paint(g);
        initPaint(g);


        g.setColor(Color.white);
        g.setFont(new Font("宋體", Font.BOLD, 25));
        FontMetrics fm = getFontMetrics(new Font("宋體", Font.BOLD, 20));
        String value1 = source + "";
        g.drawString(value1,
                195 + (80 - fm.stringWidth(value1)) / 2,
                30 + (50 - fm.getAscent() - fm.getDescent()) / 2 + fm.getAscent());
        String value2 = best + "";
        g.drawString(value2,
                285 + (80 - fm.stringWidth(value2)) / 2,
                30 + (50 - fm.getAscent() - fm.getDescent()) / 2 + fm.getAscent());

        if (isOver) {
            g.setColor(new Color(0, 0, 0, 0.5f));
            g.fillRect(0, 0, getWidth(), getHeight());
            g.setFont(new Font("宋體", Font.BOLD, 60));
            fm = getFontMetrics(new Font("宋體", Font.BOLD, 60));
            String value = "游戲結(jié)束";
            g.drawString(value,
                    (getWidth() - fm.stringWidth(value)) / 2,
                    (getHeight() - fm.getAscent() - fm.getDescent()) / 2 + fm.getAscent());
        }
    }

    //初始化畫板
    private void initPaint(Graphics g) {
        //TODO 畫方塊所造區(qū)域
        g.setColor(new Color(192, 175, 159));
        g.fillRect(10, 120, 360 + 8, 360 + 8);

        //TODO 畫得分區(qū)域以及說(shuō)明區(qū)域
        g.setColor(new Color(209, 132, 102));
        g.fillRect(200, 15, 80, 50);
        g.fillRect(290, 15, 80, 50);

        g.setColor(Color.black);
        g.setFont(new Font("宋體", Font.BOLD, 20));
        g.drawString("得分", 220, 35);
        g.drawString("最高分", 300, 35);
        g.setFont(new Font("宋體", Font.BOLD, 35));
        g.drawString("游戲說(shuō)明:", 15, 55);
        g.setFont(new Font("宋體", Font.BOLD, 20));
        g.drawString("按上下左右鍵控制;按空格鍵重新游戲", 15, 100);

        for (int i = 0; i < 4; i++) {
            for (int j = 0; j < 4; j++) {
                paintBlock(g, new Block(table[i][j]), j, i);
            }
        }
    }

    //畫方塊
    private void paintBlock(Graphics g, Block block, int x, int y) {
        block.setAllFont();
        g.setColor(block.bColor);
        g.fillRect(10 + x * 90 + 7, 120 + y * 90 + 7, 83, 83);
        if (block.kind > 0) {
            g.setColor(block.wColor);
            g.setFont(block.wFont);
            FontMetrics fm = getFontMetrics(block.wFont);
            String value = block.s;
            g.drawString(value,
                    10 + x * 90 + 7 + (83 - fm.stringWidth(value)) / 2,
                    120 + y * 90 + 7 + (83 - fm.getAscent() - fm.getDescent()) / 2 + fm.getAscent());
        }
    }

    @Override
    public void keyTyped(KeyEvent e) {

    }

    @Override
    public void keyPressed(KeyEvent e) {
        int keyCode = e.getKeyCode();
        if (!isOver) {
            Thread thread = new Thread(this);
            if (keyCode == KeyEvent.VK_DOWN) {
                fx = 2;
                thread.start();
            } else if (keyCode == KeyEvent.VK_UP) {
                fx = 0;
                thread.start();
            } else if (keyCode == KeyEvent.VK_RIGHT) {
                fx = 1;
                thread.start();
            } else if (keyCode == KeyEvent.VK_LEFT) {
                fx = 3;
                thread.start();
            }
        }
        if (keyCode == KeyEvent.VK_SPACE) {
            init();
        }
        repaint();
    }


    @Override
    public void keyReleased(KeyEvent e) {

    }

    @Override
    public void run() {
        for (int i = 0; i < 4; i++) {
            c[i] = true;
        }

        int[][] tt = new int[4][4];
        for (int i = 0; i < 4; i++) {
            for (int j = 0; j < 4; j++) {
                tt[i][j] = table[i][j];
            }
        }

        for (int k = 0; k < 3; k++) {
            switch (fx) {
                case 0 -> bUp();
                case 1 -> bRight();
                case 2 -> bDown();
                case 3 -> bLeft();
                default -> {
                }
            }
            try {
                Thread.sleep(40);
            } catch (InterruptedException e) {
                throw new RuntimeException(e);
            }

            if (best < source) {
                best = source;
                try {
                    setS(source);
                } catch (IOException ioException) {
                    ioException.printStackTrace();
                }

            }

            repaint();
        }

        isMove = false;
        loop:
        for (int i = 0; i < 4; i++) {
            for (int j = 0; j < 4; j++) {
                if (tt[i][j] != table[i][j]) {
                    isMove = true;
                    break loop;
                }
            }
        }
        randomBlock();
    }

    private void randomBlock() {
        v.clear();
        for (int i = 0; i < 4; i++) {
            for (int j = 0; j < 4; j++) {
                if (table[i][j] == 0) {
                    v.add(i);
                    v.add(j);
                }
            }
        }
        if (v.size() > 0 && isMove) {
            int kk = rand.nextInt(v.size() / 2);
            table[v.get(kk * 2)][v.get(kk * 2 + 1)] = (rand.nextInt(7) % 6 == 0) ? 2 : 1;
        }

        if (v.size() == 0) {
            boolean isSame = false;
            loop1:
            for (int i = 0; i < 3; i++) {
                for (int j = 0; j < 4; j++) {
                    if ((table[i][j] == table[i + 1][j]) || (table[j][i] == table[j][i + 1])) {
                        isSame = true;
                        break loop1;
                    }
                }
            }
            if (!isSame) {
                isOver = true;
                repaint();
            }
        }
    }

    private void bDown() {
        for (int j = 0; j <= 3; j++) {
            //第一個(gè)if是為了一種稍微特殊的地方
            //后面的每個(gè)方向都一樣
            if (table[0][j] == table[1][j] && table[2][j] == table[3][j]
                    && table[0][j] != 0 && table[2][j] != 0) {
                table[1][j]++;
                table[0][j] = 0;
            }

            for (int i = 2; i >= 0; i--) {
                if (table[i + 1][j] == 0) {
                    table[i + 1][j] = table[i][j];
                    table[i][j] = 0;
                }
                if (table[i][j] != 0 && table[i][j] == table[i + 1][j]) {
                    if (c[j]) {
                        table[i + 1][j]++;
                        table[i][j] = 0;
                        c[j] = false;
                        source += (int) Math.pow(2, table[i + 1][j]);
                    }
                }
            }
        }
    }

    private void bLeft() {
        for (int i = 0; i <= 3; i++) {

            if (table[i][0] == table[i][1] && table[i][2] == table[i][3]
                    && table[i][0] != 0 && table[i][2] != 0) {
                table[i][2]++;
                table[i][3] = 0;
            }

            for (int j = 1; j <= 3; j++) {
                if (table[i][j - 1] == 0) {
                    table[i][j - 1] = table[i][j];
                    table[i][j] = 0;
                }
                if (table[i][j] != 0 && table[i][j] == table[i][j - 1]) {
                    if (c[i]) {
                        table[i][j - 1]++;
                        table[i][j] = 0;
                        c[i] = false;
                        source += (int) Math.pow(2, table[i][j - 1]);
                    }
                }
            }
        }
    }

    private void bRight() {
        for (int i = 0; i <= 3; i++) {

            if (table[i][0] == table[i][1] && table[i][2] == table[i][3]
                    && table[i][0] != 0 && table[i][2] != 0) {
                table[i][1]++;
                table[i][0] = 0;
            }

            for (int j = 2; j >= 0; j--) {
                if (table[i][j + 1] == 0) {
                    table[i][j + 1] = table[i][j];
                    table[i][j] = 0;
                }
                if (table[i][j] != 0 && table[i][j] == table[i][j + 1]) {
                    if (c[i]) {
                        table[i][j + 1]++;
                        table[i][j] = 0;
                        c[i] = false;
                        source += (int) Math.pow(2, table[i][j + 1]);
                    }
                }
            }
        }
    }

    private void bUp() {
        for (int j = 0; j <= 3; j++) {

            if (table[0][j] == table[1][j] && table[2][j] == table[3][j]
                    && table[0][j] != 0 && table[2][j] != 0) {
                table[2][j]++;
                table[3][j] = 0;
            }

            for (int i = 1; i <= 3; i++) {
                if (table[i - 1][j] == 0) {
                    table[i - 1][j] = table[i][j];
                    table[i][j] = 0;
                }
                if (table[i][j] != 0 && table[i][j] == table[i - 1][j]) {
                    if (c[j]) {
                        table[i - 1][j]++;
                        table[i][j] = 0;
                        c[j] = false;
                        source += (int) Math.pow(2, table[i - 1][j]);
                    }
                }
            }
        }
    }

    public int getS() throws IOException {
        String filePath = "src\\game_2048\\best.txt";
        FileReader fileReader = new FileReader(filePath);
        int data = 0;
        String s = "";
        while ((data = fileReader.read()) != -1) {
            s += (char) data;
        }
        int y = Integer.parseInt(s);
        fileReader.close();
        return y;
    }

    private void setS(int y) throws IOException {
        String filePath = "src\\game_2048\\best.txt";
        FileWriter fileWriter = new FileWriter(filePath);
        String yy = y + "";
        fileWriter.write(yy);
        fileWriter.close();
    }

}

Block?

? ? ? ? 每個(gè)方塊創(chuàng)建的類。?

package game_2048;

import java.awt.*;

public class Block {

    int kind;
    Font wFont;
    Color wColor;
    Color bColor;
    String s;

    public Block(int kind) {
        this.kind = kind;
    }

    private final Font font1 = new Font("宋體", Font.BOLD, 46);
    private final Font font2 = new Font("宋體", Font.BOLD, 40);
    private final Font font3 = new Font("宋體", Font.BOLD, 34);
    private final Font font4 = new Font("宋體", Font.BOLD, 28);

    private final Color color1 = new Color(119,108,99);
    private final Color color2 = new Color(254,254,254);

    public void setAllFont() {
        switch (kind) {
            case 0 -> bColor = new Color(206, 194, 180);
            case 1 -> {
                wFont = font1;
                wColor = color1;
                bColor = new Color(237, 229, 218);
                s = 2 + "";
            }
            case 2 -> {
                wFont = font1;
                wColor = color1;
                bColor = new Color(237, 220, 190);
                s = 4 + "";
            }
            case 3 -> {
                wFont = font1;
                wColor = color1;
                bColor = new Color(242, 177, 123);
                s = 8 + "";
            }
            case 4 -> {
                wFont = font2;
                wColor = color2;
                bColor = new Color(246, 147, 92);
                s = 16 + "";
            }
            case 5 -> {
                wFont = font2;
                wColor = color2;
                bColor = new Color(245, 118, 86);
                s = 32 + "";
            }
            case 6 -> {
                wFont = font2;
                wColor = color2;
                bColor = new Color(245, 83, 45);
                s = 64 + "";
            }
            case 7 -> {
                wFont = font3;
                wColor = color2;
                bColor = new Color(237, 206, 115);
                s = 128 + "";
            }
            case 8 -> {
                wFont = font3;
                wColor = color2;
                bColor = new Color(230,209,81);
                s = 256 + "";
            }
            case 9 -> {
                wFont = font3;
                wColor = color2;
                bColor = new Color(207,163,12);
                s = 512 + "";
            }
            case 10 -> {
                wFont = font4;
                wColor = color2;
                bColor = new Color(229,180,6);
                s = 1024 + "";
            }
            case 11 -> {
                wFont = font4;
                wColor = color2;
                bColor = new Color(161,131,115);
                s = 2048 + "";
            }
            default -> {
            }
        }
    }

}

MFrame文章來(lái)源地址http://www.zghlxwxcb.cn/news/detail-491865.html

package game_2048;

/*
 *@author douhehe
 */

import javax.swing.*;

public class MFrame {
    public static void main(String[] args) {
        JFrame jf = new JFrame("2048小游戲");

        jf.add(new MPanel());

        jf.setSize(401,552);
        jf.setLocationRelativeTo(null);     //居中
        jf.setResizable(false);
        jf.setDefaultCloseOperation(WindowConstants.EXIT_ON_CLOSE);
        jf.setVisible(true);
    }
}

到了這里,關(guān)于2048小游戲 java版(代碼+注釋)的文章就介紹完了。如果您還想了解更多內(nèi)容,請(qǐng)?jiān)谟疑辖撬阉鱐OY模板網(wǎng)以前的文章或繼續(xù)瀏覽下面的相關(guān)文章,希望大家以后多多支持TOY模板網(wǎng)!

本文來(lái)自互聯(lián)網(wǎng)用戶投稿,該文觀點(diǎn)僅代表作者本人,不代表本站立場(chǎng)。本站僅提供信息存儲(chǔ)空間服務(wù),不擁有所有權(quán),不承擔(dān)相關(guān)法律責(zé)任。如若轉(zhuǎn)載,請(qǐng)注明出處: 如若內(nèi)容造成侵權(quán)/違法違規(guī)/事實(shí)不符,請(qǐng)點(diǎn)擊違法舉報(bào)進(jìn)行投訴反饋,一經(jīng)查實(shí),立即刪除!

領(lǐng)支付寶紅包贊助服務(wù)器費(fèi)用

相關(guān)文章

  • 利用Python編寫一個(gè)AI腳本自動(dòng)控制2048網(wǎng)頁(yè)小游戲

    利用Python編寫一個(gè)AI腳本自動(dòng)控制2048網(wǎng)頁(yè)小游戲

    本文將使用python+selenium自動(dòng)控制游戲運(yùn)行。當(dāng)然采用的是偽隨機(jī)數(shù)進(jìn)行鍵盤控制。只作為一個(gè)拋磚迎玉的參考,不涉及專業(yè)算法。 – pip install win32gui pip install PyUserInput pip install PyKeyboard pip install selenium(注意要配合相應(yīng)的webdriver驅(qū)動(dòng)使用,webdriver的安裝下載請(qǐng)自行到網(wǎng)上搜索學(xué)

    2023年04月08日
    瀏覽(28)
  • vue3+uniapp在微信小程序?qū)崿F(xiàn)一個(gè)2048小游戲

    vue3+uniapp在微信小程序?qū)崿F(xiàn)一個(gè)2048小游戲

    微信小程序搜索《靜遠(yuǎn)的工具箱》:偶數(shù)求和那個(gè)功能

    2024年04月12日
    瀏覽(30)
  • 基于Java的2048小游戲的設(shè)計(jì)與實(shí)現(xiàn),附源碼+文檔,適合課程設(shè)計(jì),包遠(yuǎn)程安裝調(diào)試運(yùn)行

    基于Java的2048小游戲的設(shè)計(jì)與實(shí)現(xiàn),附源碼+文檔,適合課程設(shè)計(jì),包遠(yuǎn)程安裝調(diào)試運(yùn)行

    1、項(xiàng)目介紹 本游戲采用Java語(yǔ)言編寫,使用Eclipse編譯器,jdk1.8編譯環(huán)境。游戲的UI主要運(yùn)用Java圖形界面編程(AWT),實(shí)現(xiàn)窗口化可視化的界面。 游戲的后臺(tái)通過(guò)監(jiān)聽(tīng)鍵盤方向鍵來(lái)移動(dòng)數(shù)字方塊,運(yùn)用隨機(jī)數(shù)的思想隨機(jī)產(chǎn)生一個(gè)2或4的隨機(jī)數(shù),顯示在隨機(jī)方塊中,運(yùn)用二維數(shù)組

    2024年02月03日
    瀏覽(85)
  • 實(shí)現(xiàn)用java做一個(gè)簡(jiǎn)易版《羊了個(gè)羊》小游戲(附源代碼)

    實(shí)現(xiàn)用java做一個(gè)簡(jiǎn)易版《羊了個(gè)羊》小游戲(附源代碼)

    該項(xiàng)目是跟著這個(gè)b站視頻一步一步寫出來(lái)的,初學(xué)java有些地方我看不是很明白,但是講解很仔細(xì),大家可以看原視頻,我沒(méi)有添加背景音樂(lè)和背景圖片,做出來(lái)的效果也勉勉強(qiáng)強(qiáng)。 代碼已經(jīng)上傳到github上了,大家可以去github上直接下載代碼,附上鏈接:點(diǎn)擊進(jìn)入github源碼鏈接

    2024年02月04日
    瀏覽(220)
  • python小游戲 2048小游戲設(shè)計(jì)與實(shí)現(xiàn)

    python小游戲 2048小游戲設(shè)計(jì)與實(shí)現(xiàn)

    ?? Hi,各位同學(xué)好呀,這里是L學(xué)長(zhǎng)! ??今天向大家分享一個(gè)今年(2022)最新完成的畢業(yè)設(shè)計(jì)項(xiàng)目作品 python小游戲畢設(shè) 2048小游戲設(shè)計(jì)與實(shí)現(xiàn) (源碼) ?? 學(xué)長(zhǎng)根據(jù)實(shí)現(xiàn)的難度和等級(jí)對(duì)項(xiàng)目進(jìn)行評(píng)分(最低0分,滿分5分) 難度系數(shù):3分 工作量:3分 創(chuàng)新點(diǎn):4分 今天我們用python實(shí)現(xiàn)

    2024年02月11日
    瀏覽(19)
  • python小游戲畢設(shè) 2048小游戲設(shè)計(jì)與實(shí)現(xiàn) (源碼)

    python小游戲畢設(shè) 2048小游戲設(shè)計(jì)與實(shí)現(xiàn) (源碼)

    ?? Hi,各位同學(xué)好呀,這里是L學(xué)長(zhǎng)! ??今天向大家分享一個(gè)今年(2022)最新完成的畢業(yè)設(shè)計(jì)項(xiàng)目作品 python小游戲畢設(shè) 2048小游戲設(shè)計(jì)與實(shí)現(xiàn) (源碼) ?? 學(xué)長(zhǎng)根據(jù)實(shí)現(xiàn)的難度和等級(jí)對(duì)項(xiàng)目進(jìn)行評(píng)分(最低0分,滿分5分) 難度系數(shù):3分 工作量:3分 創(chuàng)新點(diǎn):4分 項(xiàng)目獲?。?https://

    2024年02月12日
    瀏覽(29)
  • 2048小游戲成品源碼

    2048小游戲成品源碼

    2048小游戲,可以自選背景顏色,方框顏色,音樂(lè)播放。 還可以展示當(dāng)前玩家的排名,動(dòng)態(tài)排名,及歷史玩家的排名。 前期需求: 使用pygame加載目錄音樂(lè)。MP3文件: 看下運(yùn)行后的效果圖: =========參數(shù)設(shè)置: =========背景設(shè)置: =========方塊設(shè)置: ==========源碼分享:

    2024年02月16日
    瀏覽(29)
  • Qt--2048小游戲

    Qt--2048小游戲

    2048 1.功能 上下左右控制數(shù)字格子的移動(dòng) WASD 4*4 格子移動(dòng)操作,加操作 開(kāi)始游戲的按鈕,重新游戲按鈕 得分計(jì)算 判斷游戲是否結(jié)束 2.源程序 代碼如下(示例): MainWindow.h Main.cpp MainWindow.cpp 5.結(jié)果 以上是今天要講的內(nèi)容,練習(xí)了2048小游戲。

    2024年01月25日
    瀏覽(24)
  • c++制作小游戲2048

    c++制作小游戲2048

    完整代碼來(lái)自于愛(ài)編程的柚子《【C語(yǔ)言/C++游戲項(xiàng)目】:2048小游戲,超詳細(xì)教程教會(huì)你寫這個(gè)小游戲?!?這個(gè)游戲用到了#include graphics.h,思路比較簡(jiǎn)單。 首先做出游戲頁(yè)面,然后畫出4*4的格子,利用map二維數(shù)組,依據(jù)數(shù)字{0,2,4,8,16,32,64,128,256,512,1024,2048}找到對(duì)應(yīng)顏色在固定位

    2024年02月13日
    瀏覽(28)
  • Android期末項(xiàng)目2048小游戲

    Android期末項(xiàng)目2048小游戲

    Android期末項(xiàng)目2048小游戲。 2048屬于益智類小游戲,它做到了娛樂(lè)性、趣味性、教育性相統(tǒng)一。益智類的游戲即是需要去開(kāi)動(dòng)大腦去思考從而獲得游戲的勝利。簡(jiǎn)單的益智類游戲可以使玩家在娛樂(lè)中不斷的開(kāi)發(fā)大腦。這樣一來(lái)就實(shí)現(xiàn)了在娛樂(lè)中學(xué)習(xí)。每次可以選擇上下左右其中

    2024年02月06日
    瀏覽(19)

覺(jué)得文章有用就打賞一下文章作者

支付寶掃一掃打賞

博客贊助

微信掃一掃打賞

請(qǐng)作者喝杯咖啡吧~博客贊助

支付寶掃一掃領(lǐng)取紅包,優(yōu)惠每天領(lǐng)

二維碼1

領(lǐng)取紅包

二維碼2

領(lǐng)紅包