修改如下:(一共三个地方)
package cn.dadongzicool.coin.entities;
import java.util.Random;
public class Coin {
private int coinNumber;
private int inputNumber;
private int takeNumber;
Random random;
//public void getCoinSide(){
//System.out.println("Coin's getCoinSide");
//}
public void setCoinNum(){
random = new Random();
coinNumber = random.nextInt(10)+30;
}
public int getCoinNum(){
System.out.println("Coin's getCoinNum");
return coinNumber;
}
public boolean takeCoin(int takeCoinNumber){
System.out.println("Coin's takeCoin");
if(takeCoinNumber <= coinNumber){
coinNumber -=takeCoinNumber;
return true;
}
else
return false;
}
public boolean getWinner(){
System.out.println("Coin's getWinner");
if(coinNumber == 0){ //把此处的判断由coinNumber == 1改为coinNumber == 0
return true;
}
return false;
}
}
***********************************************
package cn.dadongzicool.coin.controller;
import java.util.Random;
import cn.dadongzicool.coin.entities.Coin;
import cn.dadongzicool.coin.view.GamePanel;
public class Controller {
Coin coin;
Random random = new Random();
int inputNumber;
public Controller(Coin coin){
this.coin = coin;
}
public void newGame(){
coin.setCoinNum();
}
public void chargeOfEnter(){
if(!coin.getWinner()){
try{
inputNumber = Integer.parseInt(GamePanel.inputTextField.getText().trim());
}
catch(Exception ee){
GamePanel.showTextArea.append("\n"+ee+"\n");
}
if(inputNumber <=0 || inputNumber > 3){
GamePanel.showTextArea.append("Please enter a number between 1 to 3 !!!\n");
}
else{
if(coin.takeCoin(inputNumber)){
GamePanel.showTextArea.append("user take "+inputNumber+" coins!\n" +
"There are "+coin.getCoinNum()+" left!\n");
if(coin.getWinner()){
GamePanel.showTextArea.append("Winner:Computer!!!\n");");//此处的:User改为Computer
}
int computerTakeCoinNum = 0;
if(coin.getCoinNum() > 4) {
computerTakeCoinNum = random.nextInt(3)+1;
}
else {
computerTakeCoinNum = coin.getCoinNum()-1;
if(computerTakeCoinNum ==0 ){
computerTakeCoinNum++;
}
}
if(!coin.getWinner()){
coin.takeCoin(computerTakeCoinNum);
GamePanel.showTextArea.append("computer take "+computerTakeCoinNum+" coins!\n" +
"There are "+coin.getCoinNum()+" left!\n");
if(coin.getWinner()){
GamePanel.showTextArea.append("Winner:User!!!\n");//此处的Winner:computer改为User
}
}
}
else{
GamePanel.showTextArea.append("Sorry,there is only "+coin.getCoinNum()+" left!\n" +
"Please enter a number which is lower than "+coin.getCoinNum()+" !\n");
}
}
}
}
}
令导出的jar文件:
package cn.dadongzicool.coin.entities;
import java.util.Random;
public class Coin {
private int coinNumber;
private int inputNumber;
private int takeNumber;
Random random;
//public void getCoinSide(){
//System.out.println("Coin's getCoinSide");
//}
public void setCoinNum(){
random = new Random();
coinNumber = random.nextInt(10)+30;
}
public int getCoinNum(){
System.out.println("Coin's getCoinNum");
return coinNumber;
}
public boolean takeCoin(int takeCoinNumber){
System.out.println("Coin's takeCoin");
if(takeCoinNumber <= coinNumber){
coinNumber -=takeCoinNumber;
return true;
}
else
return false;
}
public boolean getWinner(){
System.out.println("Coin's getWinner");
if(coinNumber == 0){ //把此处的判断由coinNumber == 1改为coinNumber == 0
return true;
}
return false;
}
}
***********************************************
package cn.dadongzicool.coin.controller;
import java.util.Random;
import cn.dadongzicool.coin.entities.Coin;
import cn.dadongzicool.coin.view.GamePanel;
public class Controller {
Coin coin;
Random random = new Random();
int inputNumber;
public Controller(Coin coin){
this.coin = coin;
}
public void newGame(){
coin.setCoinNum();
}
public void chargeOfEnter(){
if(!coin.getWinner()){
try{
inputNumber = Integer.parseInt(GamePanel.inputTextField.getText().trim());
}
catch(Exception ee){
GamePanel.showTextArea.append("\n"+ee+"\n");
}
if(inputNumber <=0 || inputNumber > 3){
GamePanel.showTextArea.append("Please enter a number between 1 to 3 !!!\n");
}
else{
if(coin.takeCoin(inputNumber)){
GamePanel.showTextArea.append("user take "+inputNumber+" coins!\n" +
"There are "+coin.getCoinNum()+" left!\n");
if(coin.getWinner()){
GamePanel.showTextArea.append("Winner:Computer!!!\n");");//此处的:User改为Computer
}
int computerTakeCoinNum = 0;
if(coin.getCoinNum() > 4) {
computerTakeCoinNum = random.nextInt(3)+1;
}
else {
computerTakeCoinNum = coin.getCoinNum()-1;
if(computerTakeCoinNum ==0 ){
computerTakeCoinNum++;
}
}
if(!coin.getWinner()){
coin.takeCoin(computerTakeCoinNum);
GamePanel.showTextArea.append("computer take "+computerTakeCoinNum+" coins!\n" +
"There are "+coin.getCoinNum()+" left!\n");
if(coin.getWinner()){
GamePanel.showTextArea.append("Winner:User!!!\n");//此处的Winner:computer改为User
}
}
}
else{
GamePanel.showTextArea.append("Sorry,there is only "+coin.getCoinNum()+" left!\n" +
"Please enter a number which is lower than "+coin.getCoinNum()+" !\n");
}
}
}
}
}
令导出的jar文件:
CoinGame.rar
(5.54 KB)
本人出售软件专业毕业设计(包括论文,代码)题目众多,价格从优联系方式:QQ
1635008514(寻找高校代理)