java实现双人五子棋游戏

本文实例为大家分享了java实现双人五子棋游戏的具体代码,供大家参考,具体内容如下

通过 上下左右 控制棋盘走动  空格落子   (深度优先搜索)

package day_1; 
 
import java.awt.*;
import javax.swing.*;
 
import java.awt.event.*;
 
public class CircleRun extends JFrame {
    /**
     * 
     */
    MyPanel mp = null;
 
    public static void main(String[] args) {
        CircleRun cr = new CircleRun();
    }
 
    public CircleRun() {
 
        mp = new MyPanel();
        this.add(mp);
        this.addKeyListener(mp);
        this.setTitle("双人五子棋正式版3.0");
        this.setSize(518, 538);// 设置窗体大小
        this.setLocation(340, 50);// 设置出现的位置
        this.setVisible(true);// 设置为可见
        this.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
        JOptionPane.showMessageDialog(this, "双人五子棋游戏说明:通过←↑→↓控制旗子走向,空格下子先满五个子胜利", "游戏说明", JOptionPane.WARNING_MESSAGE);
    }// 游戏说明
}
 
class Text2Frame {// 设置一个交互框
    JTextField jt1 = new JTextField(); // new一个文本框
    JTextArea jt2 = new JTextArea(); // new一个文本区
 
    JTextArea jt4 = new JTextArea(); // new一个文本区
 
    Text2Frame() {
 
        JScrollPane jsp = new JScrollPane(jt2); // new一个滚条
        String title = "正在思考。。。。";
        JFrame jf = new JFrame(title);
        Container container = jf.getContentPane();
        // container.setBackground(Color.yellow); //容器的背景色
        jf.setVisible(true); // 窗体可见
        jf.setLocation(150, 50);
        jf.setSize(300, 150); // 窗体大小
        jf.setLayout(new BorderLayout()); // 边界布局
        jf.add(BorderLayout.NORTH, jt1); // 文本框边界顶部放置
        jt1.setBackground(Color.yellow);
        jf.add(BorderLayout.CENTER, jt2); // 文本框边界中间放置
        jf.add(BorderLayout.EAST, jt4); // 文本框边界中间放置
        jt2.setBackground(Color.red);
 
        jt2.setFont(new Font("宋体", Font.PLAIN, 30));
 
    }
 
    void add(String a) {
        jt2.setText(a);
 
    }
 
};
 
class Text3Frame {
    JTextField jt1 = new JTextField(); // new一个文本框
    JTextArea jt2 = new JTextArea(); // new一个文本区
 
    JTextArea jt4 = new JTextArea(); // new一个文本区
 
    Text3Frame() {
 
        JScrollPane jsp = new JScrollPane(jt2); // new一个滚条
        String title = "当前坐标";
        JFrame jf = new JFrame(title);
        Container container = jf.getContentPane();
        // container.setBackground(Color.yellow); //容器的背景色
        jf.setVisible(true); // 窗体可见
        jf.setLocation(140, 180);
        jf.setSize(300, 200); // 窗体大小
        jf.setLayout(new BorderLayout()); // 边界布局
        jf.add(BorderLayout.NORTH, jt1); // 文本框边界顶部放置
        jt1.setBackground(Color.yellow);
        jf.add(BorderLayout.CENTER, jt2); // 文本框边界中间放置
        jf.add(BorderLayout.EAST, jt4); // 文本框边界中间放置
        jt2.setBackground(Color.green);
 
        jt2.setFont(new Font("宋体", Font.PLAIN, 30));
 
    }
 
    void add(String a) {
        jt2.setText(a);
 
    }
 
    String shu(int a, int b) {
        return "当前坐标(" + a + "," + b + ")";
    }
 
};
 
// 定义自己的面板
class MyPanel extends JPanel implements KeyListener {
    /**
     * 
     */
    private static final long serialVersionUID = 4154597541232213984L;
    Text2Frame txw = new Text2Frame();
    Text3Frame txw3 = new Text3Frame();
    static JFrame sc = new JFrame();
    static int jishu = 1;
 
    static int summm = 1;
    static int summm2 = 1;
    static int arr[][] = new int[11][12];
 
