软件工程-黄金点游戏 21组第9周

一、第8周工作内容

黄金点游戏控制台源码:

 1 package GoldenPoint;
 2 import java.awt.EventQueue;
 3 import java.util.*;
 4 public class GoldenPoint {
 5 
 6     public static void main(String[] args) {
 7         EventQueue.invokeLater(new Runnable() {
 8             public void run() {
 9                 try {
10                     GameStart frame = new GameStart();
11                     frame.setLocationRelativeTo(null);
12                     frame.setVisible(true);
13                 } catch (Exception e) {
14                     e.printStackTrace();
15                 }
16             }
17         });
18     }
19 
20     public static class Player{
21         public double number;                                        //玩家输入的数字
22         public int sumOfscores;                                            //玩家获取的总分
23     }
24     
25     public static class Judge{
26         public int numOfplayers;                                    //一回合中玩家的数量
27         public double G;                                            //本回合中的G值
28         public int max;
29         public int min;                                                //本回合中与G值距离最大与最小的玩家
30         public double []distance;                                    //各玩家与G值之间的距离
31         public int []scoresOfplayers;                                //本回合中个玩家的得分
32         public Judge(int numOfplayers) {
33             this.numOfplayers=numOfplayers;
34             distance=new double[numOfplayers];
35             scoresOfplayers=new int[numOfplayers];
36         }
37         public void Cal(Player players[]) {
38             double sum=0.0;
39             for(int i=0;i<numOfplayers;i++) {
40                 sum+=players[i].number;
41             }
42             G=sum/numOfplayers*0.618;                                //求出G值
43         }
44         public void SetDistance(Player players[]) {
45             for(int i=0;i<numOfplayers;i++) {
46                 this.distance[i]=Math.abs(players[i].number-G);            //求出各玩家与G值之间的距离
47             }
48         }
49         public void Result(Player players[]) {
50             int max=MAX(distance,numOfplayers);
51             int min=MIN(distance,numOfplayers);
52             for(int i=0;i<numOfplayers;i++) {
53                 if(i==min) {
54                     scoresOfplayers[i]=numOfplayers;                    //玩家得分
55                 }
56                 else if(i==max) {
57                     scoresOfplayers[i]=-2;
58                 }
59                 else {
60                     scoresOfplayers[i]=0;
61                 }
62                 players[i].sumOfscores+=scoresOfplayers[i];                //玩家总分加上该回合的得分
63             }
64         }
65     }
66     
67     public static int MAX(double a[], int n) {                            //返回数组中最大值的下标
68         int max = 0;
69         double temp = a[0];
70         for(int i=0;i<n;i++) {
71             if(a[i]>temp) {
72                 temp=a[i];
73                 max=i;
74             }
75         }
76         return max;
77     }
78     
79     public static int MIN(double a[],int n) {                            //返回数组中最小值的下标
80         int min=0;    
81         double temp=a[0];
82         for(int i=0;i<n;i++) {
83             if(a[i]<temp) {
84                 temp=a[i];
85                 min=i;
86             }
87         }
88         return min;
89     }
90 }

二、第9周工作内容:黄金点游戏实现简易界面

1.各文件实现内容

GameStart.java:游戏开始界面

Game1.java:输入游戏人数界面

Game2.java:根据玩家编号,逐玩家输入数字界面

Game3.java:显示玩家得分界面

GoldenPoint.java:相关函数包

 2.运行截图

游戏开始界面

输入游戏人数

按编号输入数字

显示得分

若继续游戏,第二回合得分

posted @ 2020-11-01 21:32  SE_Goldenpoint  阅读(83)  评论(0)    收藏  举报