Results 1 to 9 of 9
  1. #1
    XMarkoX is offline Member
    Join Date
    Nov 2009
    Posts
    9
    Rep Power
    0

    Default Help please, bingo game.

    Okay, i'm making this bingo game but i need some help. It has to be 9 random numbers 3x3 for every player. Here is what i have gained so far: Ask how many players, if wrong input, it gives error and asks you to give player amount again. Also I've got it to make some random numbers but not 3x3.

    left to do : The actual game, and that it makes the 3x3 game for the amount of players given from keyboard. I've got NO CLUE, how to continue. I'd appreciate if someone could help me. Thanks in advance

    heres the code:
    Java Code:
    import java.util.Scanner;
    import java.util.Random;
    public class Niiranenmarkolopputehtävä2 {
    
    
    static Random r=new Random();
    
    public static void main(String[] args) {
    
    // TODO Auto-generated method stub
    
    	
    	
    
    	  
        Scanner in = new Scanner(System.in);
        int players= 0;
        
        
        IndexOutOfBoundsException outOfRange = new IndexOutOfBoundsException ("");
        NumberFormatException nonNumbericValue = new NumberFormatException ("");
        
        boolean repeat = true; 
        
        while(repeat == true)
        {
            try
            {
                System.out.println("How many players (1-4)");
                
                if(in.hasNextInt() == true)
                {
                	players = in.nextInt();
                    repeat = false;
                }
                else 
                    throw nonNumbericValue;                    
                
                if(players> 6 || players < 2)
                    throw outOfRange;
    
            }
            
            catch (IndexOutOfBoundsException e)
            {
                repeat = true;
                System.out.println(outOfRange.toString());
            }
            
            catch (NumberFormatException e)
            {
                repeat = true;
                System.out.println(e.toString());
            }
            
    	
    for (int i=0;i<10;i++){
    
    int x=r.nextInt(10)+1;
    
    System.out.println(x);
    
    }
    
    }
    }
    }
    Last edited by XMarkoX; 11-18-2009 at 08:11 AM.

  2. #2
    XMarkoX is offline Member
    Join Date
    Nov 2009
    Posts
    9
    Rep Power
    0

    Default

    I've got like week left to do this thing. been fighting intense fight with it for few days. xD

  3. #3
    XMarkoX is offline Member
    Join Date
    Nov 2009
    Posts
    9
    Rep Power
    0

    Default

    The output should be something like this.. :S

    Welcome to play bingo game
    How many players: 1
    5 7 9
    3 1 6
    4 8 2

    Continue game (y/n) Y
    5 7 9
    3 1 6
    0 8 2

    Continue game (y/n) Y
    5 7 9
    0 1 6
    0 8 2
    Continue game (y/n) Y
    5 7 9
    0 0 6
    0 8 2
    Continue game (y/n) Y
    5 7 0
    0 0 6
    0 8 2
    BINGO

    And end of game.

  4. #4
    XMarkoX is offline Member
    Join Date
    Nov 2009
    Posts
    9
    Rep Power
    0

    Default

    C'mon.. this should be so easy for advanced coder. But im still stuck at this point, got 4 days left.. lawl. :P

  5. #5
    JosAH's Avatar
    JosAH is offline Moderator
    Join Date
    Sep 2008
    Location
    Voorschoten, the Netherlands
    Posts
    13,340
    Blog Entries
    7
    Rep Power
    20

    Default

    I'll give you a jump start; it's spoonfeeding so no further comments;

    Java Code:
    import java.util.ArrayList;
    import java.util.Arrays;
    import java.util.Collections;
    import java.util.Iterator;
    import java.util.List;
    
    public class Board {
    
    	private static int[][] board(int n) {
    		
    		List<Integer> list= new ArrayList<Integer>();
    		
    		for (int i= 0; i < n; list.add(i++));
    		Collections.shuffle(list);
    		
    		int[][] board= new int[3][3];
    		Iterator<Integer> i= list.iterator();
    		
    		for (int r= 0; r < board.length; r++)
    			for (int c= 0; c < board[r].length; c++)
    				board[r][c]= i.next();
    		
    		return board;
    	}
    
    	public static void main(String[] args) {
    
    		int[][] b= board(50);
    		
    		System.out.println(Arrays.deepToString(b));
    	}
    }
    kind regards,

    Jos

  6. #6
    XMarkoX is offline Member
    Join Date
    Nov 2009
    Posts
    9
    Rep Power
    0

    Default

    Thank you, helped a lot.

  7. #7
    JosAH's Avatar
    JosAH is offline Moderator
    Join Date
    Sep 2008
    Location
    Voorschoten, the Netherlands
    Posts
    13,340
    Blog Entries
    7
    Rep Power
    20

    Default

    Quote Originally Posted by XMarkoX View Post
    Thank you, helped a lot.
    Good; you're welcome of course; a bit of advice: don't just copy and paste the stuff but read the API documentation for every class used and try to understand what is happening.

    kind regards,

    Jos

  8. #8
    XMarkoX is offline Member
    Join Date
    Nov 2009
    Posts
    9
    Rep Power
    0

    Default

    Well, thats the weird part.. i know what it does.. i can read the code.. but its harder to code.. i know its weird but yeah.. I edited it a lil bit and made better for my "needs" :p

  9. #9
    Join Date
    Nov 2009
    Posts
    22
    Rep Power
    0

    Default

    year!!

    thank very must
    :D I'm from vietnam - I hope you help me :D

Similar Threads

  1. Replies: 2
    Last Post: 08-05-2010, 04:49 AM
  2. Help with my game!
    By Manikyr in forum New To Java
    Replies: 6
    Last Post: 06-06-2009, 11:09 AM
  3. Multi Client-Bingo
    By Aga^^ in forum Networking
    Replies: 0
    Last Post: 05-23-2009, 05:21 PM
  4. Game 21
    By aRTx in forum Advanced Java
    Replies: 3
    Last Post: 04-04-2009, 12:33 AM
  5. 2D strategy game or 2D war game
    By led1433 in forum Java 2D
    Replies: 5
    Last Post: 02-10-2009, 06:00 AM

Posting Permissions

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