    int x = 5;
    int y = 5;
    int sum = 0;
    int sum2 = 0;
    Node n1 = new Node(x, y);
    seqlist kai = new seqlist(n1);
    seqlist seq = new seqlist(null);
    seqlist seq2 = new seqlist(null);
 
    static void soushang(int a, int b) {
 
        if (a - 1 < 1) {
 
            return;
 
        }
        if (arr[a - 1][b] == 1 && a - 1 > 0) {
 
            summm++;
            if (summm == 5) {
                for (int i = 0; i < 11; i++) {
                    for (int k = 0; k < 12; k++) {
                        arr[i][k] = 0;
                    }
 
                }
                System.out.println("胜利");
                JOptionPane.showMessageDialog(sc, "红色方胜利,点击确定重新开始", "结果", JOptionPane.WARNING_MESSAGE);
 
            }
 
            soushang(a - 1, b);
 
        }
 
    }
 
    static void souxia(int a, int b) {
 
        if (a + 1 > 10) {
 
            return;
 
        }
        if (arr[a + 1][b] == 1 && a + 1 <= 10) {
 
            summm++;
            if (summm == 5) {
                for (int i = 0; i < 11; i++) {
                    for (int k = 0; k < 12; k++) {
                        arr[i][k] = 0;
                    }
 
                }
                System.out.println("胜利");
                JOptionPane.showMessageDialog(sc, "红色方胜利,点击确定重新开始", "结果", JOptionPane.WARNING_MESSAGE);
            }
 
            souxia(a + 1, b);
 
        }
 
    }
 
    static void souzuo(int a, int b) {
 
        if (b - 1 < 1) {
 
            return;
 
        }
        if (arr[a][b - 1] == 1 && b - 1 >= 1) {
 
            summm++;
            if (summm == 5) {
                for (int i = 0; i < 11; i++) {
                    for (int k = 0; k < 12; k++) {
                        arr[i][k] = 0;
                    }
 
                }
                System.out.println("胜利");
                JOptionPane.showMessageDialog(sc, "红色方胜利,点击确定重新开始", "结果", JOptionPane.WARNING_MESSAGE);
            }
 
            souzuo(a, b - 1);
 
        }
 
    }
 
    static void souyou(int a, int b) {
 
        if (b + 1 > 10) {
 
            return;
 
        }
        if (arr[a][b + 1] == 1 && b + 1 <= 10) {
 
            summm++;
            if (summm == 5) {
                for (int i = 0; i < 11; i++) {
                    for (int k = 0; k < 12; k++) {
                        arr[i][k] = 0;
                    }
 
                }
                System.out.println("胜利");
                JOptionPane.showMessageDialog(sc, "红色方胜利,点击确定重新开始", "结果", JOptionPane.WARNING_MESSAGE);
            }
 
            souyou(a, b + 1);
 
        }
    }
 
    static void soushangzuo(int a, int b) {
 
        if (a - 1 < 1 || b - 1 < 1) {
 
            return;
 
        }
        if (arr[a - 1][b - 1] == 1 && (a - 1 > 0) && (b - 1) > 0) {
 
            summm++;
 
            if (summm == 5) {
                for (int i = 0; i < 11; i++) {
                    for (int k = 0; k < 12; k++) {
                        arr[i][k] = 0;
                    }
 
                }
                System.out.println("胜利");
                JOptionPane.showMessageDialog(sc, "红色方胜利,点击确定重新开始", "结果", JOptionPane.WARNING_MESSAGE);
            }
 
            soushangzuo(a - 1, b - 1);
        }
 
    }
 
    static void souxiazuo(int a, int b) {
 
        if (a + 1 > 10 || b - 1 < 1) {
 
            return;
 
        }
        if (arr[a + 1][b - 1] == 1 && (a + 1 <= 10) && (b - 1) >= 1) {
 
            summm++;
            if (summm == 5) {
                for (int i = 0; i < 11; i++) {
                    for (int k = 0; k < 12; k++) {
                        arr[i][k] = 0;
                    }
 
                }
                System.out.println("胜利");
                JOptionPane.showMessageDialog(sc, "红色方胜利,点击确定重新开始", "结果", JOptionPane.WARNING_MESSAGE);
            }
 
            souxiazuo(a + 1, b - 1);
        }
 
    }
 
