小弟新人,刚接触java不久,学习十几天,觉得挺有意思的,看视频中刘意老师写的用集合模逆玩游戏,顿时觉得运用java确实能做很多事,下面是小弟手写的代码,各位大虾路过勿喷,毕竟小弟是新人~~~~
跪谢~
--------------------------------我是可爱的分割线---------------------------------------
package prictice;
import java.util.ArrayList;
import java.util.Collections;
public class PlayGame {
public static void main(String[] args) {
ArrayList<String> list = new ArrayList<String>();
String[] st = { "A", "2", "3", "4", "5", "6", "7", "8", "9", "10", "J", "Q", "K" };
String[] s = { "红桃", "梅花", "方块", "黑桃" };
list.add("大王");
list.add("小王");
for (String s1 : s) {
for (String s2 : st) {
list.add(s1.concat(s2));
}
}
Collections.shuffle(list);
// System.out.println(list);
ArrayList player1 = new ArrayList();
ArrayList player2 = new ArrayList();
ArrayList myself = new ArrayList();
for (int i = 0; i < list.size() - 3; i++) {
if (i % 3 == 0) {
player1.add(list.get(i));
}
if (i % 3 == 1) {
player2.add(list.get(i));
}
if (i % 3 == 2) {
myself.add(list.get(i));
}
}
System.out.println("底牌");
for(int i = list.size()-3;i<list.size();i++){
System.out.print(list.get(i)+"\t");
}
System.out.println();
System.out.println("玩家一的手牌");
System.out.println(player1);
System.out.println("玩家二的手牌");
System.out.println(player2);
System.out.println("我的手牌");
System.out.println(myself);
}
}
|
|