Lighthalzen Posted March 1, 2009 Share Posted March 1, 2009 Hello All! I have a project for school to create a bingo game, however, I am currently stuck on how to design how to store stuff in an array: The game can choose up to 20 players [user can input how many players] Each player would get 1 or 2 cards. Each card contains 25 numbers Now what I am trying to ask is, how should I store each card for each player knowing that the # number players would be dynamic? Link to comment Share on other sites More sharing options...
0 lime Posted March 2, 2009 Share Posted March 2, 2009 List/Array of Player objects - Player object has List/Array of Card objects - Card objects has List/Array of numbers (ints) Basically you take the number of players input and create that many new Player objects and put them in a List or Array or whatever... Something like that would work right? Link to comment Share on other sites More sharing options...
0 neoAndy Posted March 2, 2009 Share Posted March 2, 2009 u got 3 classes .. Player / Cards / Engine ... u gonna create a big ArrayList of player type - i guess as i first thought of this game - to be in the Engine Class ... Player will have a small 'array' of the cards ... cards will have a small 'array' of int type ... its engine is so simple i assume , my own problem with this would be with its interface , i'm bad in design hehe :p Link to comment Share on other sites More sharing options...
0 Lighthalzen Posted March 2, 2009 Author Share Posted March 2, 2009 Thanks for the suggestions guys! But now I am stuck on another problem, every time I want to return the generated numbers back to my array, it will fill it with "0"s if I have more than one player, and I don't know what's wrong! import java.util.*; public class OurBingo { public OurBingo() { } public static void main(String[] args) { Boolean Game_State = true; int[][][] player_Cards_DBase; System.out.println("Project #1, OurBingo"); System.out.println("--------------------"); int num_player = player_input(); player_Cards_DBase = new int[num_player][num_player][num_player]; System.out.println("\n"); String player_datebase[] = player_creation(num_player); int draw_Num = max_Draw(); System.out.println("< All the players have been created! >"); System.out.printf("%d players have been created as follows: \n\n", num_player); for(int i = 0; i < num_player; i++){ player_Cards_DBase = card_Generator(i, num_player); } for(int i = 0; i < num_player; i++){ System.out.println("---------------------------------"); System.out.printf("Player %s\n\n", player_datebase[i]); for(int j = 0; j < 5; j++){ for(int k = 0; k < 5; k++){ System.out.printf("%5d", player_Cards_DBase[i][j][k]); } System.out.println("\n"); } } } public static int player_input(){ Scanner num_player = new Scanner(System.in); int player = 0; do{ System.out.print("Please enter the number of players you want to create [<= 20]: "); player = num_player.nextInt(); }while(player > 20); return player; } public static String[] player_creation(int num_players){ String Player_Database[] = new String[num_players]; for(int i = 0; i < num_players; i++){ Player_Database[i] = "P" + i; } return Player_Database; } public static int max_Draw(){ Scanner readDraw = new Scanner(System.in); int num_Draw = 0; System.out.print("Please enter the maximum number of draws you want to play: "); num_Draw = readDraw.nextInt(); System.out.print("\n\n"); return num_Draw; } public static int[][][] card_Generator(int p_index, int p_num){ Random bingo_Num_Gen = new Random(); int[][][] temp_Card = new int[p_num][5][5]; for(int i = 0; i < 5; i++){ for(int j = 0; j < 5; j++){ temp_Card[p_index][j][i] = bingo_Num_Gen.nextInt(10); } } for(int i = 1; i < 5; i++){ for(int j = 0; j < 5; j++){ temp_Card[p_index][j][i] = bingo_Num_Gen.nextInt(10) + 10; } } for(int i = 2; i < 5; i++){ for(int j = 0; j < 5; j++){ temp_Card[p_index][j][i] = bingo_Num_Gen.nextInt(10) + 20; } } for(int i = 3; i < 5; i++){ for(int j = 0; j < 5; j++){ temp_Card[p_index][j][i] = bingo_Num_Gen.nextInt(10) + 30; } } for(int i = 4; i < 5; i++){ for(int j = 0; j < 5; j++){ temp_Card[p_index][j][i] = bingo_Num_Gen.nextInt(10) + 40; } } return temp_Card; } } Link to comment Share on other sites More sharing options...
0 Lighthalzen Posted March 2, 2009 Author Share Posted March 2, 2009 Nvm, Fixed ^<^ Link to comment Share on other sites More sharing options...
0 lime Posted March 3, 2009 Share Posted March 3, 2009 public static int[][][] card_Generator(int p_index, int p_num) That kind of a method signature makes me want to gouge my eyes out. An int[][][] ???? Definitely a code smell.....smells real bad.... I don't want to do your homework for you...but some pointers: 1. Make an "Engine" type class that does all the work, don't do it all in that class with static methods. 2. Change your method naming scheme....card_Generator is not a method name. generateCards() is. 3. This little project is not hard. It would be much easier to use better object orientation like described above. You're definitely doing it the hard way. If I had to look at code like that at work I would delete all of it immediately and rewrite. It is not maintainable and error prone. Just a heads up....I don't mean to be harsh....so just ask more questions and we will help you make it better ;) Link to comment Share on other sites More sharing options...
0 Lighthalzen Posted March 3, 2009 Author Share Posted March 3, 2009 Yeah, I haven't learned the Engine thing yet... so I have no idea what you mean >,< But I will look into the other stuff. Link to comment Share on other sites More sharing options...
0 Andre S. Veteran Posted March 3, 2009 Veteran Share Posted March 3, 2009 Just a heads up....I don't mean to be harsh....so just ask more questions and we will help you make it better ;)I think you are indeed a bit harsh. A simple bingo game doesn't need to be object-oriented at all. It's already very good for a beginner if each method has a single, clear purpose, if the code compiles cleanly and the program does exactly what required. Link to comment Share on other sites More sharing options...
Question
Lighthalzen
Hello All! I have a project for school to create a bingo game, however, I am currently stuck on how to design how to store stuff in an array:
The game can choose up to 20 players [user can input how many players]
Each player would get 1 or 2 cards.
Each card contains 25 numbers
Now what I am trying to ask is, how should I store each card for each player knowing that the # number players would be dynamic?
Link to comment
Share on other sites
7 answers to this question
Recommended Posts