i 绝望

依然

Miss Lang

有趣的java小项目------猜拳游戏

package com.aaa;

//总结:猜拳游戏主要掌握3个方面:1.人出的动作是从键盘输入的(System.in)2.电脑是随机出的(Random随机数)3.双方都要出(条件判断)
import java.util.Scanner;

public class bbb {
	public static void main(String[] args) {
		Scanner in = new Scanner(System.in);
		System.out.println("----猜拳游戏----");
		System.out.println("请出拳 (1.剪刀 2.石头 3.布)");
		int person = in.nextInt();
		int computer = (int) (Math.random() * 3) + 1;
		String Marks = "拳头";// 你出的是
		String Marks2 = "拳头";// 电脑出的是
		switch (person) {
		case 1:
			Marks = "剪刀";
			break;
		case 2:
			Marks = "石头";
			break;
		case 3:
			Marks = "布";
			break;

		}
		switch (computer) {
		case 1:
			Marks2 = "剪刀";
			break;
		case 2:
			Marks2 = "石头";
			break;
		case 3:
			Marks2 = "布";
			break;

		}

		System.out.println(computer);
		if (person == 1 && computer == 1) {
			System.out
					.println("你出的是:" + Marks + ",电脑输出的是" + Marks2 + "~0~--平局");

		} else if (person == 1 && computer == 2 || person == 2 && computer == 3
				||

				person == 3 && computer == 1) {
			System.out.println("你出的是:" + Marks + ",电脑输出的是" + Marks2 + "你输了-_-");
		} else
			System.out.println("你出的是:" + Marks + ",电脑输出的是:" + Marks2 + "你赢了!");
	}
}

  

 

posted on 2013-10-23 00:28  juewang  阅读(1899)  评论(0编辑  收藏  举报

绝望依然

Miss Lang