学过了模拟斗地主发牌,,因本人不玩斗地主,,所以改了一个三国杀发牌,,一开始就找不到思路,,现在特地分享给大家,一块理解一下思路,,
因为还不会让代码出牌,,所以牌只能一直增加,,
有些人可能没有玩过三国杀,,,在此说一下,,三国杀,每回合每人发两张牌,,出牌结束后到下一个人,,,于是下一个人再得两张牌,,,
另外还有一点必须声明,,,有一个地方还有修改好,,当前这个代码只能发26次牌,,以后学了新知识再改进..
- package cn.itcast;
- import java.util.ArrayList;
- import java.util.Collections;
- import java.util.Scanner;
- /*模拟三国杀发牌,,
- * 1,买牌
- * 2,洗牌
- * 3,发牌,每次发两张牌,,回合结束,点结束出牌,则发给下一个人两张牌,以此循环。
- *
- * */
- public class sanGuSha2 {
- public static void main(String[] args) {
- String[] colors = {"红","方","黑","梅"};
- String[] numbers= {"1杀","2杀","3杀","4闪","5闪","6桃","7闪",
- "8探囊取物","9釜底抽薪","10烽火狼烟","J万箭齐发","Q刀","K盾"};
-
- ArrayList<String> array = new ArrayList<String>();
-
- for (String c : colors) {
- for (String n : numbers) {
- array.add(c.concat(n));
- }
- }
- Collections.shuffle(array);
- ArrayList<String> zhangfei = new ArrayList<String>();
- ArrayList<String> guanyu = new ArrayList<String>();
- int j=0;
- int x = 0;
- System.out.println("开始");
- String string = "结束出牌";
-
- while(j<=array.size()&& string.equals("结束出牌")){
-
-
- if(x%2==0){
- for (int i = j; i <= j+1; i++) {
- zhangfei.add(array.get(i));
- }
- System.out.println("zhangfei"+zhangfei);
- }else{
- for (int i = j; i <= j+1; i++) {
- guanyu.add(array.get(i));
- }
- System.out.println("guanyu"+guanyu);
- }
- j+=2;
- x++;
- System.out.println("是否结束出牌");
- Scanner scc = new Scanner(System.in);
- string = scc.next();
- System.out.println("下一回合");
- }
- }
- }
复制代码 |
|