當前位置:
首頁 > 知識 > Java的實現聯機五子棋

Java的實現聯機五子棋


代碼字數太多了只能有的截圖了,!



Java的實現聯機五子棋


Config.xml?122B


50 8 8


Main.java?112B


進口面板公共課主 public static void main(String [] args){ 新的MainUI(); }}

[文件] Config.java?5KB


包裝面板import java.awt.Color;import java.io.File;import javax.xml.parsers.DocumentBuilder;import javax.xml.parsers.DocumentBuilderFactory;import org.w3c.dom.Document;import org.w3c.dom.NodeList;公共類Config { 私有靜態int埠; / ** *?à×ó±??ò?àà? * / public static final int STARTX = 50; / ** *?Yé?±??ò?àà? * / 公共靜態最終int STARTY = 90; / ** *???? * / public static int SIZE = 50; / ** *DDêy * / public static int ROW = 10; / ** *áDêy * / public static int CLOUNM = 10; 私人靜態顏色color = Color.BLACK; private static byte [] [] chess; private static int [] notify = {-1,-1}; 靜態的 { 嘗試{ 文件f =新建文件(「Config.xml」); DocumentBuilderFactory factory = DocumentBuilderFactory .newInstance(); DocumentBuilder builder = factory.newDocumentBuilder(); 文檔doc = builder.parse(f); NodeList nl = doc.getElementsByTagName(「CONFIG」); // SIZE = Integer.parseInt(doc.getElementsByTagName(「SIZE」)。item(0).getFirstChild()。getNodeValue())); for(int i = 0; i = 0; ii ++,jj--){ if(chess [ii] [jj] == c && flag == false){ n = 1; flag = true; } else if(chess [ii] [jj] == c && flag == true){ 的n ++; } else if(chess [ii] [jj]!= c){ n = 0 flag = false; } if(5 == n){ n = 0 flag = false; 返回真 } } } } n = 0 flag = false; //?D??óòD± for(int i = 0; i


[文件] MainUI.java?3KB


包裝面板進口遊戲import java.awt.BorderLayout;import java.awt.Color;import java.awt.Graphics;import javax.swing.ImageIcon;import javax.swing.JFrame;import javax.swing.JLabel;import javax.swing.JMenu;import javax.swing.JMenuBar;import javax.swing.JMenuItem;import javax.swing.JPanel;@SuppressWarnings( 「串列」)公共類MainUI擴展了JFrame { 私人MenuListener menupolice; 私人JMenuBar菜單; 私人JMenu菜單 private JMenuItem itemStart; 私有JMenuItem itemjoin; private JMenuItem itemOver; public MainUI(){ setSize(2 * Config.STARTX + Config.CLOUNM * Config.SIZE,Config.STARTY + Config.SIZE *(Config.ROW + 1)); setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE); setLayout(new BorderLayout()); itemStart = new JMenuItem(「創建遊戲」); itemjoin = new JMenuItem(「加入遊戲」); itemOver = new JMenuItem(「結束遊戲」); menu = new JMenu(「菜單」); menubar = new JMenuBar(); menu.add(itemStart); menu.add(itemjoin); menu.add(itemOver); menubar.add(菜單); add(menubar,BorderLayout.NORTH); menupolice = new MenuListener(itemStart,itemjoin,itemOver,this); itemStart.addActionListener(menupolice); itemjoin.addActionListener(menupolice); itemOver.addActionListener(menupolice); //添加窗體背景圖片 ImageIcon icon = new ImageIcon(「1.jpg」); JLabel label = new JLabel(icon); getLayeredPane()。add(label,new Integer(Integer.MIN_VALUE)); label.setBounds(0,0,1000,1000); ((JPanel)this.getContentPane())。setOpaque(false); ChessUtils.locateFrameCenter(本); 調用setVisible(真); 的setTitle( 「五子棋」); } / ** *重寫父類重繪方法 * / public void paint(Graphics g){ //調用父類重繪方法 super.paint(克); 的drawLine(克); drawChessMan(克); } / ** *重繪棋盤 * / private void drawLine(Graphics g){ g.setColor(Color.BLACK); //縱線 for(int i = 0; i


[文件] MyListener.java?3KB

包裝面板進口遊戲進口遊戲進口遊戲。import java.awt.event.ActionEvent;import java.awt.event.ActionListener;import java.awt.event.MouseEvent;import java.awt.event.MouseListener;import javax.swing.JFrame;import javax.swing.JMenuItem;/ ** *處理輸贏判斷以及坐標轉換 * * @author chenj_000 * * /public class MyListener實現MouseListener { / ** *滑鼠點擊觸發 * / public void mousePressed(MouseEvent e){ // 1,獲得焦點坐標 int x = e.getX(); int y = e.getY(); x =((x-Config.STARTX)+(Config.SIZE / 2))/ Config.SIZE * Config.SIZE + Config.STARTX; y =((y - Config.STARTY)+(Config.SIZE / 2))/ Config.SIZE * Config.SIZE + Config.STARTY; // 2,判斷坐標是否閑置 if(!Config.isChessMan(x,y,Config.getColor())) 返回; // 3,若坐標可用,則向配置文件發送坐標信息 Config.setX(X); Config.setY(Y);



Java的實現聯機五子棋




Java的實現聯機五子棋


喜歡這篇文章嗎?立刻分享出去讓更多人知道吧!

本站內容充實豐富,博大精深,小編精選每日熱門資訊,隨時更新,點擊「搶先收到最新資訊」瀏覽吧!


請您繼續閱讀更多來自 java吧 的精彩文章:

神奇的Canvas貝塞爾曲線畫心,程序員的表白
如何才算掌握Java?學習中的你一定要知道
20個非常有用的Java 程序片段
一個資深程序猿對 Java初學者的學習思維路線建議
java學習:你知道嗎?Java常見的幾大代碼

TAG:java吧 |

您可能感興趣

四屏聯機很兇殘 微軟Surface Hub 2公開
微軟Surface Hub 2正式發布!四屏聯機震撼
谷歌AR塗鴉Just a Line開始支持雙人聯機
Magic Leap欲實現與ARKit/ARCore聯機娛樂
四女神online怎麼聯機 四女神ol聯機補丁使用教程
Steam聯機遊戲——Duck Game
國行Nintendo Switch細節公布:主機保修一年 聯機體驗更暢快
《Nostos》全球Alpha測試結束 VR聯機開放沉浸式體驗
吃雞遊戲《瘋狂正義》Xbox One與Switch聯機演示!
據傳Xbox One正與Steam就跨平台聯機進行合作
VR派對遊戲《Acron:Attack of the Squirrels!》登陸Oculus,支持八人本地聯機
PC聯機Switch《火箭聯盟》今年實現跨平台對戰
PC聯機Switch 《火箭聯盟》今年實現跨平台對戰
Xbox Live進軍手機遊戲 和iOS/Android全面跨平台聯機指日可待
腐蝕rust搭建Rust伺服器及聯機教程
聯機已出!星露穀物語聯機測試服正式於steam上線!
四女神online聯機污穢的黑暗單刷方法
流浪Vagante聯機模式玩法技巧
Vloger 的利器:CamFi 卡菲全能版聯機拍攝方案
支持三人聯機,RPG遊戲《Preta:Vendetta Rising》本周登陸PSVR平台