zoukankan      html  css  js  c++  java
  • “单词竞猜游戏之管理员端”补充版

    1、管理员端实现

              1.1、默认初始化,创建文件夹和文本文档数据库

              1.2、支持自动更新和手动更新

    2、管理员端主函数

    using System;
    using System.Collections.Generic;
    using System.Linq;
    using System.Text;
    using System.IO;
    
    namespace WordsPlayAdmin
    {
        class Program
        {
            static void Main(string[] args)
            {    
                Console.WriteLine("
    ---------  欢迎管理员登陆  -----------
    ");
                int sOrW;
                int grade;
                string isAnto;
    
                //是否全部初始化
                Console.WriteLine("是否全部初始化<y> OR <n>?");
                string isAllInit = Console.ReadLine();
                if ("y" == isAllInit)
                {
                    //创建一个文件夹e:1111139
                    Directory.CreateDirectory(@"e:1111139"); 
    
                    TextOperateClass.InitAchievement();
                    for (int k = 1; k <=3; k++)
                        TextOperateClass.InitText(true, k);
                }            
    
                for (int i = 0; i < 3; i++)//3次输入机会
                {
                    Console.Write("请输入管理员账号:");
                    string adminName = Console.ReadLine();
    
                    Console.Write("请输入密码:");
                    string adminPwd = Console.ReadLine();
    
                    //判断权限
                    if ("admin".Equals(adminName) && "123".Equals(adminPwd))
                    {
                        Console.WriteLine("登陆成功");
                        break;
                    }
                    else
                        Console.WriteLine("对不起,你的输入有误,还有{0}次机会",2-i);
                    if (i==2)
                    {
                        Console.Write("你已经3次输入错误,请按任意键结束程序");
                        return;
                    }
                }
    
                while (true)
    
                {
                    Console.WriteLine("	1.初始化的得分数据库
    	2.更新词汇数据库");
                    sOrW = int.Parse(Console.ReadLine());
    
                    //判断是不是更新得分
                    if (sOrW == 1)
                        TextOperateClass.InitAchievement();
                    else
                    {
                        //更新词汇库
                        Console.WriteLine("	1.高级词汇
    	2.中级词汇
    	3.初级词汇");
                        while (true)
                        {
                            try
                            {
                                //防止输入不能转换成整型的字符,会出现异常
                                grade = int.Parse(Console.ReadLine());
                                break;
                            }
                            catch
                            {
                                Console.WriteLine("请重新输入:");
                                Console.WriteLine("	1.高级词汇
    	2.中级词汇
    	3.初级词汇");
                            }
                        }
                       
                        Console.WriteLine("自动更新<y> OR <n>?");
                        isAnto = Console.ReadLine();
                        if (isAnto == "y")
                            TextOperateClass.InitText(true, grade);
                        else
                            TextOperateClass.InitText(false, grade);
                    }
    
                    Console.WriteLine("是否继续更新其他<y> OR <n>");
                    
                    string isUpdate=Console.ReadLine();
                    if ("y" != isUpdate)
                        break;
                }
                Console.Write("BYE,任意键结束程序");
                Console.ReadLine();
            }
        }
    }
    

    3、管理员端文本操作类

    using System;
    using System.Collections.Generic;
    using System.Linq;
    using System.Text;
    using System.IO;
    using System.Collections;
    
    namespace WordsPlayAdmin
    {
        class TextOperateClass
        {
            //初始化得分和成绩
            public static void InitAchievement()
            {
                string[] maxScoreArr = { "高级#0#zxy", "中级#0#zxy", "初级#0#zxy" };
                string[] wordsHeroArr = {"高级#zxy#0#0", "中级#zxy#0#0", "初级#zxy#0#0" };
                ArrayList maxScore = new ArrayList(maxScoreArr);
                ArrayList wordsHero = new ArrayList(wordsHeroArr);
    
                init(0,"maxScore.txt",maxScore);
                init(0,"WordsHero.txt", wordsHero);
            }
            //初始化词汇
            public static void InitText(bool isAnto,int grade)
            {
                string isContinue;  //判断输入单词是否结束
                if (isAnto == true)
                {
                    //词汇表初始化
                    string[] highLevelWordArr ={"confront","front","prototype","prince","confuse","refuse","diffuse","fume","grateful",
                                              "connection","first","scientific","second","save","dessert","observe","surgeon","soul",
                                              "destruction","destroy","up","prior","council","infrared","touch","temper","thermal",
                                              "time","group","tissue","genetic","paddy","destination","debate","appeal","exasperate","noisome"};
                    string[] middleLevelWordArr ={"accord","action","answer","apparent","abstract","blue","blouse","block","bachelor","baby",
                                                "battery","breakfast","cartoon","carry","caution","certainty","check","cheat","conform",
                                                "development","datail","dream","deal","dedicate","deform","duck","elevate","emission",
                                                "enrich","expire","extra","fair","fake","fact","fill","fighter","foul","fit","fowl",
                                                "float","germ","gesture","global","hard","hamonious","induce","indoor","like"};
                    string[] lowLevelWordArr = {"relative","last","cost","cousin","double","couple","cup","cross","course","credit","criticism",
                                               "day","down","diary","industy","deaf","number","deaf","data","generous","grade","degree",
                                               "paint","old","class","eight","room","egg","bike","cake","bird","person","cup","computer",
                                               "mouse","clock","box","sister","boat","hill","tree","right","friend","much","brother","here",
                                               "thank","sorry","home","father","nice","fine"};
    
                    //方便下面函数调用,动态数组适合管理员输入,随机增长
                    ArrayList highLevelWordArrList = new ArrayList(highLevelWordArr);
                    ArrayList middleLevelWordArrList = new ArrayList(middleLevelWordArr);
                    ArrayList lowLevelWordArrList = new ArrayList(lowLevelWordArr);
    
                    if (grade == 1) //自动更新高级词汇
                        init(1, "HighLevelWord.txt", highLevelWordArrList);
                    else if(grade==2)
                        init(1, "MiddleLevelWord.txt", middleLevelWordArrList);
                    else
                        init(1, "LowLevelWord.txt", lowLevelWordArrList);
                }
                
                else if(grade==1)
                { 
                    //手动输入更新高级词汇
                    ArrayList highLevelWordArrList = new ArrayList();
                    Console.WriteLine("请一个一个输入要存储的单词,结束请输<y>");
    
                    while(true)
                    {
                        isContinue=Console.ReadLine();
                        if ("y" == isContinue || "Y" == isContinue)
                        {
                            break;
                        }
                        else
                            highLevelWordArrList.Add(isContinue);
                    }
    
                    init(1, "HighLevelWord.txt", highLevelWordArrList);
                }
    
                else if (grade == 2)
                {
                    //手动输入跟新中级词汇
                    ArrayList middleLevelWordArrList = new ArrayList();
                    Console.WriteLine("请一个一个输入要存储的单词,结束请输<y>");
                    
                    while (true)
                    {
                        isContinue = Console.ReadLine();
                        if ("y" == isContinue || "Y" == isContinue)
                        {
                            break;
                        }
                        else
                            middleLevelWordArrList.Add(isContinue);
                    }
    
                    init(1, "MiddleLevelWord.txt", middleLevelWordArrList);
                    
                }
    
                else if (grade == 3)
                {
                    //手动输入更新低级词汇
                    ArrayList lowLevelWordArrList = new ArrayList();
                    Console.WriteLine("请一个一个输入要存储的单词,结束请输<y>");
    
                    while (true)
                    {
                        isContinue = Console.ReadLine();
                        if ("y" == isContinue || "Y" == isContinue)
                        {
                            break;
                        }
                        else
                            lowLevelWordArrList.Add(isContinue);
                    }
    
                    init(1, "LowLevelWord.txt", lowLevelWordArrList);
                }   
            }
    
            //将动态数组送的词汇写到文本文档
            private static int init(int WorS,string path,ArrayList strArr)
            {
                string highPath=@"e:1111139"+path;
                FileStream fsw = new FileStream(@highPath, FileMode.Create, FileAccess.Write);
                StreamWriter sw = new StreamWriter(fsw, System.Text.Encoding.Default);
    
                if (WorS == 1)
                {
                    foreach (string item in strArr)
                    {
                        sw.Write(item + " ");
                    }
                }
                else
                {
                    foreach (string item in strArr)
                    {
                        sw.WriteLine(item + " ");
                    }
                }
               
    
                sw.Close();
                fsw.Close();
    
                return 1;
            }      
    
        }
    }
    


    4、文件夹、文本文档程序自动创建,不需自己手动,位置:E:1111139**.txt

    这样,整个“单词竞猜”游戏就相对完成了,大家只要将其在visual studio2010 中编译就能运行了。

    如果大家想把程序发布成可安装文件,可以参考:VS2010打包操作-博客园

    如有转载请请务必保留此出处:http://www.cnblogs.com/xiangyangzhu/
  • 相关阅读:
    Spring IOC实现原理,源码深度剖析!
    MYSQL配置参数优化详解
    MYSQL 索引优化全攻略
    MySQL性能优化实战
    最强MySQL MVCC实现原理
    redis集群代建
    redis分布式锁
    mysql 的语句的执行顺序
    Rockey pushConsumer 和 pullConsumer 的区别
    RockeyMQ消息处理
  • 原文地址:https://www.cnblogs.com/xiangyangzhu/p/4239808.html
Copyright © 2011-2022 走看看