JCreator Forum Board: Black Jack Game - JCreator Forum Board

Jump to content

  • 2 Pages +
  • 1
  • 2
  • You cannot start a new topic
  • You cannot reply to this topic

Black Jack Game Help me please!

#1 User is offline   yomochi 

  • Member
  • PipPip
  • Group: Members
  • Posts: 15
  • Joined: 17-October 07
  • Gender:Male
  • Location:Grim City

Posted 17 October 2007 - 03:32 PM

Can anyone help me make a blackjack game??

This is what i have so far:
CODE
class goodBlackJack
{
    
    //MAKES THE DECK
    public static int[] makeDeck()
    {
        //Creates the deck and the four suits
        int d[]=new int [52];
        for (int i=0; i<13; i++)
        {
            d[i]=i+1;
            d[i+13]=i+1;
            d[i+26]=i+1;
            d[i+39]=i+1;
        }
        return d;
    }
    //SHUFFLES THE DECK
    public static void shuffleDeck()
    {
        //Random stuff here
    }
    
}


THANX!
0

#2 User is offline   ham90mack 

  • Advanced Member
  • PipPipPip
  • Group: Members
  • Posts: 937
  • Joined: 15-November 06

Posted 17 October 2007 - 07:17 PM

You will need to be more specific about what you need help with...

You probably want to make a Card object (which stores the value and suit of a card) and a CardStack object (which stores a stack of cards and has a shuffle method). If you know object oriented programming, it will be much easier to use it here since cards and decks of cards are physical items in the real world.
ham90mack
http://ham90mack.googlepages.com
Resistance may be futile,
But capacitance has potential.
BLAH!
0

#3 User is offline   yomochi 

  • Member
  • PipPip
  • Group: Members
  • Posts: 15
  • Joined: 17-October 07
  • Gender:Male
  • Location:Grim City

Posted 18 October 2007 - 02:31 PM

QUOTE(ham90mack @ Oct 17 2007, 03:17 PM) View Post
You will need to be more specific about what you need help with...

You probably want to make a Card object (which stores the value and suit of a card) and a CardStack object (which stores a stack of cards and has a shuffle method). If you know object oriented programming, it will be much easier to use it here since cards and decks of cards are physical items in the real world.

Thanks!
And i need help with everything, lol.
I just started learning java and I dont understand most of it.... We just learned meathods and i understand a little.
0

#4 User is offline   yomochi 

  • Member
  • PipPip
  • Group: Members
  • Posts: 15
  • Joined: 17-October 07
  • Gender:Male
  • Location:Grim City

Posted 18 October 2007 - 03:15 PM

I am stuck at making the deck. Should i make an array?
0

#5 User is offline   Gehn 

  • Member
  • PipPip
  • Group: Members
  • Posts: 20
  • Joined: 28-April 05
  • Location:Pennsylvania, USA
  • Interests:Stuff

Posted 18 October 2007 - 03:34 PM

I would say start with something more simple. If you just started to learn methods there is still a lot to learn to make a really good program. Then when you feel you know enough to make your game, make it console style first and then move on to a GUI setup.
"I didn't do it."

Student at Kutztown University
0

#6 User is offline   Captain Pierce 

  • Advanced Member
  • PipPipPip
  • Group: Moderator
  • Posts: 877
  • Joined: 06-July 06
  • Gender:Male
  • Location:Georgia

Posted 18 October 2007 - 10:58 PM

^^ That is really good advice
0

#7 User is offline   yomochi 

  • Member
  • PipPip
  • Group: Members
  • Posts: 15
  • Joined: 17-October 07
  • Gender:Male
  • Location:Grim City

Posted 19 October 2007 - 02:33 PM

We haven't learned GUI yet, but i dont understand methods and loop... :( All the easy stuff...
0

#8 User is offline   Captain Pierce 

  • Advanced Member
  • PipPipPip
  • Group: Moderator
  • Posts: 877
  • Joined: 06-July 06
  • Gender:Male
  • Location:Georgia