    static void souyoushang(int a, int b) {
 
        if (a - 1 < 1 && b + 1 > 10) {
 
            return;
 
        }
        if (arr[a - 1][b + 1] == 1 && a - 1 >= 1 && b + 1 <= 10) {
 
            summm++;
            if (summm == 5) {
                for (int i = 0; i < 11; i++) {
                    for (int k = 0; k < 12; k++) {
                        arr[i][k] = 0;
                    }
 
                }
                System.out.println("胜利");
                JOptionPane.showMessageDialog(sc, "红色方胜利,点击确定重新开始", "结果", JOptionPane.WARNING_MESSAGE);
            }
 
            souyoushang(a - 1, b + 1);
        }
 
    }
 
    static void souyouxia(int a, int b) {
 
        if (b + 1 > 10 && a + 1 > 10) {
 
            return;
 
        }
        if (arr[a + 1][b + 1] == 1 && b + 1 <= 10 && a + 1 <= 10) {
 
            summm++;
            if (summm == 5) {
                for (int i = 0; i < 11; i++) {
                    for (int k = 0; k < 12; k++) {
                        arr[i][k] = 0;
                    }
 
                }
                System.out.println("胜利");
                JOptionPane.showMessageDialog(sc, "红色方胜利,点击确定重新开始", "结果", JOptionPane.WARNING_MESSAGE);
            }
 
            souyouxia(a + 1, b + 1);
        }
    }
 
    static void soushang2(int a, int b) {
 
        if (a - 1 < 1) {
 
            return;
 
        }
        if (arr[a - 1][b] == 2 && a - 1 > 0) {
 
            summm2++;
            if (summm2 == 5) {
                for (int i = 0; i < 11; i++) {
                    for (int k = 0; k < 12; k++) {
                        arr[i][k] = 0;
                    }
 
                }
                System.out.println("胜利");
                JOptionPane.showMessageDialog(sc, "绿色方胜利,点击确定重新开始", "结果", JOptionPane.WARNING_MESSAGE);
            }
 
            soushang2(a - 1, b);
 
        }
 
    }
 
    static void souxia2(int a, int b) {
 
        if (a + 1 > 10) {
 
            return;
 
        }
        if (arr[a + 1][b] == 2 && a + 1 <= 10) {
 
            summm2++;
            if (summm2 == 5) {
                for (int i = 0; i < 11; i++) {
                    for (int k = 0; k < 12; k++) {
                        arr[i][k] = 0;
                    }
 
                }
                System.out.println("胜利");
                JOptionPane.showMessageDialog(sc, "绿色方胜利,点击确定重新开始", "结果", JOptionPane.WARNING_MESSAGE);
            }
 
            souxia2(a + 1, b);
 
        }
 
    }
 
    static void souzuo2(int a, int b) {
 
        if (b - 1 > 10) {
 
            return;
 
        }
        if (arr[a][b - 1] == 2 && b - 1 >= 1) {
 
            summm2++;
            if (summm2 == 5) {
                for (int i = 0; i < 11; i++) {
                    for (int k = 0; k < 12; k++) {
                        arr[i][k] = 0;
                    }
 
                }
                System.out.println("胜利");
                JOptionPane.showMessageDialog(sc, "绿色方胜利,点击确定重新开始", "结果", JOptionPane.WARNING_MESSAGE);
            }
 
            souzuo2(a, b - 1);
 
        }
 
    }
 
    static void souyou2(int a, int b) {
 
        if (b + 1 > 10) {
 
            return;
 
        }
        if (arr[a][b + 1] == 2 && b + 1 <= 10) {
 
            summm2++;
            if (summm2 == 5) {
                for (int i = 0; i < 11; i++) {
                    for (int k = 0; k < 12; k++) {
                        arr[i][k] = 0;
                    }
 
                }
                System.out.println("胜利");
                JOptionPane.showMessageDialog(sc, "绿色方胜利,点击确定重新开始", "结果", JOptionPane.WARNING_MESSAGE);
            }
 
            souyou2(a, b + 1);
 
        }
 
    }
 
