计算机辅助教学软件开发:教学生英语`
题目要求:屏幕.上随机出现一个汉语单词,英语单词,汉语词组,英语词组或- -短句提示学生给出相应答案,答错了要//提示要求重新输入,直到答对为止。要统计给分,且累计,够- -定分数后可进级,即从单词到词组,从词组到短句,里面有三关,单词关,词组关,短语关
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Data;
using System.Data.SqlClient;
using System.Collections;
namespace 背单词
{
class Program
{
static void Main(string[] args)
{
string strSql_1 = "select 中文,英文 from 单词";
string strSql_2 = "select 中文,英文 from 词组";
string strSql_3 = "select 中文,英文 from 短语";
Hashtable words = Connection(strSql_1);
int score = 0;
int flage = 0;
pass_1(strSql_1, score, strSql_2, strSql_3, flage);
Console.ReadKey();
}
//连接数据库得到所需数据
public static Hashtable Connection(string strSql)
{
string ConnStr = "Data Source=.;Initial Catalog=单词库;Integrated Security=SSPI";
SqlConnection conn = new SqlConnection(ConnStr);
conn.Open();
Hashtable words = new Hashtable();
//这里用hashtable是因为hsahtable里出来的值是随机的
SqlCommand cmd = new SqlCommand(strSql, conn);
SqlDataReader sdr = cmd.ExecuteReader();
//定义俩个list用来装从数据库读出来的英文和中文
List<string> chinese = new List<string>();
List<string> english = new List<string>();
while (sdr.Read())
{
chinese.Add(sdr["中文"].ToString());
english.Add(sdr["英文"].ToString());
}
for (int i = 0; i < chinese.Count; ++i)
{
words.Add(english[i], chinese[i]);
}
//把俩个list里的值放到hashtable里
sdr.Close();
conn.Close();
return words;
}
//判断答案是否正确,计算得分并返回
public static void Judge(out int score, Hashtable words, out int flage)
{
score = 0;
flage = 0;
string choose=null;
//需要返回多个值用out,用一个标志来标记是否是中途想要退出程序,是就直接加一个if判断退出
foreach (DictionaryEntry item in words)
{
Console.WriteLine(item.Key);
Console.WriteLine("请输入与之对应的中文:");
string chinAnswer = Console.ReadLine();
if (chinAnswer == item.Value.ToString())
{
score++;
Console.WriteLine("回答正确,总分:{0}", score);
Console.WriteLine("请选择是否继续答题:按任意键继续 no退出");
choose = Console.ReadLine();
if (choose == "no")
{
Console.WriteLine("你最终的得分是{0}分", score);
flage = 1;
return;
//退出循环,退出程序
}
}
else
{
int count = 1;//判断答题的次数
while (true)
{
Console.WriteLine("答错了,请重新输入与之对应的中文:");
chinAnswer = Console.ReadLine();
count++;
if (count > 3)
{
Console.WriteLine("你答错的次数超过了三次,不能再继续了!程序将会退出!你将重新进入开始答题。");
flage = 1;
return;
}
if (chinAnswer == item.Value.ToString())
{
score++;
Console.WriteLine("回答正确,总分:{0}", score);
Console.WriteLine("请选择是否继续答题:按任意键继续 no退出");
choose = Console.ReadLine();
if (choose == "no"/*||score == words.Count*/)
{
Console.WriteLine("你最终的得分是{0}分", score);
flage = 1;
return;
}
}
}
}
}
}
//第一关,我这一关有五题,答对3题就可以通关,每题有三次机会答错就要重新开始
public static void pass_1(string strSql_1, int score, string strSql_2, string strSql_3, int flage)
{
Hashtable words = Connection(strSql_1);
Judge(out score, words, out flage);
if (flage == 1)
{
return;
//退出程序(退出此函数即可)
}
if (score >= 3)
{
Console.WriteLine("恭喜你进入下一关!");
Console.Clear();//清屏
score = 0;
pass_2(strSql_2, score, strSql_3, flage);
}
//进入下一关
else
{
Console.WriteLine("很遗憾你没有过关,需要重新开始!");
Console.Clear();//清屏
score = 0;
pass_1(strSql_1, score, strSql_2, strSql_3, flage);
}
//重新开始
}
public static void pass_2(string strSql_2, int score, string strSql_3, int flage)
{
Hashtable words = Connection(strSql_2);
Judge(out score, words, out flage);
if (flage == 1)
{
return;
//退出程序(退出此函数即可)
}
if (score >= 3)
{
Console.WriteLine("恭喜你进入下一关!");
Console.Clear();//清屏
score = 0;
pass_3(strSql_3, score, flage);
}
//进入下一关
else
{
Console.WriteLine("很遗憾你没有过关,需要重新开始!");
Console.Clear();//清屏
score = 0;
pass_2(strSql_2, score, strSql_3, flage);
}
//重新开始
}
public static void pass_3(string strSql_3, int score, int flage)
{
Hashtable words = Connection(strSql_3);
Judge(out score, words, out flage);
if (flage == 1)
{
return;
//退出程序(退出此函数即可)
}
if (score >= 3)
{
Console.WriteLine("最强王者诞生!");
}
//进入下一关
else
{
Console.WriteLine("很遗憾你没有过关,需要重新开始!");
Console.Clear();//清屏
score = 0;
pass_3(strSql_3, score, flage);
}
//重新开始
}
}
}