the hard part is logical analysis, the ability to convert logic into code is a capability that needs to be summed up in more practice.
A lot of advice, common progress.
Problem:
requires the implementation of the Bucket Landlord game licensing process, printing three players cards and cards. In the case of not looking at the cards, the number of three players to count bombs;
S (small) on behalf of Xiao Wang, B (big) on behalf of the King
--------------------------------------------------------------------------------------------------------------- --------------
--------------------------------------------------------------------------------------------------------------- --------------
Thinking Analysis:
all with the digital representation of the size and color of the card, so that it can be conveniently stored and distributed, only in the final printing card when the actual color and size conversion;
How to count the number of bombs randomly issued?
1, the library consists of 54 cards, with a two-dimensional array to store 4 rows and 14 columns ( the row represents the suit, the column represents the size of the card )
1) The difficulty is how to store the size of the King
because the next is randomly issued to three people, so casually use the 14th column of two rows to store the size of the king, (also with the number for the size of the King), the remaining two rows of the 14th column is empty;
2) define a two-dimensional array of Boolean types, and also 4 rows and 14 columns, and set the subscript of the card library to true;
2, randomly generated cards
randomly generated number 0-3 to control the number of lines, that is, the color of the card;
randomly generate a number 0-14 to control the number of columns, that is, the size of the card ;
3, random distribution card
1) Randomly generated number 1-3, 3 for redundancy, 0 for the first person, 1 for the second person, 2 for the third person;
2) Whether the judgment has been sent out (using Boolean array to judge, true means not sent out)
use an array to store the emitted color, send it out and use a Boolean array to set the subscript to false, and calculate the number of cards issued;
3) The same is second, the third person randomly licensing;
4) Condition judgment, when already issued to 51 cards, jump out of the loop;
4. Print the generated cards and cards
1) Traverse the Boolean array and the card library at this time, find the subscript and the size of the card, you can get the hole cards;
2) The color and size of the cards generated are traversed by an array of one array storing the suit and the size of the memory card;
5, traverse the count of everyone's bombs
1) First count the number of king size, and then double loop to traverse other cards whether there is a bomb ;
2) In the same vein, the second person is counted, the third one;
Code implementation:
How the Java Foundation solves the problem of landlords