1. 程式人生 > >實訓二 部落格二

實訓二 部落格二

成員:郭美晴:16012109

   鄒彤:16012107

   郜碩:16012106

   張文竹:16012116

git地址:https://gitee.com/hlxwzyyyyzyq/events

第一步建立udp程式碼

第二步資料庫連線

第三步圖形介面構思

將三步布組合起來,一個遊戲就製作完成了

團隊分工:郜碩負責udp的程式碼部分

     張文竹負責資料庫的建立

     鄒彤負責圖形介面的部分

     郭美晴負責寫部落格

個人貢獻分:

   張文竹:  8

   郭美晴: 10

   鄒彤:  9

   郜碩:  7

程式碼:

遊戲程式碼

import java.awt.event.MouseEvent;

import java.util.Scanner;

public class B {  

  

public static void main(String args[])  

    {  

        Scanner in=new Scanner(System.in); //使用Scanner類定義物件  

        double numn[][] = new double [100][100]; 

        double goal[] = new double [100];

        double gan[] = new double [100];

        double max=0,min=100;

        double sum=0,G=0;

        System.out.println("請輸入人數");  

        double nump=in.nextDouble(); //接收float型資料 

        System.out.println("請輸入遊戲次數");  

        double numg=in.nextDouble(); //接收float型數

        for(int h=0;h<nump;h++){

         goal[h]=0;

         gan[h]=0;

        }

        for(int s=0;s<numg;s++)

        { 

             System.out.println("遊戲開始");

       for(int k=0;k<nump;k++) { 

        System.out.println("玩家輸入");

        double num = in.nextDouble(); //接收float型資料

            numn[s][k]=num;    

            }
       for(int j=0;j<nump;j++)

        {

      sum+=numn[s][j];

          }

   

     G=(sum/nump)*0.618;//求G值  

      double dif=0;

      

     for(int qq=0;qq<nump;qq++){//求分數

     dif=Math.abs(numn[s][qq]-G);

     goal[qq]=dif;    

       }

        for(int f=0;f<nump;f++)

         {

            if(max<goal[f])

               max=goal[f];

            if(min>goal[f])

             min=goal[f];                

          }

         for(int th=0;th<nump;th++)

         {

          if(goal[th]==min)

          gan[th]=gan[th]+nump;

          if(goal[th]==max)

          gan[th]=gan[th]-2;

         }             

         

        for(int tt=0;tt<nump;tt++)

        {

         System.out.println(gan[tt]);

          }

        }        

}

}

登入介面:

import java.awt.event.ActionListener;
import javax.swing.JTextField;
import javax.swing.JFrame;
import java.awt.Color;
import javax.swing.JPanel;
import javax.swing.JButton;
import javax.swing.JLabel;
import java.awt.Font;
import javax.swing.JOptionPane;
import javax.swing.JPasswordField;
import java.awt.event.ActionEvent;

public class A extends JFrame{
public JPanel pnluser;
public JLabel lbluserLogIn;
public JLabel lbluserName;
public JLabel lbluserPWD;
public JTextField txtName;
public JPasswordField pwdPwd;
public JButton btnSub;
public JButton btnReset;

public A(){
pnluser = new JPanel();
lbluserLogIn = new JLabel();
lbluserName = new JLabel();
lbluserPWD = new JLabel();
txtName = new JTextField();
pwdPwd = new JPasswordField();
btnSub = new JButton();
btnReset = new JButton();
userInit();
}

public void userInit(){
this.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);//關閉框架的同時結束程式
this.setSize(700,500);//框架長700,寬500
this.setResizable(false);//框架不可以改變大小
this.setTitle("黃金點");//框架標題
this.pnluser.setLayout(null);//面板佈局管理
this.pnluser.setBackground(Color.pink);//面板背景顏色
this.lbluserLogIn.setText("來了老弟!");//標籤標題
this.lbluserLogIn.setFont(new Font("宋體",Font.BOLD | Font.ITALIC,25));//標籤字型
this.lbluserLogIn.setForeground(Color.blue);//標籤字型顏色
this.lbluserName.setText("賬號:");
this.lbluserPWD.setText("密 碼:");
this.btnSub.setText("登入");
this.btnReset.setText("註冊");
this.lbluserLogIn.setBounds(300,20,200,80);//設定標籤座標及長寬高
this.lbluserName.setBounds(250,100,70,30);
this.lbluserPWD.setBounds(250,150,70,30);
this.txtName.setBounds(300,100,140,30);
this.pwdPwd.setBounds(300,150,140,30);
this.btnSub.setBounds(365,200,70,30);
this.btnSub.addActionListener(new ActionListener()
{
public void actionPerformed(ActionEvent e){
btnsub_ActionEvent(e);
}
}
);
this.btnReset.setBounds(260,200,70,30);
this.btnReset.addActionListener(new ActionListener()
{
public void actionPerformed(ActionEvent e){
btnreset_ActionEvent(e);
}
}
);
this.pnluser.add(lbluserLogIn);
this.pnluser.add(lbluserName);
this.pnluser.add(lbluserPWD);
this.pnluser.add(txtName);
this.pnluser.add(pwdPwd);
this.pnluser.add(btnSub);
this.pnluser.add(btnReset);
this.add(pnluser);
this.setVisible(true);
}

public void btnsub_ActionEvent(ActionEvent e){
String name = txtName.getText();
String pwd = String.valueOf(pwdPwd.getPassword());
if(name.equals("")){
JOptionPane.showMessageDialog(null,"請輸入賬號","錯誤",JOptionPane.ERROR_MESSAGE);
return;
}else if (pwd.equals("")){
JOptionPane.showMessageDialog(null,"請輸入密碼","錯誤",JOptionPane.ERROR_MESSAGE);
return;
}else if(true){
this.dispose();
}
}

public void btnreset_ActionEvent(ActionEvent e){
txtName.setText("");
pwdPwd.setText("");
}

public static void main(String[] args){
new A();

}
} 

  

執行截圖:

 

 

總結:這次的實訓任務到這裡就結束了,我們四個各司其職,雖然並沒有到達預期的結果,但是我們都做到了最大的努力,而且1+1+1+1>4,只一個人的思維是不會有太大的成果,集思廣益,團隊合作才是最棒的