...

View Full Version : Deal or No Deal



TheLstSpartan
05-26-2008, 03:41 AM
Ive accidently posted this in JavaScript section :rolleyes:

But anyway,

I am taking Java in high school as my graduation requirement. And as our final project we are to make Deal or no Deal game on JCreator.

Now the most recent topic we covered was ArrayLists, we also covered topics like for/while loops, Exceptions and etc...

i have so far been able to print the money values and cases. So yea i got something started, i got some help from some of my classmates.
I really really need some major help. I am a complete beginner and not a computer guy so this class was always a challenge to me (for me tougher than Calc 3, haha)

so if anyone anyone at all can help me please please let me know so I can show you what i have so far. This is some really basic Java compared to what you guys do here. like first year high school java (so i was really hoping to see some light at the end of the tunnel by coming here).

Heres my Code so far:


import java.lang.Math;
import java.io.*;
import java.util.*;

public class DealOrNoDeal
{
Scanner in = new Scanner(System.in);
Scanner inFile;

private ArrayList <Double> money = new ArrayList <Double> (26);
private ArrayList <Double> moneyMix = new ArrayList <Double> (26);
private int myCase;
private double myCaseValue;
private int myRound = 1;
private int casesLeft = 6;

//stores money into cases randomly
public void setCases()
{
ArrayList <Double> temp = new ArrayList <Double> (money);

while (temp.size() != 0)
{
moneyMix.add(temp.remove((int)(Math.random()*temp.size())));
}
}

//gets money from file
public void getMoney()
{
try{
inFile = new Scanner(new File("dealmoney.txt"));
}catch(IOException i){
System.out.println("Error: "+ i.getMessage());
}

while (inFile.hasNext())
{
money.add(inFile.nextDouble());
}

/*for(int x=1; x<=26; x++)
System.out.print(money.get(x) + " ");*/
}

//asks user to pick case to keep
public void keepCase()
{
System.out.print("Keep case #: ");
myCase = in.nextInt();
myCaseValue = moneyMix.get(myCase - 1);
moneyMix.set(myCase-1,0.0);
}

//ask user case# choice
public void chooseCase()
{
System.out.println("Round " + myRound);
System.out.print(casesLeft + " cases left - ");
int chooseCase = in.nextInt();
moneyMix.set(chooseCase-1,0.0);
}

//displays cases
public void displayCases()
{
for(int x=1; x<=26; x++)
{
if(money.get(x-1) != 0)
System.out.print(x + " ");
else
System.out.print("X ");
}
System.out.println();
}

//displays money
public void displayMoney()
{
for(int x=1; x<=26; x++)
{
if(money.get(x-1) != 0)
System.out.print("$" + money.get(x-1) + " ");
else
System.out.print("X ");
}
System.out.println();
System.out.println();
}

//plays game
public void play()
{
getMoney();
setCases();
displayCases();
displayMoney();
keepCase();
chooseCase();

}

//runs program
public static void main(String[] args)
{
DealOrNoDeal game = new DealOrNoDeal();
game.play();
}
}



Please PM me or e-mail me at : viseshv@gmail.com

hope we can work together

Aradon
05-27-2008, 02:40 AM
You need to please describe the problem you are having. We aren't going to do your homework for you but we will help you.

TheLstSpartan
05-30-2008, 01:00 AM
You need to please describe the problem you are having. We aren't going to do your homework for you but we will help you.

sorry i havent had time to get back and couldnt really describe my problem:

But the problem im having right now is i am at the part where the player has to start playing the actual game. Like round 1 picks 6 cases and then the banker makes a deal and the round 2 pick 5 cases and then the bankers makes another offer. This goes on up to round 9 and the last couple of rounds the player picks like 1 case. (I dont know if you know how the game works so excuse my lengthy explanation)

I know that i have to make a banker method that makes an offer at the end of each round.
And make a "chooser" method that pretty much lets the player pick cases.

Well this is what i came up with for the player to pick the cases: I am overwhelmed by a lot of errors right now that im trying to dig up so i dont exactly know if it works. IF you can look over it and let me know what you think thatd be great.


public void chooser()
{
System.out.println("Pick your next case!");
howiesScanner = new Scanner(System.in);
int temp = howiesScanner.nextInt();
//if its been pickd, make it null
if(randomValues.get(temp)!=null)
{
System.out.println("You have revealed case number " +
temp +". It's value is " + randomValues.get(temp));
randomValues.set(temp,null);
}
else
{
//when the player picks the same case
System.out.println("You already picked that case, smarts. Pick a new one!");
chooser();
}

}

This is due for me on Monday so I dont have a lot of time but then again if this works and if my banker method works im pretty much done, I just have to fix some errors.

Scriptet
05-30-2008, 06:52 PM
I'm not too good with Java, I just know some basics, but this is maybe how you could go about it.

You have the 26 boxes and their values inside an ArrayList
You have the rounds, and boxes to be opened inside a round inside another ArrayList

So when the user starts the game, and they input the value you need to possibly do something like this:

for (Values v : money) {
if (userValue == v.getBoxValue) {
/*This Box Has Been Picked So:*/
Output the Value to the User
Set the Box to a Null Value
++ The Counter for the Boxes Selected
-- boxesRemaining
Then Check the Counter against the amount of boxes allowed in this round
If counter==allowedBoxes then ++roundCounter and run the banker metho

The Banker could calculate an offer like:

int offerTotal;
for (values V : otherName) {
offerTotal += v.getBoxValue
}
double bankerOffer = offerTotal / boxesRemaining

This would give an average offer, you could also implement the use of the random library to mix it up a little bit (i.e assign an importance to a box, so if there is 5 boxes of little importance the offer is lower than the average, and if there are 2 important boxes add onto the average). You also need to add validation to check user input values are possible.



EZ Archive Ads Plugin for vBulletin Copyright 2006 Computer Help Forum