    static void soushangzuo2(int a, int b) {
 
        if (a - 1 < 1 || b - 1 < 1) {
 
            return;
 
        }
        if (arr[a - 1][b - 1] == 2 && (a - 1 >= 1) && (b - 1) >= 1) {
 
            summm2++;
 
            if (summm2 == 5) {
                for (int i = 0; i < 11; i++) {
                    for (int k = 0; k < 12; k++) {
                        arr[i][k] = 0;
                    }
 
                }
                System.out.println("胜利");
                JOptionPane.showMessageDialog(sc, "绿色方胜利,点击确定重新开始", "结果", JOptionPane.WARNING_MESSAGE);
            }
 
            soushangzuo2(a - 1, b - 1);
        }
 
    }
 
    static void souxiazuo2(int a, int b) {
 
        if (a + 1 > 10 || b - 1 < 1) {
 
            return;
 
        }
        if (arr[a + 1][b - 1] == 2 && (a + 1 <= 10) && (b - 1) >= 1) {
 
            summm2++;
            if (summm2 == 5) {
                for (int i = 0; i < 11; i++) {
                    for (int k = 0; k < 12; k++) {
                        arr[i][k] = 0;
                    }
 
                }
                System.out.println("胜利");
                JOptionPane.showMessageDialog(sc, "绿色方胜利,点击确定重新开始", "结果", JOptionPane.WARNING_MESSAGE);
            }
 
            souxiazuo2(a + 1, b - 1);
        }
 
    }
 
    static void souyoushang2(int a, int b) {
 
        if (a - 1 < 1 && b + 1 > 10) {
 
            return;
 
        }
        if (arr[a - 1][b + 1] == 2 && a - 1 >= 1 && b + 1 <= 10) {
 
            summm2++;
            if (summm2 == 5) {
                for (int i = 0; i < 11; i++) {
                    for (int k = 0; k < 12; k++) {
                        arr[i][k] = 0;
                    }
 
                }
                System.out.println("胜利");
                JOptionPane.showMessageDialog(sc, "绿色方胜利,点击确定重新开始", "结果", JOptionPane.WARNING_MESSAGE);
            }
 
            souyoushang2(a - 1, b + 1);
        }
 
    }
 
    static void souyouxia2(int a, int b) {
 
        if (b + 1 > 10 && a + 1 > 10) {
 
            return;
 
        }
        if (arr[a + 1][b + 1] == 2 && b + 1 <= 10 && a + 1 <= 10) {
 
            summm2++;
            if (summm2 == 5) {
                for (int i = 0; i < 11; i++) {
                    for (int k = 0; k < 12; k++) {
                        arr[i][k] = 0;
                    }
 
                }
                System.out.println("胜利");
                JOptionPane.showMessageDialog(sc, "绿色方胜利,点击确定重新开始", "结果", JOptionPane.WARNING_MESSAGE);
            }
 
            souyouxia2(a + 1, b + 1);
        }
    }
 
    public void paint(Graphics g) {
        if (jishu % 2 == 1) {
            String aaa = "红方开始下棋";
            txw.add(aaa);
 
        } else {
            String aaa = "绿方开始下棋";
            txw.add(aaa);
 
        }
 
        txw3.add(txw3.shu(x, y));
        super.paint(g);
        for (int i = 1; i <= 10; i++) {
            for (int k = 1; k <= 10; k++) {
                g.fillOval((i - 1) * 50, (k - 1) * 50, 50, 50);
            }
        }
        Color c = g.getColor();
 
        g.fillOval(x * 50, y * 50, 50, 50);
        Node now = seq.head;
        Node tou = kai.head;
        Color u = g.getColor();
        if (jishu % 2 == 1) {
            g.setColor(Color.red);
            g.fillOval((tou.a - 1) * 50, (tou.b - 1) * 50, 50, 50);
            g.setColor(u);
        } else {
            g.setColor(Color.green);
            g.fillOval((tou.a - 1) * 50, (tou.b - 1) * 50, 50, 50);
            g.setColor(u);
 
        }
 
        while (now != null) {
            System.out.print("(" + now.a + " " + now.b + ")");
            Color r = g.getColor();
            g.setColor(Color.red);
            g.fillOval((now.a - 1) * 50, (now.b - 1) * 50, 50, 50);
            g.setColor(r);
            now = now.next;
 
        }
        Node now2 = seq2.head;
        while (now2 != null) {
            System.out.print("(" + now2.a + " " + now2.b + ")");
            Color r = g.getColor();
            g.setColor(Color.green);
            g.fillOval((now2.a - 1) * 50, (now2.b - 1) * 50, 50, 50);
            g.setColor(r);
            now2 = now2.next;
 
        }
        System.out.println();
    }
 
