What In This Code Is Creating The Symbols ?
CodeGuru Home VC++ / MFC / C++ .NET / C# Visual Basic VB Forums Developer.com
Results 1 to 3 of 3

Thread: What In This Code Is Creating The Symbols ?

  1. #1
    Join Date
    Jan 2011
    Posts
    1

    What In This Code Is Creating The Symbols ?

    Hi...

    I've Found This Code Online And Would Like To Use It For My School Project, But I Do Not Understand What Part Of This Code Is Creating The Symbols...

    I Will Be Using This Code For My BlackJack Game And This Code Generates The Card...

    What I Don't Get Is What Part Of This Code Generates The Symbols [Hear, Spades & etc.]

    Can Someone Please Explain It To Me ?


    public class Tango{
    public static void main ( String[] arg ) throws Exception{
    String[] cards = new String[52];
    int i=0,v=0;
    for(int k = 0;k<52;k++){

    i = k%13;
    if(i==0){
    cards[k]="K";
    }
    else if(i==1){
    cards[k]="A";
    }
    else if(i>=2 && i<11){
    cards[k]= " " + i;
    }
    else if(i==11){
    cards[k]= "J";
    }
    else if(i==12){
    cards[k]= "Q";
    }

    if(k<13){
    cards[k]= cards[k]+(char)(6)+" ";
    }
    else if(k<26){
    cards[k]= cards[k]+(char)(3)+ " ";
    }
    else if(k<39){
    cards[k]= cards[k]+ (char)(5)+ " ";
    }
    else if(k<52){
    cards[k]= cards[k]+(char)(4)+ " ";
    }
    }

    for (int a=0; a<=cards.length; a++) {
    System.out.print(cards[a]);
    }
    }
    }
    Attached Files Attached Files

  2. #2
    Join Date
    May 2006
    Location
    UK
    Posts
    4,473

    Re: What In This Code Is Creating The Symbols ?

    Isn't the point of your project that you write the code yourself rather than finding code online and using that?
    Posting code? Use code tags like this: [code]...Your code here...[/code]
    Click here for examples of Java Code

  3. #3
    Join Date
    Jan 2011
    Location
    Tacoma, Washington
    Posts
    31

    Re: What In This Code Is Creating The Symbols ?

    You're better off starting from some point that you can define yourself. If you are building a Black Jack game ask yourself:

    What is a black jack game?
    What is required to play a black jack game?
    What are the real world rules for the game?

    Start jotting down answers to these questions and you might get something like this:

    Black jack requires cards, at least one player, a dealer or "house", a playing table, etc. (you don't have to implement everything you think of for example you don't necessarily need to program a "playing table")

    So now you can ask what is a card?

    A card is an object that has one of four suits and one of 13 values.

    Now that you know the "physical" properties of a card you can start creating a Card class.

    Then think about how the cards are used and start writing methods for manipulating the cards. You'll need a deck of at least 52 and some way to randomly generate them without duplicating them (assuming one deck).

    From there you can go any direction you'd like. Make it as simple or as complex as you'd like.

    I think if it were me I would be making card objects that are stored in deck objects that have methods that simulate dealing random (shuffled) cards.

    When doing a school project it is, in my opinion, more useful to build it all from scratch. When you get stuck it might be useful to examine similar code to reverse engineer to get some ideas but, you should never integrate some other programmer's code without proper citation.

    Anyway good luck

Tags for this Thread

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  


Azure Activities Information Page

Windows Mobile Development Center


Click Here to Expand Forum to Full Width

This is a CodeGuru survey question.


Featured


HTML5 Development Center