public prompt(Form A,User user)
 {
     InitializeComponent();
     Atimer.Tick += Atimer_Tick;
     Atimer.Interval = 25;
     Aform = A;
     Auser = user;
 }
 public welcome(User A)
     : this()
 {
     Auser = A;
     Atimer.Tick += Atimer_Tick;
     Atimer.Interval = 25;
     this.userName.Text = Auser.Username;
 }
 public learn(User A,Hanzi H)
 {
     Auser = A;
     Ahanzi = H;
     InitializeComponent();
     Atimer.Tick += Atimer_Tick;
     Atimer.Interval = 25;
     Ale = this;
     this.hanziPictureBox1.Hanzi = Ahanzi;
     hanziPictureBox1.CorrectDrew += new BihuaHandler(OnCorrectDrew);
     hanziPictureBox1.WrongDrew += new BihuaHandler(OnWrongDrew);
     hanziPictureBox1.Completed += new BihuaHandler(OnCompleted);
     this.paraphrase.Text = Ahanzi.Info;
     this.infoLabel.Text = "已成功载入汉字 " + "'" + Ahanzi.Zi + "'";
 }
        public achievement(User A)
        {
            InitializeComponent();
            Atimer.Tick += Atimer_Tick;
            Atimer.Interval = 25;
            Auser = A;
            this.nameOfAch.Text = Auser.Username;

            if (Auser.LearnLog.Count == 0) label1.Visible = true;
            else label1.Visible = false;

            int tmp = Auser.LearnLog.Count;
            if ((tmp - 4 >= 0) && Auser.LearnLog.Keys.ElementAt(tmp - 4) != null)
            {
                pictureBox1.Image = new Bitmap(
                    Auser.LearnLog[Auser.LearnLog.Keys.ElementAt(tmp-4)].ImageList[0],
                    new Size(pictureBox1.Width, pictureBox1.Height));
            }
            if ((tmp - 3 >= 0) && Auser.LearnLog.Keys.ElementAt(tmp - 3) != null)
            {
                pictureBox2.Image = new Bitmap(
                    Auser.LearnLog[Auser.LearnLog.Keys.ElementAt(tmp - 3)].ImageList[0],
                    new Size(pictureBox2.Width, pictureBox2.Height));
            }
            if ((tmp - 2 >= 0) && Auser.LearnLog.Keys.ElementAt(tmp - 2) != null)
            {
                pictureBox3.Image = new Bitmap(
                    Auser.LearnLog[Auser.LearnLog.Keys.ElementAt(tmp - 2)].ImageList[0],
                    new Size(pictureBox3.Width, pictureBox3.Height));
            }
            if ((tmp - 1 >= 0) && Auser.LearnLog.Keys.ElementAt(tmp - 1) != null)
            {
                pictureBox4.Image = new Bitmap(
                    Auser.LearnLog[Auser.LearnLog.Keys.ElementAt(tmp - 1)].ImageList[0],
                    new Size(pictureBox4.Width, pictureBox4.Height));
            }

            foreach (AchievementElement achE in Auser.Achievement.ArcList)
            {
                arcListBox.Items.Add(achE.ArcInfo);
            }

            maxLevel.Text = Auser.MaxReachedLevel.ToString();
        }
        public challenge( User user )
        {
            InitializeComponent();
            this.user = user;
            this.cha = new Challenge(user);

            Atimer.Tick += Atimer_Tick;
            Atimer.Interval = 25;

            Hanzi Ahanzi = HanziIO.Read("中");
            hanziPictureBox1.Hanzi = Ahanzi;
            hanziPictureBox1.Completed += cha.OnFinishHanzi;
            hanziPictureBox1.Enabled = false;

            cha.FinishLevel += OnFinishLevel;
            cha.FinishLevel += user.Achievement.OnFinishLevel;
            cha.Lose += OnLose;

            next.Visible = true;
            next.Enabled = true;
            timer1.Interval = 25;
            timeMaxLength = resttime.Width;
            resttime.BackColor = Color.Cyan;
        }
 public Achievement(User user)
 {
     user.FinishHanzi += OnFinishHanzi;
     arcList = new List<AchievementElement>();
 }
        private void dlu_Click(object sender, EventArgs e)
        {
            Sound.PlaySE("se_buttonclick");
            try
               {
              Auser=UserManager.Login(this.name.Text,this.passwd.Text);
              Auser.ResetHanziWeekFinished();
              welcome Awelcom = new welcome(Auser);

              this.OnClose(false);
              Auser.FinishHanzi += Auser.Achievement.OnFinishHanzi;
              Auser.Achievement.AchievementReach += OnAchievementReach;

              Awelcom.OnShow();

            }
            catch(UserException a)
            {
                wrong Awrong = new wrong(a.Message);
                Awrong.Shown += new EventHandler(BlockWindow);
                Awrong.FormClosed += new FormClosedEventHandler(UnblockWindow);
                Awrong.OnShow();
            }
        }
 public Challenge( User user )
 {
     this.user = user;
     this.hzlist = HanziIO.ReadAll();
 }
        private void submit_Click(object sender, EventArgs e)
        {
            Sound.PlaySE("se_buttonclick");
            try
            {
                Auser = UserManager.Register(this.Username.Text, this.passwd1.Text);
                this.OnClose(true);
                DL.ADL.OnClose(false);
                Auser.Achievement.AchievementReach += DL.ADL.OnAchievementReach;
                Auser.FinishHanzi += Auser.Achievement.OnFinishHanzi;
                welcome Awelcome = new welcome(Auser);
                Awelcome.OnShow();

            }
            catch (UserException a)
            {
                wrong Wrong = new wrong(a.Message);
                Wrong.OnShow();

            }
        }
        /// <summary>
        /// 以用户名和密码注册一个新的用户
        /// </summary>
        /// <param name="username">用户名</param>
        /// <param name="password">密码</param>
        /// <returns>构建的User对象,若用户名已存在则返回null</returns>
        public static User Register(String username, String password)
        {
            if (!IsExisted(username))
            {
                User user = new User(username, GetMD5(password));
                user.achievement = new Achievement(user);
                SaveFile(user);
                return user;
            }
            else throw new UserException ("用户名已存在");

            /*
            User user = new User(username, GetMD5(password));
            try {
                String filepath = path + "/" + username + ".xml";
                FileStream fs = new FileStream(filepath, FileMode.Open);
                fs.Close();
            }
            catch ( FileNotFoundException )
            {
                SaveFile(user);
                return true;
            }
            return false;
            */
        }
 /// <summary>
 /// 保存用户数据
 /// </summary>
 /// <param name="user">要保存的User对象</param>
 public static void SaveFile(User user)
 {
     if (!Directory.Exists(String.Format(UserDirFormat, user.Username)))
         Directory.CreateDirectory(Path + user.Username);
     String filepath = String.Format(ProfilePathFormat, user.Username);
     FileStream fs = new FileStream(filepath,FileMode.OpenOrCreate);
     BinaryFormatter bp = new BinaryFormatter();
     bp.Serialize(fs, user);
     fs.Close();
 }