    // 键的一个值被输出
    @Override
    public void keyTyped(KeyEvent e) {
 
    }
 
    // 键被按下
    @Override
 
    public void keyPressed(KeyEvent e) {
 
        System.out.print("线性表为");
 
        System.out.println();
        // System.out.println("键被按下"+e.getKeyCode());
        if (e.getKeyCode() == KeyEvent.VK_DOWN) {
 
            // System.out.println("12");
 
            y = y + 1;
            if (y >= 11) {
                y = y % 11 + 1;
            }
 
        } else if (e.getKeyCode() == KeyEvent.VK_UP) {
            y = y - 1;
            if (y < 1) {
                y = y + 10;
            }
 
        } else if (e.getKeyCode() == KeyEvent.VK_LEFT) {
            x = x - 1;
            if (x < 1) {
                x = x + 10;
            }
        } else if (e.getKeyCode() == KeyEvent.VK_RIGHT) {
 
            x = x + 1;
            if (x >= 11) {
                x = x % 11 + 1;
            }
 
        } else if (e.getKeyCode() == KeyEvent.VK_SPACE) {
            int luo1 = x;
            int luo2 = y;
 
            Node n2 = new Node(luo1, luo2);
            if (jishu % 2 != 0) {
                Node now3 = seq2.head;
                Node now2 = seq.head;
                int aaa = 1;
 
                if (arr[x][y] == 1 || arr[x][y] == 2) {
                    JOptionPane.showMessageDialog(sc, "此处已有棋子,请下别处", "错误", JOptionPane.WARNING_MESSAGE);
                    aaa = 2;
 
                }
 
                if (aaa == 1) {
 
                    jishu++;
                    seq.add(n2);
                    arr[luo1][luo2] = 1;
                    seq.tostring();
                    System.out.println("摁下空格");
                    soushang(x, y);
 
                    System.out.println("sum1" + "  " + summm);
                    if (summm == 5) {
                        seq.head = null;
                        seq2.head = null;
                    }
 
                    souxia(x, y);
                    System.out.println("sum2" + "  " + summm);
                    if (summm == 5) {
                        seq.head = null;
                        seq2.head = null;
                    }
                    summm = 1;
                    souzuo(x, y);
                    System.out.println("sum3" + "  " + summm);
                    if (summm == 5) {
                        seq.head = null;
                        seq2.head = null;
                    }
 
                    souyou(x, y);
                    System.out.println("sum4" + "  " + summm);
                    if (summm == 5) {
                        seq.head = null;
                        seq2.head = null;
                    }
                    summm = 1;
 
                    soushangzuo(x, y);
                    System.out.println("sum5" + "  " + summm);
                    if (summm == 5) {
                        seq.head = null;
                        seq2.head = null;
                    }
 
                    souyouxia(x, y);
                    System.out.println("sum6" + "  " + summm);
                    if (summm == 5) {
                        seq.head = null;
                        seq2.head = null;
                    }
                    summm = 1;
                    souyoushang(x, y);
                    System.out.println("sum7" + "  " + summm);
                    if (summm == 5) {
                        seq.head = null;
                        seq2.head = null;
                    }
                    souxiazuo(x, y);
                    if (summm == 5) {
                        seq.head = null;
                        seq2.head = null;
                    }
                    summm = 1;
                }
 
            } else {
                int aaa = 1;
 
                if (arr[x][y] == 1 || arr[x][y] == 2) {
                    JOptionPane.showMessageDialog(sc, "此处已有棋子,请下别处", "错误", JOptionPane.WARNING_MESSAGE);
                    aaa = 2;
 
                }
                if (aaa == 1) {
 
                    jishu++;
                    seq2.add(n2);
                    arr[luo1][luo2] = 2;
                    seq2.tostring();
                    System.out.println("摁下空格");
                    soushang2(x, y);
 
                    System.out.println("sum1" + "  " + summm);
                    if (summm2 == 5) {
                        seq.head = null;
                        seq2.head = null;
                    }
 
                    souxia2(x, y);
                    System.out.println("sum2" + "  " + summm);
                    if (summm2 == 5) {
                        seq.head = null;
                        seq2.head = null;
                    }
                    summm2 = 1;
                    souzuo2(x, y);
                    System.out.println("sum3" + "  " + summm);
                    if (summm2 == 5) {
                        seq.head = null;
                        seq2.head = null;
                    }
 
                    souyou2(x, y);
                    System.out.println("sum4" + "  " + summm);
                    if (summm2 == 5) {
                        seq.head = null;
                        seq2.head = null;
                    }
                    summm2 = 1;
 
                    soushangzuo2(x, y);
                    System.out.println("sum5" + "  " + summm);
                    if (summm2 == 5) {
                        seq.head = null;
                        seq2.head = null;
                    }
 
                    souyouxia2(x, y);
                    System.out.println("sum6" + "  " + summm);
                    if (summm2 == 5) {
                        seq.head = null;
                        seq2.head = null;
                    }
                    summm2 = 1;
                    souyoushang2(x, y);
                    System.out.println("sum7" + "  " + summm);
                    if (summm2 == 5) {
                        seq.head = null;
                        seq2.head = null;
                    }
                    souxiazuo2(x, y);
                    if (summm2 == 5) {
                        seq.head = null;
                        seq2.head = null;
                    }
                    summm2 = 1;
 
                }
            }
            for (int i = 1; i <= 10; i++) {
                for (int k = 1; k <= 10; k++) {
                    System.out.print(arr[i][k] + " ");
 
                }
                System.out.println();
 
            }
 
        }
        kai.huan(x, y);
 
        // 调用repaint()函数,来重绘界面
        this.repaint();
    }
 
