C#简单宠物商店登录管理系统

/// <summary>
/// 创建宠物代码
/// </summary>
using System;

using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using System.IO;
using System.Text;

namespace 创建宠物_20180809__1
{
class Program
{
static void Main(string[] args)
{
int a = 2;
int num = 5;
switch (a)
{
case 2:num+=5;break;

            default:
                Console.WriteLine("");
                break;
        }
        Console.WriteLine(num);

        //CreatePet();
        Console.ReadKey();
    }

    public static void CreatePet()
    {
        string[] str1 = File.ReadAllLines(@"C:\Users\a\Desktop\ZSQ\PetSystem\message.txt");
        //姓名:{1}  年龄:{2}岁  性别:{3}  体重:{4}kg  身高:{5}cm   品种:{6}  价格:{7}金"
        for (int i = 0; true; i++)
        {
            Console.WriteLine("第{0}只宠物", i + 1);
            for (int k = 0; k < 7; k++)
            {
                Console.WriteLine("请输入第{0}个", k + 1);
                string str = Console.ReadLine();
                if (i == 0 && k == 0&&str1.Length==0)
                {
                    File.AppendAllText(@"C:\Users\a\Desktop\ZSQ\PetSystem\dog.txt", str);//在原有文本文件上添加
                }
                else
                {
                    File.AppendAllText(@"C:\Users\a\Desktop\ZSQ\PetSystem\dog.txt","\n"+ str);//在原有文本文件上添加
                }
            }

            Console.WriteLine("输入“tx”退出创建宠物");
            string str2 = Console.ReadLine();
            if (str2 == "tx")
            {
                break;
            }
        }


    }



}

}

/// <summary>
/// 宠物商店管理系统代码
/// </summary>
using System;

using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using System.IO;
using System.Text;

namespace 宠物管理系统__20180809
{
class Program
{
static void Main(string[] args)
{
Inter();
Console.ReadKey();
}
#region 登录
//界面
public static void Inter()
{
Console.WriteLine(“***********************”);
Console.WriteLine(“* 欢迎来到本系统 *”);
Console.WriteLine(“* 请选择操作 *”);
Console.WriteLine(“* 1.登录账户 *”);
Console.WriteLine(“* 2.注册账户 *”);
Console.WriteLine(“* 3.找回密码 *”);
Console.WriteLine(“* 4.账户解锁 *”);
Console.WriteLine(“* 5.退出 *”);
Console.WriteLine(“***********************”);
for (int i = 0; true; i++)
{
int n = int.Parse(Console.ReadLine());
switch (n)
{
case 1: Register(); break;
case 2: RegisteredAaccount(); break;
case 3: ForgotPassword(); break;
case 4: Unlock(); break;
case 5: Quit(); break;
default:
Console.WriteLine(“输入错误”);
break;
}
}

    }

    //登录后选择
    public static void RegisterInter(string account)
    {
        Console.WriteLine("*********************************");
        Console.WriteLine("*          请选择操作           *");
        Console.WriteLine("*          1.修改密码           *");
        Console.WriteLine("*          2.宠物商店           *");
        Console.WriteLine("*          3.返回登录           *");
        Console.WriteLine("*          4.注销账户           *");
        Console.WriteLine("*          5.退出               *");
        Console.WriteLine("*********************************");
        int n = int.Parse(Console.ReadLine());
        switch (n)
        {
            case 1: changePassword(account); break;
            case 2: InterPet(account); break;
            case 3: Register(); break;
            case 4: cancelUser(account); break;
            case 5: Quit(); break;
            default:
                Console.WriteLine("输入错误");
                break;
        }
    }


    //修改密码后选择
    public static void changePasswordInter()
    {
        Console.WriteLine("*********************************");
        Console.WriteLine("*         修改密码成功           *");
        Console.WriteLine("*          请选择操作           *");
        Console.WriteLine("*          1.返回界面           *");
        Console.WriteLine("*          2.重新登录           *");
        Console.WriteLine("*          3.退出               *");
        Console.WriteLine("*********************************");
        for (int i = 0; true; i++)
        {
            int n = int.Parse(Console.ReadLine());
            switch (n)
            {
                case 1: Inter(); break;
                case 2: Register(); break;
                case 3: Quit(); break;
                default:
                    Console.WriteLine("输入错误,请重新输入");
                    break;
            }
        }

    }