Posted 19 October 2007 - 09:22 PM

-ignore please, silly forum software
0

#9 User is offline   Captain Pierce 

  • Advanced Member
  • PipPipPip
  • Group: Moderator
  • Posts: 877
  • Joined: 06-July 06
  • Gender:Male
  • Location:Georgia

Posted 19 October 2007 - 09:28 PM

QUOTE

We haven't learned GUI yet, but i dont understand methods and loop... :( All the easy stuff...


Which is why Gehn's advice is really good. Figure out methods and loops with simple programs and then start to branch out.

Think of methods as verbs, designed to do a specific task such as add items to a list, print out text to the console, etc. That will help you figure out what methods you need. Then to actually make one you have 4 key components in the method signature:

visibility (public/private/protected) return-type (void, int, String, etc.) method-name parameters
CODE
/*
Public method that adds three ints together, returns the result.
*/
public int add(int a, int b, int c) {
     return a + b + c;<BR>}


*note there can be more keywords in the method signature such as static, final, synchronized, but I limited my example to the basic ones every method must have with the exception of public, no specified visibility still means its access limited to the same package.

Loops are used to do repeated tasks. There are several types: for, while, do-while.

I'll give an example of a for loop that prints out the numbers from 1 to 10.

CODE
public static void main(String[] args) {
     for (int i = 1; i <= 10; i++) {
           System.out.println(i);
     }
}


Now in the for statement this: int i = 1; i <= 10; i++ has the following meaning.

variable i is initialized to one as soon as the program enters the loop. The second part of the statement is a conditional statement that tells Java when to stop looping. If a loop never stops it's called an infinite loop. Before each execution of the for-loop's code block it will check to make sure that conditional is true. After each time it executes the code block the third statement, i++, is executed. All this does is provide a convenient place for the programmer to place simple code to make progress in the loop. Often times loops simply increment/decrement a counter. I don't have to put the increment there, I could put that statement after the call to println, but that's really not good programming style with Java for-loops unless there's a valid reason for doing so.

No doubt that I didn't really help you understand methods/loops very much since I don't know what you don't know, why not ask questions about what you are confused on/don't know/etc and we'll try to point you in the right direction.
0

#10 User is offline   yomochi 

  • Member
  • PipPip
  • Group: Members
  • Posts: 15
  • Joined: 17-October 07
  • Gender:Male
  • Location:Grim City

Posted 22 October 2007 - 02:57 PM

Here is what i have now.... i cant figure out how to stop the game when the user enters a number over 100.

import java.awt.*;
import java.awt.event.*;
import java.util.*;
import java.io.*;

class goodBlackJack
{

//MAKES THE DECK
public static int[] makeDeck()
{
//Creates the deck and the four suits
int d[]=new int [52];
for (int i=0; i<13; i++)
{
d[i]=i+1;
d[i+13]=i+1;
d[i+26]=i+1;
d[i+39]=i+1;
}
return d;
}

//SHUFFLES THE DECK
public static void shuffleDeck()
{
//randomize cards to shuffle deck and replace values, etc.
Random shuffle= new Random();
int card1= shuffle.nextInt(52);
}

//SETS THE VALUES OF THE 7CARDS
public static void cardValues()
{
//change number into point value
}

//MAIN
public static void main(String args[]) throws Exception
{
// Creates int money
int money= 100;
// Creates int bet
int bet;
boolean win=true;

//displays "Welcome to Black Jack"
System.out.println("\4Welcome to Black Jack!\4");
InputStreamReader isr=new InputStreamReader(System.in);
BufferedReader br=new BufferedReader(isr);
String input;
System.out.println("\nYou have: $100");
System.out.println("Please bet (min 5):");
input = br.readLine();
bet= Integer.parseInt(input);
if (bet< 4 || bet> money)
System.out.println("Your bet must be between 5 and " + money + '.');
win=false;
if (bet == 0 || money == 0)
System.out.println("Game Over. /nThanks for Playing Ultimate BlackJack!");
win=false;

while (win)
{
if(money<5)
win=false;
}
if (bet> 4 || money>0)
{
money=money-bet;
System.out.println("You now have "+money+" dollars.");
}
}
}
0

