Welcome to Dream.In.Code
Become a Java Expert!

Join 150,051 Java Programmers for FREE! Get instant access to thousands of Java experts, tutorials, code snippets, and more! There are 1,704 people online right now. Registration is fast and FREE... Join Now!




Bingo Game Help

 
Reply to this topicStart new topic

Bingo Game Help, Designing the look of a bingo card

rge
3 Jun, 2008 - 06:45 PM
Post #1

New D.I.C Head
*

Joined: 3 Jun, 2008
Posts: 10

I have to create a bingo game that runs through until it wins. I have created a new class called ASet. This class is sort of like a collection, storing generic data of any type
and having implemented a SetInterface I created.

The card has to look like this...

|----|----|----|----|----|
| B | I | N | G | O |
|----|----|----|----|----|
| 2| 27| 33| 55| 62|

.....and so on with the Middle N column a Zero.

So my problem here is when ever the number is found it is replaced with a zero. This messes up the columns pushing them out of line when it is two digits.
I tried making tags to put in when it goes to a zero but it is all going wrong still. Any help would greatly be appreciated. I will put my code for printing out
the card as I have it now but it is really messy. If you need anymore information to better help me out just let me know. Thanks!

CODE


System.out.println("|----|----|----|----|----|");
System.out.println("| B  | I  | N  | G  | O  |");
System.out.println("|----|----|----|----|----|");

        String tag = new String();
        String tag2 = new String();
        String tag3 = new String();
        String tag4 = new String();
        String tag5 = new String();
        
        for (int index1 = 0; index1 <= 1; index1++) {
            if (bColumn.getEntry(index1) <= 9) {
                tag = " ";
            }
            if (iColumn.getEntry(index1) == 0) {
                tag2 = " ";
            }
            if (nColumn.getEntry(index1) == 0) {
                tag3 = " ";
            }
            if (gColumn.getEntry(index1) == 0) {
                tag4 = " ";
                
            }
            if (oColumn.getEntry(index1) == 0) {
                tag5 = " ";
            }
            
            System.out.println("|  " + tag + bColumn.getEntry(index1) +  "|  " + tag2 + iColumn.getEntry(index1) +  "|  " + tag3
                    + nColumn.getEntry(index1) + "|  " + tag4 + gColumn.getEntry(index1) + "|  " + tag5 + oColumn.getEntry(index1) + "| ");
        }
        
        if (bColumn.getEntry(2) <= 9) {
            
            if (bColumn.getEntry(2) <= 9) {
                tag = " ";
            }
            if (iColumn.getEntry(2) == 0) {
                tag2 = " ";
            }
            if (nColumn.getEntry(2) == 0) {
                tag3 = " ";
            }
            if (gColumn.getEntry(2) == 0) {
                tag4 = " ";
            }
            if (oColumn.getEntry(2) == 0) {
                tag5 = " ";
            }
            System.out.println("|  " + tag + bColumn.getEntry(2) +  "|  " + tag2 + iColumn.getEntry(2) +  "|  "
                    + tag3 +  "0|  " + tag4 + gColumn.getEntry(2) + "|  " + tag5 + oColumn.getEntry(2) + "| ");
        }
        
        for (int index1 = 3; index1 <= 4; index1++) {
            if (bColumn.getEntry(index1) <= 9) {
                tag = " ";
            }
            if (iColumn.getEntry(index1) == 0) {
                tag2 = " ";
            }
            if (nColumn.getEntry(index1) == 0) {
                tag3 = " ";
            }
            if (gColumn.getEntry(index1) == 0) {
                tag4 = " ";
            }
            if (oColumn.getEntry(index1) == 0) {
                tag5 = " ";
            }
            System.out.println("|  " + tag + bColumn.getEntry(index1) +  "|  " + tag2 + iColumn.getEntry(index1) +  "|  "
                    + tag3 + nColumn.getEntry(index1) + "|  " + tag4 + gColumn.getEntry(index1) + "|  " + tag5 + oColumn.getEntry(index1) + "| ");
        }
        System.out.println("|----|----|----|----|----|");


QUOTE(rge @ 3 Jun, 2008 - 07:43 PM) *

I have to create a bingo game that runs through until it wins. I have created a new class called ASet. This class is sort of like a collection, storing generic data of any type
and having implemented a SetInterface I created.

The card has to look like this...

|----|----|----|----|----|
| B | I | N | G | O |
|----|----|----|----|----|
| 2| 27| 33| 55| 62|

.....and so on with the Middle N column a Zero.

So my problem here is when ever the number is found it is replaced with a zero. This messes up the columns pushing them out of line when it is two digits.
I tried making tags to put in when it goes to a zero but it is all going wrong still. Any help would greatly be appreciated. I will put my code for printing out
the card as I have it now but it is really messy. If you need anymore information to better help me out just let me know. Thanks!