    //登录失败
    public static void LogonFailed()
    {
        Console.WriteLine("*********************************");
        Console.WriteLine("*          请选择操作           *");
        Console.WriteLine("*          1.重新登录           *");
        Console.WriteLine("*          2.注册账户           *");
        Console.WriteLine("*          3.找回密码           *");
        Console.WriteLine("*          4.退出               *");
        Console.WriteLine("*********************************");
        for (int i = 0; i < 3; i++)
        {
            int n = int.Parse(Console.ReadLine());
            switch (n)
            {
                case 1: Register(); break;
                case 2: RegisteredAaccount(); break;
                case 3: ForgotPassword(); break;
                case 4: Quit(); break;
                default:
                    Console.WriteLine("输入错误,请重新输入");
                    break;
            }
            if (2 - i == 0)
            {
                Quit();
            }
            Console.WriteLine("您还有{0}次机会", 2 - i);
        }

    }

    //登录
    public static void Register()
    {
        string[] str = File.ReadAllLines(@"C:\Users\a\Desktop\ZSQ\PetSystem\message.txt");
        Console.WriteLine("请输入账号");
        string account = Console.ReadLine();
        for (int i = 1; i < str.Length; i += 5)
        {

            if (account == str[i - 1])
            {
                if (Convert.ToBoolean(str[i + 3]))
                {
                    Console.WriteLine("请输入密码");
                    for (int j = 0; j < 3; j++)
                    {
                        string password = Console.ReadLine();

                        if (password == str[i])
                        {
                            Console.WriteLine("登录成功");
                            RegisterInter(account);
                        }
                        else
                        {
                            if (2 - j == 0)
                            {
                                str[i + 3] = "false";
                                for (int m = 0; m < str.Length; m++)
                                {
                                    if (m == 0)
                                    {
                                        File.WriteAllText(@"C:\Users\a\Desktop\ZSQ\PetSystem\message.txt", str[m]);//在原有文本文件替换
                                    }
                                    else
                                    {
                                        File.AppendAllText(@"C:\Users\a\Desktop\ZSQ\PetSystem\message.txt", "\n" + str[m]);//在原有文本文件上替换
                                    }
                                }
                                Console.WriteLine("该账号已被锁定");
                                Inter();
                                break;
                            }
                            Console.WriteLine("密码错误,请重新输入,还有{0}次机会", 2 - j);
                        }
                    }

                }
                else
                {
                    Console.WriteLine("改该账号已经被锁定");
                    Inter();
                    break;

                }

            }
            if (i >= str.Length - 2)
            {
                Console.WriteLine("登录失败");
                LogonFailed();

            }

        }

    }