#11 User is offline   Captain Pierce 

  • Advanced Member
  • PipPipPip
  • Group: Moderator
  • Posts: 877
  • Joined: 06-July 06
  • Gender:Male
  • Location:Georgia

Posted 22 October 2007 - 07:16 PM

If you have more than one statement following conditional code such as if/else/elseIf/while/for/etc. then you need to encase your code in brackets {}.

Change

CODE
[size="1"]if (bet< 4 || bet> money)
System.out.println("Your bet must be between 5 and " + money + '.');
win=false;
if (bet == 0 || money == 0)
System.out.println("Game Over. /nThanks for Playing Ultimate BlackJack!");
win=false;[/size]


to

CODE
[size="1"]if (bet< 4 || bet> money) {
    System.out.println("Your bet must be between 5 and " + money + '.');
    win=false;
}

if (bet == 0 || money == 0) {
     System.out.println("Game Over. /nThanks for Playing Ultimate BlackJack!");
     win=false;
[/size]}


That should fix it, if not there are more errors elsewhere.

edit: Ignore the size tags...this forum software is somewhat buggy w/ IE7 and I'm tired of fixing the extraneous bs
0

#12 User is offline   yomochi 

  • Member
  • PipPip
  • Group: Members
  • Posts: 15
  • Joined: 17-October 07
  • Gender:Male
  • Location:Grim City

Posted 24 October 2007 - 02:58 PM

kk, i fixed that now what?
0

#13 User is offline   ham90mack 

  • Advanced Member
  • PipPipPip
  • Group: Members
  • Posts: 937
  • Joined: 15-November 06

Posted 24 October 2007 - 08:05 PM

Compile and try to run your code. If there are errors, try to fix them yourself. If you cannot fix it yourself, post your new code and describe the error.
ham90mack
http://ham90mack.googlepages.com
Resistance may be futile,
But capacitance has potential.
BLAH!
0

#14 User is offline   yomochi 

  • Member
  • PipPip
  • Group: Members
  • Posts: 15
  • Joined: 17-October 07
  • Gender:Male
  • Location:Grim City

Posted 25 October 2007 - 02:33 PM

there are no errrors now!!! thanks!!
How would i deal and display the cards???

Here is my updated code.....

import java.awt.*;
import java.awt.event.*;
import java.util.*;
import java.io.*;
 
class goodBlackJack
{
	
	//MAKES THE DECK
	public static int[] makeDeck()
	{
		//Creates the deck and the four suits
		int d[]=new int [52];
		for (int i=0; i<13; i++)
		{
			d[i]=i+1;
			d[i+13]=i+1;
			d[i+26]=i+1;
			d[i+39]=i+1;
		}
		return d;
	}
	
	//SHUFFLES THE DECK
	public static int [] shuffleDeck ()
	{
		int copyDeck[]=makeDeck();
		Random ran= new Random();
		int shuffle[] = makeDeck();
		for (int x=0; x<=10000; x++)
		{
			int y = ran.nextInt(52);
			int z = ran.nextInt(52);
			int newDeck;
			
			newDeck = copyDeck[y];
			copyDeck[y]=copyDeck[z];
			copyDeck[z]=newDeck;			
		}
		return copyDeck;
	}
	
	//SETS THE VALUES OF THE 7CARDS
	public static void cardValues()
	{
		//change number into point value.....
	}
	