CODE


System.out.println("|----|----|----|----|----|");
System.out.println("| B  | I  | N  | G  | O  |");
System.out.println("|----|----|----|----|----|");

        String tag = new String();
        String tag2 = new String();
        String tag3 = new String();
        String tag4 = new String();
        String tag5 = new String();
        
        for (int index1 = 0; index1 <= 1; index1++) {
            if (bColumn.getEntry(index1) <= 9) {
                tag = " ";
            }
            if (iColumn.getEntry(index1) == 0) {
                tag2 = " ";
            }
            if (nColumn.getEntry(index1) == 0) {
                tag3 = " ";
            }
            if (gColumn.getEntry(index1) == 0) {
                tag4 = " ";
                
            }
            if (oColumn.getEntry(index1) == 0) {
                tag5 = " ";
            }
            
            System.out.println("|  " + tag + bColumn.getEntry(index1) +  "|  " + tag2 + iColumn.getEntry(index1) +  "|  " + tag3
                    + nColumn.getEntry(index1) + "|  " + tag4 + gColumn.getEntry(index1) + "|  " + tag5 + oColumn.getEntry(index1) + "| ");
        }
        
        if (bColumn.getEntry(2) <= 9) {
            
            if (bColumn.getEntry(2) <= 9) {
                tag = " ";
            }
            if (iColumn.getEntry(2) == 0) {
                tag2 = " ";
            }
            if (nColumn.getEntry(2) == 0) {
                tag3 = " ";
            }
            if (gColumn.getEntry(2) == 0) {
                tag4 = " ";
            }
            if (oColumn.getEntry(2) == 0) {
                tag5 = " ";
            }
            System.out.println("|  " + tag + bColumn.getEntry(2) +  "|  " + tag2 + iColumn.getEntry(2) +  "|  "
                    + tag3 +  "0|  " + tag4 + gColumn.getEntry(2) + "|  " + tag5 + oColumn.getEntry(2) + "| ");
        }
        
        for (int index1 = 3; index1 <= 4; index1++) {
            if (bColumn.getEntry(index1) <= 9) {
                tag = " ";
            }
            if (iColumn.getEntry(index1) == 0) {
                tag2 = " ";
            }
            if (nColumn.getEntry(index1) == 0) {
                tag3 = " ";
            }
            if (gColumn.getEntry(index1) == 0) {
                tag4 = " ";
            }
            if (oColumn.getEntry(index1) == 0) {
                tag5 = " ";
            }
            System.out.println("|  " + tag + bColumn.getEntry(index1) +  "|  " + tag2 + iColumn.getEntry(index1) +  "|  "
                    + tag3 + nColumn.getEntry(index1) + "|  " + tag4 + gColumn.getEntry(index1) + "|  " + tag5 + oColumn.getEntry(index1) + "| ");
        }
        System.out.println("|----|----|----|----|----|");






p.s. the design of the card does not really show up right but everything is suppose to be lined up in the columns.

This post has been edited by rge: 3 Jun, 2008 - 06:44 PM
User is offlineProfile CardPM
+Quote Post

pbl
RE: Bingo Game Help
3 Jun, 2008 - 07:15 PM
Post #2

D.I.C Lover
Group Icon

Joined: 6 Mar, 2008
Posts: 3,587



Thanked: 233 times
Dream Kudos: 75
My Contributions
Console applications (System.out.print()) have never been designed to display nice output due to the font that shows W larger than I.

However if you use TABS "\t" you might manage to have some alignment

This code uses tab and print numbers betwwen 1 and 20.

I used TAB before outputting | followed by a defferent number of spaces if the number is smaller than 10.

I might achieve what you want

CODE


public class Main {

    public static void main(String[] arg) {
    

        printLine();
        System.out.println("\t|   B\t|   I\t|   N\t|   G\t|   O\t|");
        printLine();

        for(int i = 1; i < 21; i++) {
            System.out.print("\t|  ");
            if(i < 10)
                System.out.print(" ");
            System.out.print(i);
            if(i % 5 == 0) {
                System.out.println("\t|");
                printLine();
            }
                
        }
    }
    
    static void printLine() {
        // this one determine by test an trial
        System.out.print("\t+");
        for(int j = 1; j < 40; j++) {
            if(j % 8 == 0)
                System.out.print("+");
            else
                System.out.print("-");
        }
        System.out.println("+");
    }
}


User is online!Profile CardPM
+Quote Post

Fast ReplyReply to this topicStart new topic
Time is now: 1/8/09 10:16PM

Be Social

Dream.In.Code RSS Feed Dream.In.Code LinkedIn Group Follow Us On Twitter

Live Java Help!

Java Tutorials

Reference Sheets

Java Snippets

DIC Chatroom

Bye Bye Ads

Monthly Drawing

Thumb Drive

Top Contributors

Top 10 Kudos This Month