交易或不交易GUI游戏 [英] Deal or No Deal GUI Game

查看:72
本文介绍了交易或不交易GUI游戏的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

这是我的Box.java类

  private   double 值; 
public boolean isOpen;

public Box( double value){
.value = value;
isOpen = false;
}
public double getValue(){
返回值;
}
public boolean isOpen(){
return isOpen;
}
public void open(){
isOpen = true ;
}
public String toString(){
返回 打开: + isOpen + + value;
}
}





这是我的BoxList.java类



[/

  import  java.util。*; 
import java.io. *;
public class BoxList {
私人 Box []框;
public BoxList( double [] monetaryAmounts){

boxes = new Box [monetaryAmounts.length];

for int i = 0 ; i< boxes.length; ++ i){

Box box = new Box(monetaryAmounts [i ]);
boxes [i] = box;
}
}

public double getValue( int index){

return boxes [index] .getValue();
}

public boolean isOpen( int index){

return boxes [index] .isOpen();
}

public void open( int index){

boxes [index] .open();
}

public double averageValueOfUnopenedBoxes(){

int c = 0 ;

double average = 0 ;

for int i = 0 ; i< boxes.length; ++ i){
if (boxes [i] .isOpen()== false ){
average + = boxes [i] .getValue();
++ c;
}
}

return average / c;
}

public void shuffle( int numberOfSwaps){

Random rand = new Random();

for int i = 0 ; i< numberOfSwaps; ++ i){

int first = rand.nextInt(boxes.length - 1 ),second = rand.nextInt(boxes.length - 1 );

Box temp = boxes [first];

box [first] = boxes [second];

box [second] = temp;
}
}

public String toString( ){

字符串 list = ;

for int i = 0 ; i< boxes.length; ++ i)

list + = boxes [i];

return list;
}

}





我需要创建一个DealGame.java类



这些是方法:public DealGame(布尔测试) - 构造函数创建BoxList。如果测试参数为false,则对BoxList进行洗牌。如果HIGH_SCORE_FILE存在且可以打开,则存储最高分数的变量将设置为文件中的值。否则,最高得分变量设置为0.当前回合数设置为1,当前回合中打开的框数和总数设置为0.



public boolean hasPlayerChosenBox() - 如果玩家已经选择了一个框,则返回true,否则返回false。



public void selectBox(int index) - 如果玩家没有然后选择一个方框,索引存储为玩家的盒子索引,并且跟踪玩家是否选择了一个方框的变量设置为true。如果玩家已经选择了一个方框,BoxList中给定索引处的方框将被打开,当前轮次中打开的方框数和方框总数将增加。



public int getBoxesRemainingToOpenThisRound() - 返回当前轮次中剩余的盒子数。



public int getBoxesOpenedThisRound() - 返回的数量本轮打开的盒子。



public int getRound() - 返回当前的轮数。



public void startNextRound() - 增加当前的轮数并将该轮中打开的方框数设置为0.



public boolean isEndOfRound() - 如果返回true,则返回true本轮的所有方框都已打开,否则为假。



public double getPlayerBoxValue() - 返回玩家盒子的值。



public boolean isBoxOpen(int index) - 如果是框a,则返回true BoxList中的给定索引是打开的,否则为false。



public double getValueInBox(int index) - 返回BoxList中给定索引处Box的值。



public double getCurrentOffer() - 计算并返回银行家当前的报价。这是计算为未打开的方框(包括玩家的方框)的平均值*当前的轮数/ 10.



public double getHighScore() - 返回最高值在游戏的所有游戏中得分。



public boolean isNewHighScore(double value) - 将值与目前为止的最高分进行比较。如果值更大,则该方法返回true并将值写入HIGH_SCORE_FILE(如果文件已存在,则覆盖该文件)。如果该值不大于最高分,则该方法返回false。



这些是实例字段:



BoxList类的一个实例。一个整数,用于存储BoxList中玩家盒子的索引。一个布尔变量,知道玩家是否选择了一个盒子。存储当前轮数的整数。一个整数,用于跟踪当前轮次中已打开的方框数。一个整数,用于跟踪游戏中已打开的盒子总数。在所有游戏中存储最高分(最高金额)的双倍。



他们应该被添加到这个文件中



  public   class  DealGame { 

/ * *这是游戏中的方框数* /
public static final < span class =code-keyword> int NUM_BOXES = 26 ;


/ * *这些是将在游戏中使用的值* /
public static final double [] BOX_VALUES = { 0 01 1 5 10 25 50 75
100 200 300 400 500
750 1000 5000 10000
25000 , 50000 75000
100000 200000 300000
400000 500000 750000
百万};

/ * *这些是每轮要打开的方框数* /
public static final int [] BOXES_IN_ROUND = { 0 6 5 4 3 2
1 1 1 1 1 };

/ * *这是游戏中的轮数* /
public static final < span class =code-keyword> int
NUM_ROUNDS = 10 ;

/ * *这是设置期间交换框的次数* /
私人 静态 final int BOX_SWAPS = 500 ;

/ * *这是包含高分* / <的文件的名称/ span>
public static final 字符串 HIGH_SCORE_FILE = highscore.txt;


}





