模拟斗地主

模拟斗地主

package com.itheima_01;

import java.util.ArrayList;
import java.util.Collections;
import java.util.Random;

public class Test04 {

	public static void main(String[] args) {
		Random r = new Random();
		int nextInt = r.nextInt(3)+1;
		System.out.println(nextInt);
		String [] color = {"红桃","方片","黑桃","梅花"};
		String []number = {"A","2","3","4","5","6","7","8","9","10","J","Q","K"};
		ArrayList  arrayList = new ArrayList<>();
		for (int i = 0; i < color.length; i++) {
			for (int j = 0; j < number.length; j++) {
				arrayList.add(color[i]+number[j]);}}
		arrayList.add("大王");
		arrayList.add("小王");
		Collections.shuffle(arrayList);
		ArrayList 马良 = new ArrayList();
		ArrayList 大蓓蓓 = new ArrayList();
		ArrayList 马小燕 = new ArrayList();
		for (int i = 0; i < arrayList.size()-3; i++) {
			if(i%3 == 0){
				马良.add(arrayList.get(i));}
			if(i%3 == 1){
				大蓓蓓.add(arrayList.get(i));}
			if(i%3 == 2){
				马小燕.add(arrayList.get(i));}
		}
		System.out.print("底牌为:");
		ArrayList  arrayList2 = new ArrayList<>();
		
		for (int i = arrayList.size()-3; i < arrayList.size(); i++) {
			arrayList2.add(arrayList.get(i));
			
			System.out.print(arrayList.get(i)+",");
		}
		System.out.println();
		
		
		if(nextInt == 1){
			马良.addAll(arrayList2);
			System.out.println("地主为马良");
		}else if(nextInt == 2){
			大蓓蓓.addAll(arrayList2);
			System.out.println("地主为大蓓蓓");
		}else if(nextInt == 3){
			马小燕.addAll(arrayList2);
			System.out.println("地主为马小燕");
		}else{}
		System.out.println("马良:"+马良);
		System.out.println("大蓓蓓:"+大蓓蓓);
		System.out.println("马小燕:"+马小燕);
	}

}

你可能感兴趣的:(Demo)