    class Node {// 设置 节点类
        int a;
        int b;
        Node next;
 
        Node(int a, int b) {
            this.a = a;
            this.b = b;
            this.next = null;
        }
 
    }
 
    class seqlist {// 设置链表类
        Node head;
        Node tail;
 
        int n = 0;
 
        public seqlist(Node head) {
            // TODO Auto-generated constructor stub
            this.head = head;
            this.tail = head;
            n++;
        }
 
        void add(Node p) {
            Node now = head;
            p.next = now;
            head = p;
            n++;
 
        }
 
        void tostring() {
            Node now = head;
            System.out.print("线性表为");
            while (now != null) {
                System.out.print(now.a + ",");
                now = now.next;
            }
            System.out.println();
 
        }
 
        int length() {
            return n;
 
        }
 
        void insert(int a, Node b) {
            Node now1 = head;
            for (int i = 0; i < a - 1; i++) {
                now1 = now1.next;
            }
            b.next = now1.next;
            now1.next = b;
            n++;
        }
 
        void delete(int a) {
            Node now1 = head;
            for (int i = 0; i < a - 1; i++) {
                now1 = now1.next;
            }
            now1.next = now1.next.next;
            n--;
 
        }
 
        int geta(int n) {
            Node now1 = head;
            for (int i = 0; i < n - 1; i++) {
                now1 = now1.next;
 
            }
            return now1.a;
 
        }
 
        void huan(int a, int b) {
            head.a = a;
            head.b = b;
 
        }
 
        int getb(int n) {
            Node now1 = head;
            for (int i = 0; i < n - 1; i++) {
                now1 = now1.next;
 
            }
            return now1.b;
 
        }
 
    }
 
    // 键被释放
    @Override
    public void keyReleased(KeyEvent e) {
    }
}

以上就是本文的全部内容,希望对大家的学习有所帮助,也希望大家多多支持我们。

(0)

