<del id="d4fwx"><form id="d4fwx"></form></del>
      <del id="d4fwx"><form id="d4fwx"></form></del><del id="d4fwx"><form id="d4fwx"></form></del>

            <code id="d4fwx"><abbr id="d4fwx"></abbr></code>
          • java課程設計AI代碼 ai編程課程

            《Java》期末課程設計

            import java.io.BufferedReader;

            創(chuàng)新互聯(lián)公司網(wǎng)站建設十年堅持,服務企業(yè)網(wǎng)站設計、響應式網(wǎng)站建設等網(wǎng)站建設服務。上1000+企業(yè)的合作經(jīng)驗,幫助我們?yōu)榉掌髽I(yè)不斷提升價值。為企業(yè)建設開發(fā)網(wǎng)站和維護,主推個性化定制型網(wǎng)站設計

            import java.io.InputStreamReader;

            public class QuestionOne {

            /**

            * 編程將從鍵盤輸入文本中的子字符串“word”替換為字符串“world”, 并刪除所有的子字符串“this”。

            * 序程要求:程序中要包含有注釋,對于使用的變量和方法的功能要加以說明。

            */

            public static void main(String[] args) {

            BufferedReader reader = new BufferedReader(new InputStreamReader(

            System.in));

            String message = null; // 存儲用戶輸入的字符串

            try {

            while ((message = reader.readLine()) != null) {

            // 打印處理前的字符串

            System.out.println("輸入的字符串為:" + message);

            // 把 word 替換為 world

            message = message.replaceAll("word", "world");

            // 把 this 替換為 空

            message = message.replaceAll("this", "");

            // 打印處理后的字符串

            System.out.println("處理后為:" + message);

            }

            } catch (Exception e) {

            e.printStackTrace();

            System.out.println("出現(xiàn)異常,程序退出!");

            }

            }

            }

            貪吃蛇 java代碼

            自己寫著玩的,很簡單,你試一試哦...

            主要用了javax.swing.Timer這個類:

            import java.awt.*;

            import javax.swing.*;

            @SuppressWarnings("serial")

            public class MainClass extends JFrame {

            ControlSnake control;

            Toolkit kit;

            Dimension dimen;

            public static void main(String[] args) {

            new MainClass("my snake");

            }

            public MainClass(String s) {

            super(s);

            control = new ControlSnake();

            control.setFocusable(true);

            kit = Toolkit.getDefaultToolkit();

            dimen = kit.getScreenSize();

            add(control);

            setLayout(new BorderLayout());

            setLocation(dimen.width / 3, dimen.height / 3);// dimen.width/3,dimen.height/3

            setSize(FWIDTH, FHEIGHT);

            setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);

            setResizable(false);

            setVisible(true);

            }

            public static final int FWIDTH = 315;

            public static final int FHEIGHT = 380;

            }

            import java.util.*;

            import java.awt.*;

            import java.awt.event.*;

            import javax.swing.*;

            import javax.swing.Timer;

            import java.util.Random;

            @SuppressWarnings("serial")

            public class ControlSnake extends JPanel implements ActionListener {

            Random rand;

            ArrayListPoint list, listBody;

            String str, str1;

            static boolean key;

            int x, y, dx, dy, fx, fy, flag;

            int snakeBody;

            int speed;

            public ControlSnake() {

            snakeBody = 1;

            str = "上下左右方向鍵控制 P鍵暫停...";

            str1 = "現(xiàn)在的長度為:" + snakeBody;

            key = true;

            flag = 1;

            speed = 700;

            rand = new Random();

            list = new ArrayListPoint();

            listBody = new ArrayListPoint();

            x = 5;

            y = 5;

            list.add(new Point(x, y));

            listBody.add(list.get(0));

            dx = 10;

            dy = 0;

            fx = rand.nextInt(30) * 10 + 5;// 2

            fy = rand.nextInt(30) * 10 + 5;// 2

            setBackground(Color.WHITE);

            setSize(new Dimension(318, 380));

            final Timer time = new Timer(speed, this);

            time.start();

            addKeyListener(new KeyAdapter() {

            public void keyPressed(KeyEvent e) {

            if (e.getKeyCode() == 37) {

            dx = -10;

            dy = 0;

            } else if (e.getKeyCode() == 38) {

            dx = 0;

            dy = -10;

            } else if (e.getKeyCode() == 39) {

            dx = 10;

            dy = 0;

            } else if (e.getKeyCode() == 40) {

            dx = 0;

            dy = 10;

            } else if (e.getKeyCode() == 80) {

            if (flag % 2 == 1) {

            time.stop();

            }

            if (flag % 2 == 0) {

            time.start();

            }

            flag++;

            }

            }

            });

            }

            public void paint(Graphics g) {

            g.setColor(Color.WHITE);

            g.fillRect(0, 0, 400, 400);

            g.setColor(Color.DARK_GRAY);

            g.drawLine(3, 3, 305, 3);

            g.drawLine(3, 3, 3, 305);

            g.drawLine(305, 3, 305, 305);

            g.drawLine(3, 305, 305, 305);

            g.setColor(Color.PINK);

            for (int i = 0; i listBody.size(); i++) {

            g.fillRect(listBody.get(i).x, listBody.get(i).y, 9, 9);

            }

            g.fillRect(x, y, 9, 9);

            g.setColor(Color.ORANGE);

            g.fillRect(fx, fy, 9, 9);

            g.setColor(Color.DARK_GRAY);

            str1 = "現(xiàn)在的長度為:" + snakeBody;

            g.drawString(str, 10, 320);

            g.drawString(str1, 10, 335);

            }

            public void actionPerformed(ActionEvent e) {

            x += dx;

            y += dy;

            if (makeOut() == false) {

            JOptionPane.showMessageDialog(null, "重新開始......");

            speed = 700;

            snakeBody = 1;

            x = 5;

            y = 5;

            list.clear();

            list.add(new Point(x, y));

            listBody.clear();

            listBody.add(list.get(0));

            dx = 10;

            dy = 0;

            }

            addPoint(x, y);

            if (x == fx y == fy) {

            speed = (int) (speed * 0.8);//速度增加參數(shù)

            if (speed 200) {

            speed = 100;

            }

            fx = rand.nextInt(30) * 10 + 5;// 2

            fy = rand.nextInt(30) * 10 + 5;// 2

            snakeBody++;// 2

            } // 2

            repaint();

            }

            public void addPoint(int xx, int yy) {

            // 動態(tài)的記錄最新發(fā)生的50步以內(nèi)的移動過的坐標

            // 并畫出最新的snakeBody

            if (list.size() 100) {//蛇身長度最長為100

            list.add(new Point(xx, yy));

            } else {

            list.remove(0);

            list.add(new Point(xx, yy));

            }

            if (snakeBody == 1) {

            listBody.remove(0);

            listBody.add(0, list.get(list.size() - 1));

            } else {

            listBody.clear();

            if (list.size() snakeBody) {

            for (int i = list.size() - 1; i 0; i--) {

            listBody.add(list.get(i));

            }

            } else {

            for (int i = list.size() - 1; listBody.size() snakeBody; i--) {

            listBody.add(list.get(i));

            }

            }

            }

            }

            public boolean makeOut() {

            if ((x 3 || y 3) || (x 305 || y 305)) {

            return false;

            }

            for (int i = 0; i listBody.size() - 1; i++) {

            for (int j = i + 1; j listBody.size(); j++) {

            if (listBody.get(i).equals(listBody.get(j))) {

            return false;

            }

            }

            }

            return true;

            }

            }

            求Java課程設計—小游戲(含源代碼)

            Tank——坦克大戰(zhàn)(簡潔版)源代碼-------(此文檔是自己在韓順平教程總結而來)

            *????功能:?1.防止敵人的坦克重疊運動

            *?????????????(決定把判斷是否碰撞的函數(shù)寫到EnemyTank類)

            *??????????2.可以分關

            *??????????????2.1?(做一個開始的Panel,它是一個空的)

            *??????????????2.2?開始字體閃爍

            *??????????3.可以在玩游戲的時候,暫停和繼續(xù)

            *??????????????3.1當用戶點擊暫停時,子彈的速度和坦克速度設為0,并讓坦克的方向

            *?????????????????不要發(fā)生變化。

            *??????????4.可以記錄玩家的成績

            *??????????????4.1用文件流的方式(小游戲)[大游戲是用的數(shù)據(jù)庫cs,bs結構,三國]

            *??????????????4.2單寫一個記錄類,完成對玩家的記錄

            *??????????????4.3先完成保存共擊毀了多少輛敵人坦克的功能

            *??????????????4.4存盤退出游戲,可以記錄當時的敵人的坦克坐標,并可以恢復

            *??????????5.java如何操作聲音文件

            */

            求java編寫的五子棋代碼,要有電腦AI的

            java網(wǎng)絡五子棋

            下面的源代碼分為4個文件;

            chessClient.java:客戶端主程序。

            chessInterface.java:客戶端的界面。

            chessPad.java:棋盤的繪制。

            chessServer.java:服務器端。

            可同時容納50個人同時在線下棋,聊天。

            沒有加上詳細注釋,不過絕對可以運行,j2sdk1.4下通過。

            /*********************************************************************************************

            1.chessClient.java

            **********************************************************************************************/

            import java.awt.*;

            import java.awt.event.*;

            import java.io.*;

            import java.net.*;

            import java.util.*;

            class clientThread extends Thread

            {

            chessClient chessclient;

            clientThread(chessClient chessclient)

            {

            this.chessclient=chessclient;

            }

            public void acceptMessage(String recMessage)

            {

            if(recMessage.startsWith("/userlist "))

            {

            StringTokenizer userToken=new StringTokenizer(recMessage," ");

            int userNumber=0;

            chessclient.userpad.userList.removeAll();

            chessclient.inputpad.userChoice.removeAll();

            chessclient.inputpad.userChoice.addItem("所有人");

            while(userToken.hasMoreTokens())

            {

            String user=(String)userToken.nextToken(" ");

            if(userNumber0 !user.startsWith("[inchess]"))

            {

            chessclient.userpad.userList.add(user);

            chessclient.inputpad.userChoice.addItem(user);

            }

            userNumber++;

            }

            chessclient.inputpad.userChoice.select("所有人");

            }

            else if(recMessage.startsWith("/yourname "))

            {

            chessclient.chessClientName=recMessage.substring(10);

            chessclient.setTitle("Java五子棋客戶端 "+"用戶名:"+chessclient.chessClientName);

            }

            else if(recMessage.equals("/reject"))

            {

            try

            {

            chessclient.chesspad.statusText.setText("不能加入游戲");

            chessclient.controlpad.cancelGameButton.setEnabled(false);

            chessclient.controlpad.joinGameButton.setEnabled(true);

            chessclient.controlpad.creatGameButton.setEnabled(true);

            }

            catch(Exception ef)

            {

            chessclient.chatpad.chatLineArea.setText("chessclient.chesspad.chessSocket.close無法關閉");

            }

            chessclient.controlpad.joinGameButton.setEnabled(true);

            }

            else if(recMessage.startsWith("/peer "))

            {

            chessclient.chesspad.chessPeerName=recMessage.substring(6);

            if(chessclient.isServer)

            {

            chessclient.chesspad.chessColor=1;

            chessclient.chesspad.isMouseEnabled=true;

            chessclient.chesspad.statusText.setText("請黑棋下子");

            }

            else if(chessclient.isClient)

            {

            chessclient.chesspad.chessColor=-1;

            chessclient.chesspad.statusText.setText("已加入游戲,等待對方下子...");

            }

            }

            else if(recMessage.equals("/youwin"))

            {

            chessclient.isOnChess=false;

            chessclient.chesspad.chessVictory(chessclient.chesspad.chessColor);

            chessclient.chesspad.statusText.setText("對方退出,請點放棄游戲退出連接");

            chessclient.chesspad.isMouseEnabled=false;

            }

            else if(recMessage.equals("/OK"))

            {

            chessclient.chesspad.statusText.setText("創(chuàng)建游戲成功,等待別人加入...");

            }

            else if(recMessage.equals("/error"))

            {

            chessclient.chatpad.chatLineArea.append("傳輸錯誤:請退出程序,重新加入 \n");

            }

            else

            {

            chessclient.chatpad.chatLineArea.append(recMessage+"\n");

            chessclient.chatpad.chatLineArea.setCaretPosition(

            chessclient.chatpad.chatLineArea.getText().length());

            }

            }

            public void run()

            {

            String message="";

            try

            {

            while(true)

            {

            message=chessclient.in.readUTF();

            acceptMessage(message);

            }

            }

            catch(IOException es)

            {

            }

            }

            }

            public class chessClient extends Frame implements ActionListener,KeyListener

            {

            userPad userpad=new userPad();

            chatPad chatpad=new chatPad();

            controlPad controlpad=new controlPad();

            chessPad chesspad=new chessPad();

            inputPad inputpad=new inputPad();

            Socket chatSocket;

            DataInputStream in;

            DataOutputStream out;

            String chessClientName=null;

            String host=null;

            int port=4331;

            boolean isOnChat=false; //在聊天?

            boolean isOnChess=false; //在下棋?

            boolean isGameConnected=false; //下棋的客戶端連接?

            boolean isServer=false; //如果是下棋的主機

            boolean isClient=false; //如果是下棋的客戶端

            Panel southPanel=new Panel();

            Panel northPanel=new Panel();

            Panel centerPanel=new Panel();

            Panel westPanel=new Panel();

            Panel eastPanel=new Panel();

            chessClient()

            {

            super("Java五子棋客戶端");

            setLayout(new BorderLayout());

            host=controlpad.inputIP.getText();

            westPanel.setLayout(new BorderLayout());

            westPanel.add(userpad,BorderLayout.NORTH);

            westPanel.add(chatpad,BorderLayout.CENTER);

            westPanel.setBackground(Color.pink);

            inputpad.inputWords.addKeyListener(this);

            chesspad.host=controlpad.inputIP.getText();

            centerPanel.add(chesspad,BorderLayout.CENTER);

            centerPanel.add(inputpad,BorderLayout.SOUTH);

            centerPanel.setBackground(Color.pink);

            controlpad.connectButton.addActionListener(this);

            controlpad.creatGameButton.addActionListener(this);

            controlpad.joinGameButton.addActionListener(this);

            controlpad.cancelGameButton.addActionListener(this);

            controlpad.exitGameButton.addActionListener(this);

            controlpad.creatGameButton.setEnabled(false);

            controlpad.joinGameButton.setEnabled(false);

            controlpad.cancelGameButton.setEnabled(false);

            southPanel.add(controlpad,BorderLayout.CENTER);

            southPanel.setBackground(Color.pink);

            addWindowListener(new WindowAdapter()

            {

            public void windowClosing(WindowEvent e)

            {

            if(isOnChat)

            {

            try

            {

            chatSocket.close();

            }

            catch(Exception ed)

            {

            }

            }

            if(isOnChess || isGameConnected)

            {

            try

            {

            chesspad.chessSocket.close();

            }

            catch(Exception ee)

            {

            }

            }

            System.exit(0);

            }

            public void windowActivated(WindowEvent ea)

            {

            }

            });

            add(westPanel,BorderLayout.WEST);

            add(centerPanel,BorderLayout.CENTER);

            add(southPanel,BorderLayout.SOUTH);

            pack();

            setSize(670,548);

            setVisible(true);

            setResizable(false);

            validate();

            }

            public boolean connectServer(String serverIP,int serverPort) throws Exception

            {

            try

            {

            chatSocket=new Socket(serverIP,serverPort);

            in=new DataInputStream(chatSocket.getInputStream());

            out=new DataOutputStream(chatSocket.getOutputStream());

            clientThread clientthread=new clientThread(this);

            clientthread.start();

            isOnChat=true;

            return true;

            }

            catch(IOException ex)

            {

            chatpad.chatLineArea.setText("chessClient:connectServer:無法連接,建議重新啟動程序 \n");

            }

            return false;

            }

            public void actionPerformed(ActionEvent e)

            {

            if(e.getSource()==controlpad.connectButton)

            {

            host=chesspad.host=controlpad.inputIP.getText();

            try

            {

            if(connectServer(host,port))

            {

            chatpad.chatLineArea.setText("");

            controlpad.connectButton.setEnabled(false);

            controlpad.creatGameButton.setEnabled(true);

            controlpad.joinGameButton.setEnabled(true);

            chesspad.statusText.setText("連接成功,請創(chuàng)建游戲或加入游戲");

            }

            }

            catch(Exception ei)

            {

            chatpad.chatLineArea.setText("controlpad.connectButton:無法連接,建議重新啟動程序 \n");

            }

            }

            if(e.getSource()==controlpad.exitGameButton)

            {

            if(isOnChat)

            {

            try

            {

            chatSocket.close();

            }

            catch(Exception ed)

            {

            }

            }

            if(isOnChess || isGameConnected)

            {

            try

            {

            chesspad.chessSocket.close();

            }

            catch(Exception ee)

            {

            }

            }

            System.exit(0);

            }

            if(e.getSource()==controlpad.joinGameButton)

            {

            String selectedUser=userpad.userList.getSelectedItem();

            if(selectedUser==null || selectedUser.startsWith("[inchess]") ||

            selectedUser.equals(chessClientName))

            {

            chesspad.statusText.setText("必須先選定一個有效用戶");

            }

            else

            {

            try

            {

            if(!isGameConnected)

            {

            if(chesspad.connectServer(chesspad.host,chesspad.port))

            {

            isGameConnected=true;

            isOnChess=true;

            isClient=true;

            controlpad.creatGameButton.setEnabled(false);

            controlpad.joinGameButton.setEnabled(false);

            controlpad.cancelGameButton.setEnabled(true);

            chesspad.chessthread.sendMessage("/joingame "+userpad.userList.getSelectedItem()+" "+chessClientName);

            }

            }

            else

            {

            isOnChess=true;

            isClient=true;

            controlpad.creatGameButton.setEnabled(false);

            controlpad.joinGameButton.setEnabled(false);

            controlpad.cancelGameButton.setEnabled(true);

            chesspad.chessthread.sendMessage("/joingame "+userpad.userList.getSelectedItem()+" "+chessClientName);

            }

            }

            catch(Exception ee)

            {

            isGameConnected=false;

            isOnChess=false;

            isClient=false;

            controlpad.creatGameButton.setEnabled(true);

            controlpad.joinGameButton.setEnabled(true);

            controlpad.cancelGameButton.setEnabled(false);

            chatpad.chatLineArea.setText("chesspad.connectServer無法連接 \n"+ee);

            }

            }

            }

            if(e.getSource()==controlpad.creatGameButton)

            {

            try

            {

            if(!isGameConnected)

            {

            if(chesspad.connectServer(chesspad.host,chesspad.port))

            {

            isGameConnected=true;

            isOnChess=true;

            isServer=true;

            controlpad.creatGameButton.setEnabled(false);

            controlpad.joinGameButton.setEnabled(false);

            controlpad.cancelGameButton.setEnabled(true);

            chesspad.chessthread.sendMessage("/creatgame "+"[inchess]"+chessClientName);

            }

            }

            else

            {

            isOnChess=true;

            isServer=true;

            controlpad.creatGameButton.setEnabled(false);

            controlpad.joinGameButton.setEnabled(false);

            controlpad.cancelGameButton.setEnabled(true);

            chesspad.chessthread.sendMessage("/creatgame "+"[inchess]"+chessClientName);

            }

            }

            catch(Exception ec)

            {

            isGameConnected=false;

            isOnChess=false;

            isServer=false;

            controlpad.creatGameButton.setEnabled(true);

            controlpad.joinGameButton.setEnabled(true);

            controlpad.cancelGameButton.setEnabled(false);

            ec.printStackTrace();

            chatpad.chatLineArea.setText("chesspad.connectServer無法連接 \n"+ec);

            }

            }

            if(e.getSource()==controlpad.cancelGameButton)

            {

            if(isOnChess)

            {

            chesspad.chessthread.sendMessage("/giveup "+chessClientName);

            chesspad.chessVictory(-1*chesspad.chessColor);

            controlpad.creatGameButton.setEnabled(true);

            controlpad.joinGameButton.setEnabled(true);

            controlpad.cancelGameButton.setEnabled(false);

            chesspad.statusText.setText("請建立游戲或者加入游戲");

            }

            if(!isOnChess)

            {

            controlpad.creatGameButton.setEnabled(true);

            controlpad.joinGameButton.setEnabled(true);

            controlpad.cancelGameButton.setEnabled(false);

            chesspad.statusText.setText("請建立游戲或者加入游戲");

            }

            isClient=isServer=false;

            }

            }

            public void keyPressed(KeyEvent e)

            {

            TextField inputWords=(TextField)e.getSource();

            if(e.getKeyCode()==KeyEvent.VK_ENTER)

            {

            if(inputpad.userChoice.getSelectedItem().equals("所有人"))

            {

            try

            {

            out.writeUTF(inputWords.getText());

            inputWords.setText("");

            }

            catch(Exception ea)

            {

            chatpad.chatLineArea.setText("chessClient:KeyPressed無法連接,建議重新連接 \n");

            userpad.userList.removeAll();

            inputpad.userChoice.removeAll();

            inputWords.setText("");

            controlpad.connectButton.setEnabled(true);

            }

            }

            else

            {

            try

            {

            out.writeUTF("/"+inputpad.userChoice.getSelectedItem()+" "+inputWords.getText());

            inputWords.setText("");

            }

            catch(Exception ea)

            {

            chatpad.chatLineArea.setText("chessClient:KeyPressed無法連接,建議重新連接 \n");

            userpad.userList.removeAll();

            inputpad.userChoice.removeAll();

            inputWords.setText("");

            controlpad.connectButton.setEnabled(true);

            }

            }

            }

            }

            public void keyTyped(KeyEvent e)

            {

            }

            public void keyReleased(KeyEvent e)

            {

            }

            public static void main(String args[])

            {

            chessClient chessClient=new chessClient();

            }

            }

            /******************************************************************************************

            下面是:chessInteface.java

            ******************************************************************************************/

            import java.awt.*;

            import java.awt.event.*;

            import java.io.*;

            import java.net.*;

            class userPad extends Panel

            {

            List userList=new List(10);

            userPad()

            {

            setLayout(new BorderLayout());

            for(int i=0;i50;i++)

            {

            userList.add(i+"."+"沒有用戶");

            }

            add(userList,BorderLayout.CENTER);

            }

            }

            class chatPad extends Panel

            {

            TextArea chatLineArea=new TextArea("",18,30,TextArea.SCROLLBARS_VERTICAL_ONLY);

            chatPad()

            {

            setLayout(new BorderLayout());

            add(chatLineArea,BorderLayout.CENTER);

            }

            }

            class controlPad extends Panel

            {

            Label IPlabel=new Label("IP",Label.LEFT);

            TextField inputIP=new TextField("localhost",10);

            Button connectButton=new Button("連接主機");

            Button creatGameButton=new Button("建立游戲");

            Button joinGameButton=new Button("加入游戲");

            Button cancelGameButton=new Button("放棄游戲");

            Button exitGameButton=new Button("關閉程序");

            controlPad()

            {

            setLayout(new FlowLayout(FlowLayout.LEFT));

            setBackground(Color.pink);

            add(IPlabel);

            add(inputIP);

            add(connectButton);

            add(creatGameButton);

            add(joinGameButton);

            add(cancelGameButton);

            add(exitGameButton);

            }

            }

            class inputPad extends Panel

            {

            TextField inputWords=new TextField("",40);

            Choice userChoice=new Choice();

            inputPad()

            {

            setLayout(new FlowLayout(FlowLayout.LEFT));

            for(int i=0;i50;i++)

            {

            userChoice.addItem(i+"."+"沒有用戶");

            }

            userChoice.setSize(60,24);

            add(userChoice);

            add(inputWords);

            }

            }

            /**********************************************************************************************

            下面是:chessPad.java

            **********************************************************************************************/

            import java.awt.*;

            import java.awt.event.*;

            import java.io.*;

            import java.net.*;

            import java.util.*;

            class chessThread extends Thread

            {

            chessPad chesspad;

            chessThread(chessPad chesspad)

            {

            this.chesspad=chesspad;

            }

            public void sendMessage(String sndMessage)

            {

            try

            {

            chesspad.outData.writeUTF(sndMessage);

            }

            catch(Exception ea)

            {

            System.out.println("chessThread.sendMessage:"+ea);

            }

            }

            public void acceptMessage(String recMessage)

            {

            if(recMessage.startsWith("/chess "))

            {

            StringTokenizer userToken=new StringTokenizer(recMessage," ");

            String chessToken;

            String[] chessOpt={"-1","-1","0"};

            int chessOptNum=0;

            while(userToken.hasMoreTokens())

            {

            chessToken=(String)userToken.nextToken(" ");

            if(chessOptNum=1 chessOptNum=3)

            {

            chessOpt[chessOptNum-1]=chessToken;

            }

            chessOptNum++;

            }

            chesspad.netChessPaint(Integer.parseInt(chessOpt[0]),Integer.parseInt(chessOpt[1]),Integer.parseInt(chessOpt[2]));

            }

            else if(recMessage.startsWith("/yourname "))

            {

            chesspad.chessSelfName=recMessage.substring(10);

            }

            else if(recMessage.equals("/error"))

            {

            chesspad.statusText.setText("錯誤:沒有這個用戶,請退出程序,重新加入");

            }

            else

            {

            //System.out.println(recMessage);

            }

            }

            public void run()

            {

            String message="";

            try

            {

            while(true)

            {

            message=chesspad.inData.readUTF();

            acceptMessage(message);

            }

            }

            catch(IOException es)

            {

            }

            }

            }

            class chessPad extends Panel implements MouseListener,ActionListener

            {

            int chessPoint_x=-1,chessPoint_y=-1,chessColor=1;

            int chessBlack_x[]=new int[200];

            int chessBlack_y[]=new int[200];

            int chessWhite_x[]=new int[200];

            int chessWhite_y[]=new int[200];

            int chessBlackCount=0,chessWhiteCount=0;

            int chessBlackWin=0,chessWhiteWin=0;

            boolean isMouseEnabled=false,isWin=false,isInGame=false;

            TextField statusText=new TextField("請先連接服務器");

            Socket chessSocket;

            DataInputStream inData;

            DataOutputStream outData;

            String chessSelfName=null;

            String chessPeerName=null;

            String host=null;

            int port=4331;

            chessThread chessthread=new chessThread(this);

            chessPad()

            {

            setSize(440,440);

            setLayout(null);

            setBackground(Color.pink);

            addMouseListener(this);

            add(statusText);

            statusText.setBounds(40,5,360,24);

            statusText.setEditable(false);

            }

            public boolean connectServer(String ServerIP,int ServerPort) throws Exception

            {

            try

            {

            chessSocket=new Socket(ServerIP,ServerPort);

            inData=new DataInputStream(chessSocket.getInputStream());

            outData=new DataOutputStream(chessSocket.getOutputStream());

            chessthread.start();

            return true;

            }

            catch(IOException ex)

            {

            statusText.setText("chessPad:connectServer:無法連接 \n");

            }

            return false;

            }

            public void chessVictory(int chessColorWin)

            {

            this.removeAll();

            for(int i=0;i=chessBlackCount;i++)

            {

            chessBlack_x[i]=0;

            chessBlack_y[i]=0;

            }

            for(int i=0;i=chessWhiteCount;i++)

            {

            chessWhite_x[i]=0;

            chessWhite_y[i]=0;

            }

            chessBlackCount=0;

            chessWhiteCount=0;

            add(statusText);

            statusText.setBounds(40,5,360,24);

            if(chessColorWin==1)

            { chessBlackWin++;

            statusText.setText("黑棋勝,黑:白為"+chessBlackWin+":"+chessWhiteWin+",重新開局,等待白棋下子...");

            }

            else if(chessColorWin==-1)

            {

            chessWhiteWin++;

            statusText.setText("白棋勝,黑:白為"+chessBlackWin+":"+chessWhiteWin+",重新開局,等待黑棋下子...");

            }

            }

            public void getLocation(int a,int b,int color)

            {

            if(color==1)

            {

            chessBlack_x[chessBlackCount]=a*20;

            chessBlack_y[chessBlackCount]=b*20;

            chessBlackCount++;

            }

            else if(color==-1)

            {

            chessWhite_x[chessWhiteCount]=a*20;

            chessWhite_y[chessWhiteCount]=b*20;

            chessWhiteCount++;

            }

            }

            public boolean checkWin(int a,int b,int checkColor)

            {

            int step=1,chessLink=1,chessLinkTest=1,chessCompare=0;

            if(checkColor==1)

            {

            chessLink=1;

            for(step=1;step=4;step++)

            {

            for(chessCompare=0;chessCompare=chessBlackCount;chessCompare++)

            {

            if(((a+step)*20==chessBlack_x[chessCompare]) ((b*20)==chessBlack_y[chessCompare]))

            {

            chessLink=chessLink+1;

            if(chessLink==5)

            {

            return(true);

            }

            }

            }

            if(chessLink==(chessLinkTest+1))

            chessLinkTest++;

            else

            break;

            }

            for(step=1;step=4;step++)

            {

            for(chessCompare=0;chessCompare=chessBlackCount;chessCompare++)

            {

            if(((a-step)*20==chessBlack_x[chessCompare]) (b*20==chessBlack_y[chessCompare]))

            {

            chessLink++;

            if(chessLink==5)

            {

            return(true);

            }

            }

            }

            if(chessLink==(chessLinkTest+1))

            chessLinkTest++;

            else

            break;

            }

            chessLink=1;

            chessLinkTest=1;

            for(step=1;step=4;step++)

            {

            for(chessCompare=0;chessCompare=chessBlackCount;chessCompare++)

            {

            if((a*20==chessBlack_x[chessCompare]) ((b+step)*20==chessBlack_y[chessCompare]))

            {

            chessLink++;

            if(chessLink==5)

            {

            return(true);

            }

            }

            }

            if(chessLink==(chessLinkTest+1))

            chessLinkTest++;

            else

            break;

            }

            for(step=1;step=4;step++)

            {

            for(chessCompare=0;chessCompare=chessBlackCount;chessCompare++)

            {

            if((a*20==chessBlack_x[chessCompare]) ((b-step)*20==chessBlack_y[chessCompare]))

            {

            chessLink++;

            if(chessLink==5)

            {

            return(true);

            }

            }

            }

            if(chessLink==(chessLinkTest+1))

            chessLinkTest++;

            else

            break;

            }

            chessLink=1;

            chessLinkTest=1;

            for(step=1;step=4;step++)

            {

            for(chessCompare=0;chessCompare=chessBlackCount;chessCompare++)

            {

            if(((a-step)*20==chessBlack_x[chessCompare]) ((b+step)*20==chessBlack_y[chessCompare]))

            {

            chessLink++;

            if(chessLink==5)

            {

            return(true);

            }

            }

            }

            if(chessLink==(chessLinkTest+1))

            chessLinkTest++;

            else

            break;

            }

            for(step=1;step=4;step++)

            {

            for(chessCompare=0;chessCompare=chessBlackCount;chessCompare++)

            {

            if(((a+step)*20==chessBlack_x[chessCompare]) ((b-step)*20==chessBlack_y[chessCompare]))

            {

            chessLink++;

            if(chessLink==5)

            {

            return(true);

            }

            }

            }

            if(chessLink==(chessLinkTest+1))

            chessLinkTest++;

            else

            break;

            }

            chessLink=1;

            chessLinkTest=1;

            for(step=1;step=4;step++)

            {

            for(chessCompare=0;chessCompare=chessBlackCount;chessCompare++)

            {

            if(((a+step)*20==chessBlack_x[chessCompare]) ((b+step)*20==chessBlack_y[chessCompare]))

            {

            chessLink++;

            if(chessLink==5)

            {

            return(true);

            }

            }

            }

            if(chessLink==(chessLinkTest+1))

            chessLinkTest++;

            else

            break;

            }

            for(step=1;step=4;step++)

            {

            for(chessCompare=0;chessCompare=chessBlackCount;chessCompare++)

            {

            if(((a-step)*20==chessBlack_x[chessCompare]) ((b-step)*20==chessBlack_y[chessCompare]))

            {

            chessLink++;

            if(chessLink==5)

            {

            return(true);

            }

            }

            有關java AI編寫得問題

            0.1秒的間隔,循環(huán)就行了,這是人肉眼視覺暫留的臨界值,比這大就可能看到怪物跳著移動的效果,間隔再小一點也可以,為了性能考慮盡量大

            java課程設計題目及代碼是什么?

            java課程設計題目及代碼分別是:

            1、題目:計算器。設計內(nèi)容是設計一個圖形界面(GUI)的計算器應用程序,完成簡單的算術運算。

            設計要求是設計的計算器應用程序可以完成家法、減法、乘法、除法和取余運算。且有小數(shù)點、正負號、求倒數(shù)、退格和清零功能。

            2、代碼:

            數(shù)字按鈕NumberButton類如下:

            import java.awt.

            import java.awt.event.

            import javax.swing.

            public class NumberButton extends Button.

            {

            int number.

            public NumberButton(int number).

            {

            super(""+number).

            this.number=number.

            setForeground(Color.blue).

            }

            public int getNumber().

            {

            return number;

            }

            }

            其它java課程設計題目及代碼是:

            題目:華容道。編寫一個按鈕的子類,使用該子類創(chuàng)建的對象代表華容道中的人物。通過焦點事件控制人物顏色,當人物獲得焦點時顏色為藍色,當失去焦點時顏色為灰色。

            通過鍵盤事件和鼠標事件來實現(xiàn)曹操、關羽等人物的移動。當人物上發(fā)生鼠標事件或鍵盤事件時,如果鼠標指針的位置是在人物的下方(也就是組件的下半部分)或按下鍵盤的“↓“鍵,該人物向下移動。向左、向右和向上的移動原理類似。

            代碼是:

            String name[]={"曹操","關羽","張","劉","馬","許","兵","兵","兵","兵"}.

            for(int i=0;iname.length;i++).

            {

            person[i]=new Person(i,name[i]).

            person[i].addKeyListener(this).

            person[i].addMouseListener(this).

            //? ? ?person[i].addFocusListener(new Person).

            add(person[i]).

            }

            person[0].setBounds(104,54,100,100).

            person[1].setBounds(104,154,100,50).

            person[2].setBounds(54,154,50,100).

            person[3].setBounds(204,154,50,100).

            person[4].setBounds(54,54,50,100).

            person[5].setBounds(204,54,50,100);

            person[6].setBounds(54,254,50,50);

            person[7].setBounds(204,254,50,50);

            person[8].setBounds(104,204,50,50);

            person[9].setBounds(154,204,50,50);

            新聞名稱:java課程設計AI代碼 ai編程課程
            文章路徑:http://www.jbt999.com/article48/hppehp.html

            成都網(wǎng)站建設公司_創(chuàng)新互聯(lián),為您提供做網(wǎng)站域名注冊、全網(wǎng)營銷推廣、企業(yè)建站、App開發(fā)商城網(wǎng)站

            廣告

            聲明:本網(wǎng)站發(fā)布的內(nèi)容(圖片、視頻和文字)以用戶投稿、用戶轉載內(nèi)容為主,如果涉及侵權請盡快告知,我們將會在第一時間刪除。文章觀點不代表本網(wǎng)站立場,如需處理請聯(lián)系客服。電話:028-86922220;郵箱:[email protected]。內(nèi)容未經(jīng)允許不得轉載,或轉載時需注明來源: 創(chuàng)新互聯(lián)

            成都網(wǎng)站建設公司

              <del id="d4fwx"><form id="d4fwx"></form></del>
              <del id="d4fwx"><form id="d4fwx"></form></del><del id="d4fwx"><form id="d4fwx"></form></del>

                    <code id="d4fwx"><abbr id="d4fwx"></abbr></code>
                  • 国国产精品美女 | 一卡二卡三卡免费视频 | 亚洲精品影视 | 脚交视频 | 亚洲婷婷丁香五月 |