Java斗地主--index1 (0801)

今天遇到一个很有意思的游戏–斗地主,那么下面就开始实现斗地主啦!!!

package Demo_YY;

public class PockerIndex {
  public static void main(String[] args) {
    start();
  }

  public static void start(){
    String pocker[] = new String[54];
    String colors[] = {"♠","♣","♥","♦"};
    String nums[] = {"3","4","5","6","7","8","9","10","J","Q","K","A","2"};

    int index = 0;
    for (int i = 0; i < nums.length; i++){
      for (int j = 0; j < colors.length; j++){
        pocker[index++] = colors[j] + nums[i];
      }
    }

//    大小王🃏🂿
    pocker[index++] ="\uD83C\uDCCF";
    pocker[index] ="\uD83C\uDCBF";
//    看牌
    for (int i = 0; i < pocker.length; i++){
      System.out.print(pocker[i]+"\t");
      if((i+1) % 4 == 0 )
      {
        System.out.println();
      }
    }

  }
}

请添加图片描述

  int index = 0;
    for (int i = 0; i < colors.length; i++){
      for (int j = 0; j < nums.length; j++){
        pocker[index++] = colors[i] + nums[j];
      }
    }

修改了这里之后发现什么了呢?就是顺序不一样而已啦!
请添加图片描述
这里只是存储了54张牌,下面我们开始洗牌啦!

package Demo_YY;

public class PockerIndex {
 public static void main(String[] args) {
   start();
 }

 public static void start(){
   String pocker[] = new String[54];
   String colors[] = {"♠","♣","♥","♦"};
   String nums[] = {"3","4","5","6","7","8","9","10","J","Q","K","A","2"};

   int index = 0;
   for (int i = 0; i < nums.length; i++){
     for (int j = 0; j < colors.length; j++){
       pocker[index++] = colors[j] + nums[i];
     }
   }

//    大小王🃏🂿
   pocker[index++] ="\uD83C\uDCCF";
   pocker[index] ="\uD83C\uDCBF";
   System.out.println("\t\t\t看牌");
//    看牌
   for (int i = 0; i < pocker.length; i++){
     System.out.print(pocker[i]+"\t");
     if((i+1) % 8 == 0 )
     {
       System.out.println();
     }
   }
   System.out.println();
   System.out.println();
//    洗牌
   for(int i = 0; i < pocker.length; i++){
     int index1 = (int)(Math.random()*pocker.length);
     int index2 = (int)(Math.random()*pocker.length);
     String temp = pocker[index1];
     pocker[index1] = pocker[index2];
     pocker[index2] = temp;
   }
   System.out.println("\t\t\t洗牌后\t\t");
   for (int i = 0; i < pocker.length; i++){
     System.out.print(pocker[i]+"\t");
     if((i+1) % 8 == 0 )
     {
       System.out.println();
     }
   }


 }


}

请添加图片描述
完结,moyu_ing

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包

打赏作者

尸僵打怪兽

你的鼓励将是我创作的最大动力

¥1 ¥2 ¥4 ¥6 ¥10 ¥20
扫码支付:¥1
获取中
扫码支付

您的余额不足,请更换扫码支付或充值

打赏作者

实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值