	//DEAL CARDS FOR PLAYER AND DEALER
	public static void dealCards()
	{
		//Display cards, etc.
	}
	//MAIN
	public static void main(String args[]) throws Exception
	{
		// Creates int money
		int money= 100;
		// Creates int bet          
        int bet;  
       	boolean win=true;
	
		//displays "Welcome to Black Jack"
		System.out.println("\4Welcome to Ultimate Black Jack!\4");
		InputStreamReader isr=new InputStreamReader(System.in);
		BufferedReader br=new BufferedReader(isr);
		String input;
		//displays the current amount of money
		System.out.println("\nYou have:"+money+"$");
		//displays "Please bet" and asks for a minimum bet of 5$
		System.out.println("Please bet (Min. $5):");
		
		input = br.readLine();
		bet= Integer.parseInt(input);
		if (bet> 4 & bet< money) 
		{
   			System.out.println("GOOD!");
    		win=false;
		}
		if (bet == 0 || money == 0) 
		{
     		System.out.println("Game Over. \nThanks for Playing Ultimate BlackJack!");
     		win=true;
     	}			
		while (win)
		{
			if(money<5)
			win=false;
		}		 
		if (bet> 4 || money>0)
		{
			money=money-bet;
			System.out.println("You now have "+money+" dollars.");
		}
		System.out.println("\nShuffling cards....\n");

0

#15 User is offline   Captain Pierce 

  • Advanced Member
  • PipPipPip
  • Group: Moderator
  • Posts: 877
  • Joined: 06-July 06
  • Gender:Male
  • Location:Georgia

Posted 25 October 2007 - 05:27 PM

Someone else asked a similar question in another thread using code that is suspiciously close to yours. Anyways look at my reply there: http://www.jcreator.com/forums/index.php?s...amp;#entry10934

To display: use the method System.out.println
0

#16 User is offline   yomochi 

  • Member
  • PipPip
  • Group: Members
  • Posts: 15
  • Joined: 17-October 07
  • Gender:Male
  • Location:Grim City

Posted 29 October 2007 - 03:20 PM

QUOTE(Captain Pierce @ Oct 25 2007, 01:27 PM) View Post
Someone else asked a similar question in another thread using code that is suspiciously close to yours. Anyways look at my reply there: http://www.jcreator.com/forums/index.php?s...amp;#entry10934

To display: use the method System.out.println


kk, thanks.. i posted my new code on that topic
0

#17 User is offline   Captain Pierce 

  • Advanced Member
  • PipPipPip
  • Group: Moderator
  • Posts: 877
  • Joined: 06-July 06
  • Gender:Male
  • Location:Georgia

Posted 29 October 2007 - 07:13 PM

Are you also SynnBlack? I definitely don't see a post from you there.
0

#18 User is offline   SynnBlack 

  • Member
  • PipPip
  • Group: Members
  • Posts: 11
  • Joined: 11-October 07
  • Gender:Female
  • Location:British Columbia

Posted 05 November 2007 - 04:41 PM

QUOTE(Captain Pierce @ Oct 29 2007, 02:13 PM) View Post
Are you also SynnBlack? I definitely don't see a post from you there.

He is not me!! lolz. He is a he. I am a she. Big difference
0

#19 User is offline   Captain Pierce 

  • Advanced Member
  • PipPipPip
  • Group: Moderator
  • Posts: 877
  • Joined: 06-July 06
  • Gender:Male
  • Location:Georgia

Posted 05 November 2007 - 05:04 PM

QUOTE

Big difference


Not on the internet :P
0

#20 User is offline   i pwn noobs 

  • Newbie
  • Pip
  • Group: Members
  • Posts: 5
  • Joined: 06-November 07
  • Gender:Male
  • Location:In front of my comptuer. Duh
  • Interests:Lots of stuff

Posted 06 November 2007 - 01:10 AM

I'm in the same Computer progarming class as yomochi and SynnBlack (I think) and im having a problem shuffleing.

It says illegal start of expression for:
public static int [] shuffleDeck ()

Any suggestions?
Shut up and keep pwning, cuz it aint over, till ya roll 'em over!
0

Share this topic:


  • 2 Pages +
  • 1
  • 2
  • You cannot start a new topic
  • You cannot reply to this topic