java学习-狼人杀

/**
 * 参考 https://blog.csdn.net/wsy897/article/details/80096928
 * @ author 郑泽龙
 * @ version 1.0
 */

import java.util.Scanner;

public class HomeTest0001 {
    public static void main(String[] args) {
        Scanner sc = new Scanner(System.in);
        String[] status = {"平民","预言家","狼人","平民","女巫","狼人","平民"};
        int len = status.length;
        for (int i = 0; i <len ; i++) {
            System.out.println((i+1)+"号的身份为:"+status[i]);
        }
        System.out.println("天黑,请闭眼");
        System.out.println("狼人选择要杀的号码:");
        int num1 = sc.nextInt();
        status[num1-1] = "已死亡";
         System.out.println("预言家要查看谁的身份");
        int yunyan = sc.nextInt();
        System.out.println(yunyan+"号身份为"+status[yunyan-1]);
        System.out.println("女巫请选择是否救人(y/n)");
        String people = sc.next();
        if (people.equals("y")){
            System.out.println("请选择要救几号:");
            int peopleResurrection = sc.nextInt();
            status[peopleResurrection-1] = "已复活";
            System.out.println(peopleResurrection+"号已复活");
        }else if (people.equals("n")){
            System.out.println("你选择放弃救人");
        }else {
            System.out.println("你选择放弃救人");
        }
        System.out.println("女巫请选择是否毒人(y/n)");
        String killing = sc.next();
        if (killing.equals("y")){
            System.out.println("请输入要毒几号");
            int killingNUm = sc.nextInt();
            status[killingNUm-1] = "已死亡";
            System.out.println(killingNUm+"号玩家已死亡");
        }else if (people.equals("n")){
            System.out.println("你选择放弃毒人");
        }else {
            System.out.println("你选择放弃毒人");
        }
        if (status[num1-1].equals("已复活")){
            System.out.println(num1+"号玩家存活");
        }else {
            System.out.println(num1+"号玩家已死亡");
        }
        //设置投票数
        int[] poll = new int[7];
        System.out.println("请开始投票");
        for (int i = 0; i <len ; i++) {
            if (!(status[i].equals("已死亡"))){
                System.out.println((i+1)+"号请选择你认为是狼人的玩家");
                int num2 = sc.nextInt();
                switch (num2-1){
                    case 0 :
                        poll[0]++;
                        break;
                    case 1 :
                        poll[1]++;
                        break;
                    case 2 :
                        poll[2]++;
                        break;
                    case 3 :
                        poll[3]++;
                        break;
                    case 4 :
                        poll[4]++;
                        break;
                    case 5 :
                        poll[5]++;
                        break;
                    case 6 :
                        poll[6]++;
                        break;
                    case 7 :
                        poll[7]++;
                        break;
                }
            }
        }
        //回去最大投票数的下标
        int max = poll[0];
        int num3 = 0;
        for (int i = 0; i <poll.length ; i++) {
            if (poll[i]>max){
                max = poll[i];
                num3 = i;
            }
        }
        System.out.println((num3+1)+"号被投死");
        //
    }
}

刚刚学到数组,小试牛刀一下,看到的同学请多多指教。

  • 4
    点赞
  • 6
    收藏
    觉得还不错? 一键收藏
  • 打赏
    打赏
  • 5
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论 5
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

打赏作者

ZeLongTome

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

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

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

打赏作者

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

抵扣说明:

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

余额充值