Exemple #1
0
 private void RefreshLevelList()
 {
     listView1.Items.Clear();
     if (Directory.Exists(Application.StartupPath + "\\levels"))
     {
         DirectoryInfo dirInfo = new DirectoryInfo(Application.StartupPath + "\\levels");
         foreach (FileInfo fInfo in dirInfo.GetFiles())
         {
             if (fInfo.Extension == ".ukd" || fInfo.Extension == ".UKD")
             {
                 ListViewItem lstItem = new ListViewItem(fInfo.Name.Substring(0, fInfo.Name.IndexOf(".ukd", 0, StringComparison.InvariantCultureIgnoreCase)));
                 lstItem.Tag = fInfo.Name;
                 lstItem.SubItems.Add("0");
                 lstItem.SubItems.Add("");
                 lstItem.SubItems.Add("0");
                 listView1.Items.Add(lstItem);
             }
         }
         Records recMan = new Records();
         if (listView1.Items != null)
         {
             if (listView1.Items.Count > 0)
             {
                 foreach (RecordItem recItem in recMan.RecordsLst)
                 {
                     foreach (ListViewItem itm in listView1.Items)
                     {
                         if (itm.SubItems[0].Text == recItem.LvlName)
                         {
                             itm.SubItems[1].Text = recItem.Record.ToString();
                             itm.SubItems[2].Text = recItem.RecordsMan;
                             itm.SubItems[3].Text = recItem.Seconds.ToString();
                         }
                     }
                 }
             }
         }
     }
 }
Exemple #2
0
 private void GameForm_KeyDown(object sender, KeyEventArgs e)
 {
     if (lvl != null)
     {
         if (e.KeyCode == Keys.Left)
         {
             lvl.MoveAction(groupBoxLvl.CreateGraphics(), MoveDirections.Left);
         }
         if (e.KeyCode == Keys.Right)
         {
             lvl.MoveAction(groupBoxLvl.CreateGraphics(), MoveDirections.Rigth);
         }
         if (e.KeyCode == Keys.Up)
         {
             lvl.MoveAction(groupBoxLvl.CreateGraphics(), MoveDirections.Up);
         }
         if (e.KeyCode == Keys.Down)
         {
             lvl.MoveAction(groupBoxLvl.CreateGraphics(), MoveDirections.Down);
         }
         lblMovesCnt.Text = lvl.MovesCnt.ToString();
         if (lvl.Finished)
         {
             if (((Int32.Parse(lblRecord.Text) > lvl.MovesCnt) || Int32.Parse(lblRecord.Text) == 0) || ((Int32.Parse(lblRecord.Text) == lvl.MovesCnt && (Int32.Parse(lblSeconds.Text.Replace("сек.", "")) < Int32.Parse(lblRecordSeconds.Text.Replace("сек.", ""))))))
             {
                 MessageBox.Show("Игра завершена! Поздравляем, Вы установили новый рекорд!", "Поздравляем!", MessageBoxButtons.OK, MessageBoxIcon.Information);
                 Records records = new Records();
                 records.NewRecord(new RecordItem(Path.GetFileNameWithoutExtension(lvlFileName), Environment.UserName, lvl.SecondsCnt, lvl.MovesCnt));
                 Close();
             }
             else
             {
                 MessageBox.Show("Игра завершена!", "Поздравляем!", MessageBoxButtons.OK, MessageBoxIcon.Information);
             }
             Close();
         }
     }
 }