我已经尝试了所有东西,但到目前为止我已经失去了我有这个:



  public   class  DealGame {

private BoxList boxList;
private int playbox;
private boolean 选择;
private int round;
private int roundgame;
私人 int 已打开;
private double highestScore;

/ * *这是游戏中的方框数* /
public static final < span class =code-keyword> int NUM_BOXES = 26 ;


/ * *这些是将在游戏中使用的值* /
public static final double [] BOX_VALUES = { 0 01 1 5 10 25 50 75
100 200 300 400 500
750 1000 5000 10000
25000 , 50000 75000
100000 200000 300000
400000 500000 750000
百万};

/ * *这些是每轮要打开的方框数* /
public static final int [] BOXES_IN_ROUND = { 0 6 5 4 3 2
1 1 1 1 1 };

/ * *这是游戏中的轮数* /
public static final < span class =code-keyword> int
NUM_ROUNDS = 10 ;

/ * *这是设置期间交换框的次数* /
私人 静态 final int BOX_SWAPS = 500 ;

/ * *这是包含高分* / <的文件的名称/ span>
public static final 字符串 HIGH_SCORE_FILE = highscore.txt;

public DealGame( boolean testing)
{

}

public boolean hasPlayerChosenBox()
{

}

public void selectBox ( int index)
{

}

public int getBoxesRemainingToOpenThisRound()
{

}

public int getBoxesOpenedThisRound()
{

}

public int getRound()
{

}

public void startNextRound()
{

}

public boolean isEndOfRound()
{

}

public double getPlayerBoxValue()
{

}

$ b public boolean isBoxOpen( int index)
{

}

public double getPlayerBoxValue()
{

}

public boolean isBoxOpen( int index)
{

}

public double getValueInBox( int index)
{

}

public double getCurrentOffer ()
{

}

public double getHighScore()
{

}

public boolean isNewHighScore( double value)
{

}
}





我只需要一些指导或每种方法的概述

谢谢

解决方案

我们不做你的作业:这是有原因的。它就是为了让你思考你被告知的事情,并试着理解它。它也在那里,以便您的导师可以识别您身体虚弱的区域,并将更多的注意力集中在补救措施上。



亲自尝试,你可能会发现它不是和你想的一样困难!


我添加了一些可读性。



让我们举一个例子:



  public   boolean  hasPlayerChosenBox ()
{

}





标题告诉我:



- 公共可访问

- 返回布尔

- 被称为hasPlayerChosenBox

- 不需要任何参数()



现在你需要填写内容并让该方法返回一个值。

基本上所有功能都是这样做的。



  public   boolean  hasPlayerChosenBox()
{
if (someargument){ // 花哨的编码
return false;
}

return true; // 如果if-case失败
}


This is my Box.java class

private double value;
public boolean isOpen;

public Box(double value) {
this.value = value;
isOpen = false;
}
public double getValue() {
return value;
}
public boolean isOpen() {
return isOpen;
}
public void open() {
isOpen = true;
}
public String toString() {
return "Open: " + isOpen + " Value " + value;
} 
}



and this is my BoxList.java class

[/

 import java.util.*;
import java.io.*;
public class BoxList {
private Box[] boxes;
public BoxList(double[] monetaryAmounts) {

boxes = new Box[monetaryAmounts.length];

for (int i = 0; i < boxes.length; ++i) {

Box box = new Box(monetaryAmounts[i]);
boxes[i] = box;
}
}

public double getValue(int index) {

return boxes[index].getValue();
}

public boolean isOpen(int index) {

return boxes[index].isOpen();
}

public void open(int index) {

boxes[index].open();
}

public double averageValueOfUnopenedBoxes() {

int c = 0;

double average = 0;

for (int i = 0; i < boxes.length; ++i) {
if (boxes[i].isOpen() == false) {
average += boxes[i].getValue();
++c;
}
}

return average / c;
}

public void shuffle(int numberOfSwaps) {

Random rand = new Random();

for (int i = 0; i < numberOfSwaps; ++i) {

int first = rand.nextInt(boxes.length - 1), second = rand.nextInt(boxes.length - 1);

Box temp = boxes[first];

boxes[first] = boxes[second];

boxes[second] = temp;
}
}

public String toString() {

String list = "";

for (int i = 0; i < boxes.length; ++i) 

list += boxes[i];

return list;
}

}



I need to create a DealGame.java class

These are the methods: public DealGame(boolean testing) - The constructor creates the BoxList. If the testing parameter is false, the BoxList is shuffled. If the HIGH_SCORE_FILE exists and can be opened, the variable that stores the highest score is set to the value in the file. Otherwise the highest score variable is set to 0. The current round number is set to 1 and the number of boxes opened in the current round and overall are set to 0.

public boolean hasPlayerChosenBox() - Returns true if the player has already chosen a box, false otherwise.

public void selectBox(int index) - If the player has not yet chosen a box, the index is stored as the player's box index and the variable that keeps track of whether or not the player has chosen a box is set to true. If the player has already chosen a box, the Box at the given index in the BoxList is opened and the number of boxes opened in the current round and total number of boxes are incremented.

public int getBoxesRemainingToOpenThisRound() - Returns the number of boxes remaining to be opened in the current round.

public int getBoxesOpenedThisRound() - Returns the number of boxes opened in the current round.

public int getRound() - Returns the current round number.

public void startNextRound() - Increments the current round number and sets the number of boxes opened in the round to 0.

public boolean isEndOfRound() - Returns true if all boxes for the current round have been opened, false otherwise.

public double getPlayerBoxValue() - Returns the value of the player's box.

public boolean isBoxOpen(int index) - Returns true if the Box at the given index in the BoxList is open, false otherwise.

public double getValueInBox(int index) - Returns the value of the Box at the given index in the BoxList.

public double getCurrentOffer() - Calculates and returns the banker's current offer. This is calculated as the average value of the unopened boxes (including the player's box) * the current round number / 10.