    //注册账户
    public static void RegisteredAaccount()
    {
        string[] str = File.ReadAllLines(@"C:\Users\a\Desktop\ZSQ\PetSystem\message.txt");
        string account;
        for (int n = 0; true; n++)
        {
            bool bo = false;
            Console.WriteLine("请输入账号");
            account = Console.ReadLine();
            if (str.Length == 0)
            {
                File.AppendAllText(@"C:\Users\a\Desktop\ZSQ\PetSystem\message.txt", account);//在原有文本文件上添加
                bo = true;
            }
            else
            {
                for (int i = 0; i < str.Length; i += 5)
                {
                    if (account == str[i])
                    {
                        Console.WriteLine("该账号已经被注册,请重新输入");
                        break;
                    }
                    if (i == str.Length - 5)
                    {
                        File.AppendAllText(@"C:\Users\a\Desktop\ZSQ\PetSystem\message.txt", "\n" + account);//在原有文本文件上添加
                        bo = true;
                        break;
                    }
                }

            }

            if (bo == true)
            {
                break;
            }
        }


        for (int i = 0; i < 3; i++)
        {
            Console.WriteLine("请输入密码");
            string password = Console.ReadLine();
            Console.WriteLine("请再确认密码");
            string password1 = Console.ReadLine();
            if (password == password1)
            {
                File.AppendAllText(@"C:\Users\a\Desktop\ZSQ\PetSystem\message.txt", "\n" + password);//在原有文本文件上添加
                break;
            }
            else
            {
                if (2 - i == 0)
                {
                    Inter();
                    break;
                }
                Console.WriteLine("请重新输入密码,还有{0}次机会", 2 - i);
            }

        }
        Console.WriteLine("请选择密保问题");
        encrypted();
        Console.WriteLine("请输入密保答案");
        string result = Console.ReadLine();
        File.AppendAllText(@"C:\Users\a\Desktop\ZSQ\PetSystem\message.txt", "\n" + result);//在原有文本文件上添加
        File.AppendAllText(@"C:\Users\a\Desktop\ZSQ\PetSystem\message.txt", "\n" + "true");//在原有文本文件上添加

        for (int i = 0; true; i++)
        {
            Console.WriteLine("请输入验证码");
            int authCodes = authCode();
            Console.WriteLine(authCodes);
            int auth = int.Parse(Console.ReadLine());
            if (auth == authCodes)
            {
                File.WriteAllText(@"C:\Users\a\Desktop\ZSQ\PetSystem\" + account + ".txt", "暂无");//1.如果没有文件,就会自动创建,并且只能写文本文件 2.如果有文件,将文本中文本信息替换了
                File.AppendAllText(@"C:\Users\a\Desktop\ZSQ\PetSystem\" + account + ".txt", "\n" + "0");//在原有文本文件上添加
                Console.WriteLine("注册成功!");
                Inter();
                break;

            }
            else
            {
                if (i == 2)
                {
                    Console.WriteLine("注册失败");
                    RegisteredAaccount();
                    break;
                }
                Console.WriteLine("请重新输入验证码");

            }
        }



    }

    //修改密码
    public static void changePassword(string account)
    {
        string[] str = File.ReadAllLines(@"C:\Users\a\Desktop\ZSQ\PetSystem\message.txt");
        for (int i = 0; i < str.Length; i+=5)
        {
            if (str[i]==account)
            {
                for (int k = 0; k < 3; k++)
                {
                    Console.WriteLine("请输入新密码");
                    string password = Console.ReadLine();
                    Console.WriteLine("请再次确认密码");
                    string password1 = Console.ReadLine();
                    if (password == password1)
                    {
                        str[i + 1] = password;
                        for (int m = 0; m < str.Length; m++)
                        {
                            if (m == 0)
                            {
                                File.WriteAllText(@"C:\Users\a\Desktop\ZSQ\PetSystem\message.txt", str[m]);//在原有文本文件替换
                            }
                            else
                            {
                                File.AppendAllText(@"C:\Users\a\Desktop\ZSQ\PetSystem\message.txt", "\n" + str[m]);//在原有文本文件上替换
                            }
                        }
                        changePasswordInter();
                        break;
                    }
                    else if (2-k==0)
                    {
                        Console.WriteLine("错误次数超过三次,自动退出,返回主界面");
                        Inter();
                    }
                    else
                    {
                        Console.WriteLine("输入错误,请重新输入,还有{0}次机会",2-k);
                    }
                }                   
            }

        }

    }

    //注销账户
    public static void cancelUser(string account)
    {
        Console.WriteLine("再次确认是否注销账户,注销后用户剩余金币不予退回!\n  请输入“是”或者“否”,输入“否”或者其他字符将会跳转到主界面");
        string affirm = Console.ReadLine();
        if (affirm=="是")
        {
            string[] str = File.ReadAllLines(@"C:\Users\a\Desktop\ZSQ\PetSystem\message.txt");
            for (int i = 0; i < str.Length; i += 5)
            {
                if (str[i] == account)
                {
                    for (int m = 0; m < i; m++)
                    {
                        if (m == 0)
                        {
                            File.WriteAllText(@"C:\Users\a\Desktop\ZSQ\PetSystem\message.txt", str[m]);//在原有文本文件替换
                        }
                        else
                        {
                            File.AppendAllText(@"C:\Users\a\Desktop\ZSQ\PetSystem\message.txt", "\n" + str[m]);//在原有文本文件上添加
                        }
                    }
                    for (int m = i + 5; m < str.Length; m++)
                    {
                        File.AppendAllText(@"C:\Users\a\Desktop\ZSQ\PetSystem\message.txt", "\n" + str[m]);//在原有文本文件上添加
                    }

                    string[] accountStr = File.ReadAllLines(@"C:\Users\a\Desktop\ZSQ\PetSystem\" + account + ".txt");//获取用户对应的宠物背包背包
                    float surplusMoney = float.Parse( accountStr[1]);
                    File.Delete(@"C:\Users\a\Desktop\ZSQ\PetSystem\" + account + ".txt");//删除用户宠物背包文件

                    Console.WriteLine("注销成功,用户宠物背包剩余{0}金,将不予退回!",surplusMoney);
                    Console.WriteLine("欢迎再次使用!");
                    Inter();

                }


            }
        }
        else
        {
            Console.WriteLine("自动跳转到主界面");
            Inter();
        }
    }

    //找回密码
    public static void ForgotPassword()
    {
        string[] str = File.ReadAllLines(@"C:\Users\a\Desktop\ZSQ\PetSystem\message.txt");
        Console.WriteLine("请输入账号");
        string account = Console.ReadLine();
        for (int i = 0; i < str.Length; i += 5)
        {
            if (str[i] == account)
            {
                for (int j = 0; j < 3; j++)
                {
                    Console.WriteLine("请输入密保问题:{0}", str[i + 2]);
                    string passWorldStr = Console.ReadLine();
                    if (str[i + 3] == passWorldStr)
                    {
                        for (int k = 0; k < 3; k++)
                        {
                            Console.WriteLine("请输入新密码");
                            string password = Console.ReadLine();
                            Console.WriteLine("请再次确认新密码");
                            string password1 = Console.ReadLine();
                            if (password == password1)
                            {
                                Console.WriteLine("请输入验证码");
                                int authCodes = authCode();
                                Console.WriteLine(authCodes);
                                int auth = int.Parse(Console.ReadLine());
                                if (auth == authCodes)
                                {
                                    str[i + 1] = password;
                                    for (int m = 0; m < str.Length; m++)
                                    {
                                        if (m == 0)
                                        {
                                            File.WriteAllText(@"C:\Users\a\Desktop\ZSQ\PetSystem\message.txt", str[m]);//在原有文本文件替换
                                        }
                                        else
                                        {
                                            File.AppendAllText(@"C:\Users\a\Desktop\ZSQ\PetSystem\message.txt", "\n" + str[m]);//在原有文本文件上替换
                                        }
                                    }
                                    //File.AppendAllText(@"C:\Users\a\Desktop\ZSQ\message.txt", "\n" + str[i]);//在原有文本文件上添加
                                    //File.AppendAllText(@"C:\Users\a\Desktop\ZSQ\message.txt", "\n" + password);//在原有文本文件上添加
                                    Console.WriteLine("找回成功!");
                                    Inter();
                                }
                                else
                                {
                                    Console.WriteLine("找回密码失败");
                                    RegisteredAaccount();
                                }
                            }
                        }
                    }
                    else
                    {
                        if (2 - j == 0)
                        {
                            Quit();
                        }
                        Console.WriteLine("输入错误,还有{0}次机会", 2 - j);

                    }
                }

            }
        }
    }

    //解锁
    public static void Unlock()
    {
        string[] str = File.ReadAllLines(@"C:\Users\a\Desktop\ZSQ\PetSystem\message.txt");
        Console.WriteLine("请输入锁定账号");
        int num = 0;
        string account = Console.ReadLine();
        for (int i = 0; i < str.Length; i += 5)
        {
            if (str[i] == account)
            {
                if (Convert.ToBoolean(str[i + 4]) == false)
                {
                    Console.WriteLine("请输入密保答案:{0}", str[i + 2]);
                    string result = Console.ReadLine();
                    if (str[i + 3] == result)
                    {
                        str[i + 4] = "true";
                        for (int m = 0; m < str.Length; m++)
                        {
                            if (m == 0)
                            {
                                File.WriteAllText(@"C:\Users\a\Desktop\ZSQ\PetSystem\message.txt", str[m]);//在原有文本文件替换
                            }
                            else
                            {
                                File.AppendAllText(@"C:\Users\a\Desktop\ZSQ\PetSystem\message.txt", "\n" + str[m]);//在原有文本文件上替换
                            }

                        }
                        Console.WriteLine("解锁成功");
                        Inter();
                    }
                }
                else
                {
                    Console.WriteLine("该账号未锁定,自动返回登录界面");
                    Inter();
                }
            }
            if (num == 2)
            {
                Console.WriteLine("输入错误次数超过三次,自返回主界面");
                Inter();
            }
            if (i == str.Length - 5)
            {
                Console.WriteLine("输入账号有误,请重新输入");
                num++;
            }


        }

    }

    //退出
    public static void Quit()
    {
        Console.WriteLine("退出成功");
        Console.ReadKey();
    }

    //验证码
    public static int authCode()
    {
        Random rand1 = new Random();
        int a = rand1.Next(1000, 9000);
        return a;
    }

    //密保问题
    public static void encrypted()
    {
        Console.WriteLine("*********************************");
        Console.WriteLine("*        请选择密保问题         *");
        Console.WriteLine("*         1.最崇拜的人          *");
        Console.WriteLine("*         2.最喜欢数字          *");
        Console.WriteLine("*         3.女友姓名            *");
        Console.WriteLine("*         4.退出                *");
        Console.WriteLine("*********************************");
        int n = int.Parse(Console.ReadLine());
        switch (n)
        {
            case 1: File.AppendAllText(@"C:\Users\a\Desktop\ZSQ\PetSystem\message.txt", "\n" + "最崇拜的人"); break;//在原有文本文件上添加
            case 2: File.AppendAllText(@"C:\Users\a\Desktop\ZSQ\PetSystem\message.txt", "\n" + "最喜欢数字"); break;//在原有文本文件上添加
            case 3: File.AppendAllText(@"C:\Users\a\Desktop\ZSQ\PetSystem\message.txt", "\n" + "女友姓名"); break;//在原有文本文件上添加
            default:
                Quit();
                break;

        }
    }


    #endregion

    //////////////////////////////////////////////////////////////////////////////

    //界面
    public static void InterPet(string account)
    {

        Console.WriteLine("**********************");
        Console.WriteLine("*  欢迎来到宠物商店  *");
        Console.WriteLine("*     请选择操作     *");
        Console.WriteLine("*     1.宠物列表     *");
        Console.WriteLine("*     2.购买宠物     *");
        Console.WriteLine("*     3.玩家背包     *");
        Console.WriteLine("*     4.删除宠物     *");
        Console.WriteLine("*     5.主界面       *");
        Console.WriteLine("*     6.返回登录     *");
        Console.WriteLine("*     7.充值中心     *");
        Console.WriteLine("*     8.退出         *");
        Console.WriteLine("**********************");
        for (int i = 0; true; i++)
        {
            int n = int.Parse(Console.ReadLine());
            switch (n)
            {
                case 1: dogInter(account); ; break;
                case 2: changeDogPet(account); break;
                case 3: accounterPacksack(account); ; break;
                case 4: deleteDogPet(account); ; break;
                case 5: Inter(); ; break;
                case 6: Register(); ; break;
                case 7: rechargeInter(account); ; break;
                case 8: Quit(); ; break;
                default:
                    Console.WriteLine("输入错误,请重新输入 ");
                    break;
            }
        }

    }

    //看完宠物之后选择
    public static void dogInterLast(string account)
    {
        Console.WriteLine("**********************");
        Console.WriteLine("*     请选择操作     *");
        Console.WriteLine("*     1.商店界面     *");
        Console.WriteLine("*     2.购买宠物     *");
        Console.WriteLine("*     3.主界面       *");
        Console.WriteLine("*     4.返回登录     *");
        Console.WriteLine("*     5.退出         *");
        Console.WriteLine("**********************");
        for (int i = 0; true; i++)
        {
            int n = int.Parse(Console.ReadLine());
            switch (n)
            {
                case 1: InterPet(account); ; break;
                case 2: changeDogPet(account); break;
                case 5: Inter(); ; break;
                case 6: Register(); ; break;
                case 7: Quit(); ; break;
                default:
                    Console.WriteLine("输入错误,请重新输入 ");
                    break;
            }
        }
    }

    //狗狗宠物列表
    public static void dogInter(string account)
    {
        int num = 0;
        string[] str = File.ReadAllLines(@"C:\Users\a\Desktop\ZSQ\PetSystem\dog.txt");//每行读取
        Console.WriteLine("狗狗宠物目录如下:");
        for (int i = 0; i < str.Length; i+=7)
        {
            num++;
            Console.WriteLine("{0}.  姓名:{1}  年龄:{2}岁  性别:{3}  体重:{4}kg  身高:{5}cm   品种:{6}  价格:{7}金",num,str[i], str[i+1], str[i+2], str[i+3], str[i+4], str[i+5],str[i+6]);
        }

        dogInterLast(account);//跳转选择界面
    }

    //购买狗狗宠物,并且加入到背包
    public static void changeDogPet(string account)
    {

        string[] str = File.ReadAllLines(@"C:\Users\a\Desktop\ZSQ\PetSystem\dog.txt");//每行读取狗狗列表
        Console.WriteLine("*请输入序号*");
        int n = int.Parse(Console.ReadLine());
        int num=n-1;

        for (int i = 0; i <7; i++)
        {
            File.AppendAllText(@"C:\Users\a\Desktop\ZSQ\PetSystem\" + account + ".txt", "\n" + str[num * 7+i]);//在原有文本文件上添加
        }

        string[] accountStr = File.ReadAllLines(@"C:\Users\a\Desktop\ZSQ\PetSystem\" + account + ".txt");//每行读取背包
        accountStr[1] = (float.Parse( accountStr[1])- float.Parse( str[num * 7 + 6])).ToString();

        for (int m = 0; m < accountStr.Length; m++)
        {
            if (m == 0)
            {

                File.WriteAllText(@"C:\Users\a\Desktop\ZSQ\PetSystem\" + account + ".txt", accountStr[m]);//在原有文本文件替换
            }
            else
            {
                File.AppendAllText(@"C:\Users\a\Desktop\ZSQ\PetSystem\" + account + ".txt", "\n" + accountStr[m]);//在原有文本文件上替换
            }
        }

        Console.WriteLine("购买成功");
        InterPet(account);

    }

    //观看背包列表
    public static void accounterPacksack(string account)
    {
        string[] accountStr = File.ReadAllLines(@"C:\Users\a\Desktop\ZSQ\PetSystem\" + account + ".txt");//每行读取背包
        Console.WriteLine("用户名称:{0}\n 用户等级:{1}\n用户金额:{2} ",account,accountStr[0],accountStr[1]);
        Console.WriteLine("宠物信息:");
        for (int i = 2; i < accountStr.Length; i++)
        {
            Console.WriteLine(accountStr[i]);
            if ((i-1)%7==0)
            {
                Console.WriteLine("-------------------");
            }
        }
        InterPet(account);
    }

    //删除宠物
    public static void deleteDogPet(string account)
    {
        string[] accountStr = File.ReadAllLines(@"C:\Users\a\Desktop\ZSQ\PetSystem\" + account + ".txt");//每行读取背包
        Console.WriteLine("宠物信息:");
        for (int i = 2; i < accountStr.Length; i++)
        {
            Console.WriteLine(accountStr[i]);
            if ((i - 1) % 7 == 0)
            {
                Console.WriteLine("-------------------");
            }
        }
        Console.WriteLine("卖掉宠物将会以原来价格六折折现");
        Console.WriteLine("请输入宠物姓名:");
        for (int k = 0; k < 3; k++)
        {
            string name = Console.ReadLine();
            for (int i = 2; i < accountStr.Length; i += 7)
            {
                if (accountStr[i] == name)
                {
                    Console.WriteLine("再次确认是否卖掉,请输入“是”或者“否”");
                    string notarize = Console.ReadLine();
                    if (notarize == "是")
                    {
                        accountStr[1] = (float.Parse(accountStr[1]) + (0.6 * float.Parse(accountStr[i + 6]))).ToString();
                        for (int m = 0; m < i; m++)
                        {
                            if (m == 0)
                            {

                                File.WriteAllText(@"C:\Users\a\Desktop\ZSQ\PetSystem\" + account + ".txt", accountStr[m]);//在原有文本文件替换
                            }
                            else
                            {
                                File.AppendAllText(@"C:\Users\a\Desktop\ZSQ\PetSystem\" + account + ".txt", "\n" + accountStr[m]);//在原有文本文件上替换
                            }
                        }
                        for (int m = i + 7; m < accountStr.Length; m++)
                        {
                            File.AppendAllText(@"C:\Users\a\Desktop\ZSQ\PetSystem\" + account + ".txt", "\n" + accountStr[m]);//在原有文本文件上替换
                        }
                        Console.WriteLine("删除成功");

                        InterPet(account);
                        break;
                    }
                    else
                    {
                        Console.WriteLine("返回宠物界面");
                        InterPet(account);
                        break;
                    }
                }
            }
            if (2-k==0)
            {
                Console.WriteLine("输入次数超过三次,自动退出");
                InterPet(account);
                break;
            }
            Console.WriteLine("还有{}次机会,请重新输入宠物名字:",2-k);

        }




    }

    //充值界面
    public static void rechargeInter(string account)
    {

        string[] accountStr = File.ReadAllLines(@"C:\Users\a\Desktop\ZSQ\PetSystem\" + account + ".txt");//每行读取背包
        Console.WriteLine("**********************");
        Console.WriteLine("*   请选择充值金额   *");
        Console.WriteLine("*    1.10元1000金    *");
        Console.WriteLine("*    2.30元5000金    *");
        Console.WriteLine("*    3.50元12000金   *");
        Console.WriteLine("*    4.100元30000金  *");
        Console.WriteLine("*    5.宠物商店界面  *");
        Console.WriteLine("**********************");

            int n = int.Parse(Console.ReadLine());
            float num = 0;
            switch (n)
            {
                case 1: num = 1000; break;
                case 2: num = 5000; break;
                case 3: num = 12000; break;
                case 4: num = 30000; break;
                case 5: InterPet(account); break;
                default:
                    Console.WriteLine("输入错误,请重新输入,返回宠物商店界面");
                InterPet(account);
                break;
            }
            float money = float.Parse(accountStr[1]) + num;

            if (money>=5000&&money<150000)
            {
                accountStr[0]= "VIP黑铁";//替换等级
            }
            else if (money>=15000&&money<50000)
            {
             accountStr[0]= "VIP青铜";//替换等级
            }
            else if (money >= 50000 && money <100000)
            {
               accountStr[0]= "VIP白银";//替换等级
            }
            else if (money>=100000)
            {
            accountStr[0] = "VIP黄金";//替换等级
             }
            else
            {
            accountStr[0] = "暂无";//替换等级
             }


            accountStr[1]= money.ToString();//增加金钱

        for (int m = 0; m < accountStr.Length; m++)
        {
            if (m == 0)
            {
                File.WriteAllText(@"C:\Users\a\Desktop\ZSQ\PetSystem\" + account + ".txt", accountStr[m]);//在原有文本文件替换
            }
            else
            {
                File.AppendAllText(@"C:\Users\a\Desktop\ZSQ\PetSystem\" + account + ".txt", "\n" + accountStr[m]);//在原有文本文件上替换
            }
        }
        Console.WriteLine("充值成功,自动返回 宠物商店界面");
            InterPet( account);
        }



}

}

/// <summary>
/// 创建伪数据库过程
/// </summary>

第一步在桌面创建[

第二步

第三部

//备注:创建名称要和图片上名称一致,否则出现报错

猜你喜欢

转载自blog.csdn.net/qq_42016542/article/details/81558340