唐诗缺字游戏
来源:互联网 发布:3306端口对外开放 编辑:程序博客网 时间:2024/05/01 12:30
package com.xinzhanedu;
import java.util.Random;
import java.util.Scanner;
public class PlayGame {
public static void main(String[] args) {
int optionIndex = 0;
Scanner scanner = new Scanner(System.in);
System.out.println("请输入一首五言律诗");
String str1 = scanner.next();
String str2 = scanner.next();
String str3 = scanner.next();
String str4 = scanner.next();
Random random = new Random();
int index1 = random.nextInt(5);
int index2 = random.nextInt(5);
int index3 = random.nextInt(5);
int index4 = random.nextInt(5);
String rightAnswer = str1.charAt(index1) + " " + str2.charAt(index2)
+ " " + str3.charAt(index3) + " " + str4.charAt(index4) + " ";
char[] words = new char[4];
words[0] = str1.charAt(index1);
words[1] = str2.charAt(index2);
words[2] = str3.charAt(index3);
words[3] = str4.charAt(index4);
// 出题
str1 = str1.substring(0, index1) + "_" + str1.substring(index1 + 1);
str2 = str2.substring(0, index2) + "_" + str2.substring(index2 + 1);
str3 = str3.substring(0, index3) + "_" + str3.substring(index3 + 1);
str4 = str4.substring(0, index4) + "_" + str4.substring(index4 + 1);
System.out.println(str1);
System.out.println(str2);
System.out.println(str3);
System.out.println(str4);
String[] options = new String[4];
options[0] = rightAnswer;
optionIndex++;
int currentIndex=optionIndex;
boolean falg = true;
while (falg) {
int[] arr = { -1, -1, -1, -1 };
int i1 = random.nextInt(4);
int i2 = random.nextInt(4);
int i3 = random.nextInt(4);
int i4 = random.nextInt(4);
arr[i1] = 1;
arr[i2] = 1;
arr[i3] = 1;
arr[i4] = 1;
boolean falg2 = false;
for (int i = 0; i < 4; i++) {
if (arr[i] == -1) {
falg2 = true;
break;
}
}
if (falg2 == true) {
continue;
}
String answer = "" + words[i1] + words[i2] + words[i3] + words[i4];
boolean falg3 = false;
for (int i = 0; i < currentIndex; i++) {
if (options[i].equals(answer)) {
falg3 = true;
break;
}
}
if (falg3 == true) {
continue;
}
options[optionIndex++] = answer;
if (optionIndex == 4) {
break;
}
currentIndex++;
}
while (true) {
int[] arr = { -1, -1, -1, -1 };
int i1 = random.nextInt(4);
int i2 = random.nextInt(4);
int i3 = random.nextInt(4);
int i4 = random.nextInt(4);
arr[i1] = 1;
arr[i2] = 1;
arr[i3] = 1;
arr[i4] = 1;
boolean falg2 = false;
for (int i = 0; i < 4; i++) {
if (arr[i] == -1) {
falg2 = true;
break;
}
}
if (falg2 == true) {
continue;
}
System.out.print("A:");
System.out.println(options[i1]);
System.out.print("B:");
System.out.println(options[i2]);
System.out.print("C:");
System.out.println(options[i3]);
System.out.print("D:");
System.out.println(options[i4]);
System.out.println("请输入答案A-D");
String aws = scanner.next();
if (aws.toUpperCase().equals("A")) {
if (options[i1].equals(rightAnswer)) {
System.out.println("恭喜!!");
} else {
System.out.println("sorry!");
}
}
if (aws.toUpperCase().equals("B")) {
if (options[i2].equals(rightAnswer)) {
System.out.println("恭喜!!");
} else {
System.out.println("sorry!");
}
}
if (aws.toUpperCase().equals("C")) {
if (options[i3].equals(rightAnswer)) {
System.out.println("恭喜!!");
} else {
System.out.println("sorry!");
}
}
if (aws.toUpperCase().equals("D")) {
if (options[i4].equals(rightAnswer)) {
System.out.println("恭喜!!");
} else {
System.out.println("sorry!");
}
}
break;
}
}
}
- 唐诗缺字游戏
- 唐诗词组频率,高频字居然跟宋词相似
- 孟郊--唐诗
- 唐诗收藏
- 唐诗平仄
- 唐诗故事
- 唐诗生成器
- 唐诗、OO、范式、C++
- 唐诗名句集锦
- 唐诗一首
- 唐诗《春江花月夜》赏析
- 唐诗几种
- 综合练习:唐诗排列
- 综合练习:唐诗排列
- 跟我背唐诗
- 重温唐诗二首
- 读唐诗,学唐史-《六神磊磊读唐诗》读书小结
- 经典唐诗配画欣赏
- AWK 笔记
- 指针
- 跪求内存卡恢复软件
- LinkedIn公司实现的实时搜索引擎Zoie
- FTP软件vsftpd
- 唐诗缺字游戏
- ARM中的big-endian和little-endian
- C# 把数据写入Excel
- 图像扫描控件ScanOnWeb使用在jboss中问题一例
- VC实现对话框窗口任意分割
- static unsigned short g_httpOP='OP' 驱动里面的用法
- PCI IDSEL
- Linux线程同步
- JS的IE和Firefox兼容性汇总