public double getHighScore() - Returns the highest score in all plays of the game.

public boolean isNewHighScore(double value) - Compares the value to the highest score so far. If the value is greater, the method returns true and writes the value to the HIGH_SCORE_FILE (overwriting the file if it already exists). If the value is not greater than the highest score, the method returns false.

And these are the instance fields:

An instance of the BoxList class. An integer which stores the index of the player's box in the BoxList. A boolean variable that knows whether or not the player has chosen a box. An integer that stores the current round number. An integer that keeps track of the number of boxes that have been opened in the current round. An integer that keeps track of the total number of boxes that have been opened in the game. A double that stores the highest score (highest amount of money won) over all plays of the game.

They should be added to this file

public class DealGame {

/** This is the number of boxes in the game */
public static final int NUM_BOXES = 26;


/** These are the values that will be used in the game */
public static final double[] BOX_VALUES = {0.01, 1, 5, 10, 25, 50, 75, 
100, 200, 300, 400, 500, 
750, 1000, 5000, 10000, 
25000, 50000, 75000, 
100000, 200000, 300000, 
400000, 500000, 750000, 
1000000};

/** These are the number of boxes to be opened in each round */
public static final int[] BOXES_IN_ROUND = {0, 6, 5, 4, 3, 2, 
1, 1, 1, 1, 1}; 

/** This is the number of rounds in the game */
public static final int NUM_ROUNDS = 10;

/** This is the number of times boxes are swapped during the set up */
private static final int BOX_SWAPS = 500;

/** This is the name of the file that contains the high score */
public static final String HIGH_SCORE_FILE = "highscore.txt";


}



I have tried everything but I'm lost so far i have this:

public class DealGame {

private BoxList boxList;
private int playbox;
private boolean chosen;
private int round;
private int roundgame;
private int opened;
private double highestScore;

/** This is the number of boxes in the game */
public static final int NUM_BOXES = 26;


/** These are the values that will be used in the game */
public static final double[] BOX_VALUES = {0.01, 1, 5, 10, 25, 50, 75, 
100, 200, 300, 400, 500, 
750, 1000, 5000, 10000, 
25000, 50000, 75000, 
100000, 200000, 300000, 
400000, 500000, 750000, 
1000000};

/** These are the number of boxes to be opened in each round */
public static final int[] BOXES_IN_ROUND = {0, 6, 5, 4, 3, 2, 
1, 1, 1, 1, 1}; 

/** This is the number of rounds in the game */
public static final int NUM_ROUNDS = 10;

/** This is the number of times boxes are swapped during the set up */
private static final int BOX_SWAPS = 500;

/** This is the name of the file that contains the high score */
public static final String HIGH_SCORE_FILE = "highscore.txt";

public DealGame(boolean testing)
{

}

public boolean hasPlayerChosenBox()
{

}

public void selectBox(int index)
{

}

public int getBoxesRemainingToOpenThisRound()
{

}

public int getBoxesOpenedThisRound()
{

}

public int getRound()
{

}

public void startNextRound()
{

}

public boolean isEndOfRound()
{

}

public double getPlayerBoxValue()
{

}

public boolean isBoxOpen(int index)
{

}

public double getPlayerBoxValue()
{

}

public boolean isBoxOpen(int index)
{

}

public double getValueInBox(int index)
{

}

public double getCurrentOffer()
{

}

public double getHighScore()
{

}

public boolean isNewHighScore(double value)
{

}
}



I just need some guidance or an outline of what goes in each method
Thank you

解决方案

We do not do your homework: it is set for a reason. It is there so that you think about what you have been told, and try to understand it. It is also there so that your tutor can identify areas where you are weak, and focus more attention on remedial action.

Try it yourself, you may find it is not as difficult as you think!


I added some readability to that.

Let's make an example:

public boolean hasPlayerChosenBox()
{
 
}



The headline tells me:

- "public" accessable
- returns a "boolean"
- is called "hasPlayerChosenBox"
- does not need any arguments "()"

Now you need to fill in the content and let that method return a value.
Basically that is what all functions do.

public boolean hasPlayerChosenBox()
{
  if(someargument){// fancy coding
    return false; 
  }
  
  return true; //if if-case fails
}


这篇关于交易或不交易GUI游戏的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