相关推荐

  • java基于swing实现的五子棋游戏代码

    本文实例讲述了java基于swing实现的五子棋游戏代码.分享给大家供大家参考. 主要功能代码如下: 复制代码 代码如下: import java.awt.*; import javax.swing.*; import java.awt.event.*; public class Main extends JFrame implements ActionListener{         private static final long serialVersionUID = 1L;      

  • Java实现五子棋(附详细源码)

    本文实例为大家分享了Java实现五子棋游戏的具体代码,供大家参考,具体内容如下 学习目的:熟悉java中swing类与java基础知识的巩固.(文末有源代码文件和打包的jar文件) 效果图: 思路:**1.首先构建一个Frame框架,来设置菜单选项与按钮点击事件. MyFrame.java文件代码如下 package StartGame; import javax.swing.ButtonGroup; import javax.swing.Icon; import javax.swing.JBu

  • java实现五子棋小游戏

    java实现五子棋小游戏 package Gomoku; import java.awt.Toolkit; import javax.swing.JFrame; public class GomokuFrame extends JFrame { //定义一个操作面板 OperatorPane op=null; public GomokuFrame() { //设置名称 this.setTitle("五子棋"); //设置窗口大小 this.setSize(510,510); //设置窗

  • Java编程实现五子棋人人对战代码示例

    利用Java,在控制台操作下,编写的五子棋,作为复习二维数组,面向对象等基础知识.w表示白棋,b表示黑棋 import java.util.Scanner; public class MainMethod { public static char[][] c = new char[10][10]; public static void main(String[] args) { MainMethod mainMethod = new MainMethod(); mainMethod.init()

  • Java实现五子棋游戏的完整代码

    用Java编写简单的五子棋,供大家参考,具体内容如下 前言 这两天在空闲时间做了个五子棋项目,分享给大家看一下,界面是这样的: 界面很丑我知道,本人虽有几年PS基础,但知识浅薄,审美观不尽人意,做到如此实属极限(其实我懒得做了),大家将就着看看吧. 下面放出代码,为方便大家参考,我几乎每条代码都标有注释.    测试类代码 public class Test { public static void main(String[] args) { MyJFrame mj=new MyJFrame()

  • Java实现五子棋网络版

    本文实例为大家分享了Java实现五子棋网络版的具体代码,供大家参考,具体内容如下 需求分析: 对于网络五子棋而言,在普通五子棋的基础上需要添加以下功能: 1.拥有服务器端和客户端,用户通过客户端登录服务器后可与其他登录的用户进行对弈 2.服务器支持多组用户同时进行对弈 3.用户可以在服务器上创建新游戏或加入已创建的游戏 4.用户在下棋的时候可以进行聊天交流 由上可以知道需要实现的功能: ·提供服务器和客户端的功能 ·服务器将监听客户端的登录情况并允许多个客户端进行登录 ·用户通过客户端可以登录服

  • Java实现两人五子棋游戏(二) 画出棋盘

    本文为大家分享了java画出五子棋游戏棋盘的方法,供大家参考,具体内容如下 棋盘模块: 画五子棋棋盘:19条横线.19条竖线 步骤一:显示棋盘 我有一张名为chessboard.png的棋盘,位置为根目录/res/drawable/chessboard/png,现在我要显示这张图片. DrawChessBoard.java package xchen.test.simpleGobang; import java.awt.Graphics; import java.awt.Image; impor

  • java实现单人版五子棋游戏

    本文实例讲述了java实现的五子棋游戏代码,分享给大家供大家参考,具体代码如下 package gyb.exam; import java.awt.BorderLayout; import java.awt.Color; import java.awt.Dimension; import java.awt.Font; import java.awt.Graphics; import java.awt.Point; import java.awt.Toolkit; import java.awt.

  • java实现单机版五子棋

    这个小游戏是我和我姐们儿的JAVA课程设计,也是我做的第一个JAVA项目,适合初学者,希望能帮到那些被JAVA课设所困扰的孩纸们~~~ 一.该游戏需要实现 1.设计主框架,界面. 2.利用ActionListener接口实现按钮事件的监听. 3.重新开始功能的实现. 4.悔棋功能的实现. 5.退出功能的实现. 6.棋盘中棋子点类的定义. 7.利用MouseListener接口实现事件监听,并实现接口里的所有方法. 8.当鼠标移动到棋盘上的交点上,且该点上无棋子时能够变成小手形状. 9.点击棋盘时

  • Java实现五子棋AI算法

    五子棋AI算法 也算是一个典型的游戏AI算法,一些棋类的AI算法都可以参考实现,下面是Java实现代码 棋盘抽象接口 import java.util.List; public interface IChessboard { //取得棋盘最大横坐标 public int getMaxX(); //最大纵坐标 public int getMaxY(); //取得当前所有空白点,这些点才可以下棋 public List<Point> getFreePoints(); } 棋子类实现 //棋子类 p

随机推荐