package com.assignmet;
import java.util.Scanner;
public class Tady14 {
public static void main(String[] args) {
// TODO Auto-generated method stub Scanner sr2 = new Scanner(System.in); System.out.println("Tom很牛叉,敢和电脑玩猜拳,开始进入游戏"); System.out.println("1、开始游戏"); System.out.println("2、推出游戏"); System.out.println("3、统计胜负"); System.out.print("请选择: "); int e = sr2.nextInt(); System.out.println("----------------------------"); for (int i = 1; i <= 1000; i++) { if (e == 1) { switch (e) { case 1: Tom tom = new Tom(); tom.game(); System.out.println("1、继续游戏"); System.out.println("2、推出游戏"); System.out.println("3、统计胜负"); System.out.print("请选择: "); e = sr2.nextInt(); System.out.println("----------------------------"); if (e == 2) { break; } if (e == 3) { System.out.print("***Tom最后赢了"+(tom.c-1)+"次"); break; } break; } }}
}}class Tom {
int a; int b; static int c = 1; static int d = 1;public Tom() {
a = (int) (Math.random() * 3); Scanner sr = new Scanner(System.in); System.out.print("Tom请出拳 : "); b = sr.nextInt();}
public void get() {
if (a == 0 && b == 1) { System.out.println("电脑出的是“石头”:"); System.out.println("****电脑赢 " + (d++) + "次"); } else if (a == 0 && b == 2) { System.out.println("电脑出的是“石头”:"); System.out.println("####tom赢 " + (c++) + "次"); } else if (a == 1 && b == 0) { System.out.println("电脑出的是“剪刀”:"); System.out.println("####tom赢 "+(c++)+"次"); } else if (a == 1 && b == 2) { System.out.println("电脑出的是“剪刀”"); System.out.println("****电脑赢 "+(d++)+"次"); } else if (a == 2 && b == 0) { System.out.println("电脑出的是“布”"); System.out.println("****电脑赢 " + (d++) + "次"); } else if (a == 2 && b == 1) { System.out.println("电脑出的是“布”"); System.out.println("####tom赢 " + (c++) + "次"); } else if (a == b) { if (a == 0) { System.out.println("电脑出的是“石头”"); System.out.println("!!!!出拳一样"); } if (a == 1) { System.out.println("电脑出的是“剪刀”"); System.out.println("!!!!出拳一样"); } if (a == 2) { System.out.println("电脑出的是“布”"); System.out.println("!!!!出拳一样 "); } } }public void game() {
if (b >= 3) { System.out.println("Tom出拳不对,请重新出拳"); get(); } else { if (b == 0) { System.out.print("Tom出的是“石头”<--->"); get(); } if (b == 1) { System.out.print("Tom出的是“剪刀”<--->"); get(); } if (b == 2) { System.out.print("Tom出的是“布”<--->"); get(); } } }}