In addition to Weibo, there is also WeChat
Please pay attention
WeChat public account
Shulou
2025-03-26 Update From: SLTechnology News&Howtos shulou NAV: SLTechnology News&Howtos > Development >
Share
Shulou(Shulou.com)05/31 Report--
This article mainly introduces Java how to achieve the landlord and guess the number of game-related knowledge, content detailed and easy to understand, simple and fast operation, with a certain reference value, I believe that everyone reading this Java how to achieve the landlord and guess the number of game articles will be harvested, let's take a look at it.
Landlord Mini games Shuffle licensing task description
Prepare a landlord licensing shuffling procedures, requirements in accordance with the rules of the landlord to complete the shuffling licensing process, cards by color and numbers (including J, Q, K, A letters), color has hearts, spades, diamonds, clubs. There is also a king and a king. The order of these 54 cards will be disrupted, there are three players to participate in the game, each taking turns to touch a card, the remaining three as a card, the program ends, print out the cards and cards in each hand.
operation results
mission objectives
Learn to analyze the "Landlord Mini games shuffle licensing" program to achieve ideas.
According to the idea of independent completion of the "Landlord Mini games shuffle licensing" program code preparation, compilation and operation.
Master the characteristics of ArrayList and HashMap collections and enhance the use of for loops.
realization idea
① To implement the card program, first add 54 cards to the program, including hearts, spades, clubs, diamonds, 13 each, plus the king and the king.
(2) The suit set and the number set are nested, the suit and the number are combined to form 52 cards, and the number is assigned, and the combined cards are placed in the HashMap set. The key value of the set is the number, and the value value is the assembled card. There are also the king and the small king. Due to the inconsistent assembly rules, it is necessary to use the add() method to add these two cards to the HashMap set separately.
③ Create a set of numbers, use this set of numbers to replace the cards to complete the shuffling and dealing operations, because there are 54 cards in total, so create a set of 0-53.
④ You can use the shuffle() method of the Collections class to complete the operation of scrambling the number set to achieve the effect of shuffling. Since there are only three people, you can use the for loop to distribute the numbers representing different cards to different people and cards by taking the number and the remainder of 3.
After the shuffling is completed, the sort() method of the Collections class can be used to complete the sorting, and then the for-loop HashMap collection can be enhanced to find the corresponding card string according to the number, and stored in the newly created string collection. Finally, the string collection is displayed.
Implementation code package Swing; import java.util.ArrayList; import java.util.Collection; import java.util.Collections; import java.util.HashMap; public class DoudiZhu { public static void main(String[]args) { //Prepare the suit ArrayListcolor=new ArrayList(); color.add("spades"); color.add("hearts"); color.add("square"); add(""); //Prepare the numbers and arrange the cards from high to low using a list ArrayListnumber=new ArrayList(); for(int i=3;i
Welcome to subscribe "Shulou Technology Information " to get latest news, interesting things and hot topics in the IT industry, and controls the hottest and latest Internet news, technology news and IT industry trends.
Views: 212
*The comments in the above article only represent the author's personal views and do not represent the views and positions of this website. If you have more insights, please feel free to contribute and share.
Continue with the installation of the previous hadoop.First, install zookooper1. Decompress zookoope
"Every 5-10 years, there's a rare product, a really special, very unusual product that's the most un
© 2024 shulou.com SLNews company. All rights reserved.