FastM1nesweeperForm.cs 4.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172
  1. using FastReport.Utils;
  2. using System;
  3. namespace FastReport.Forms
  4. {
  5. internal partial class FastM1nesweeperForm : BaseDialogForm
  6. {
  7. #region Private Fields
  8. private bool lockUpdate;
  9. private DifPreset[] presets;
  10. #endregion Private Fields
  11. #region Public Properties
  12. public int Bombs
  13. {
  14. get
  15. {
  16. return (int)tbBombs.Value;
  17. }
  18. }
  19. public int Columns
  20. {
  21. get
  22. {
  23. return (int)tbColumns.Value;
  24. }
  25. }
  26. public int Rows
  27. {
  28. get
  29. {
  30. return (int)tbRows.Value;
  31. }
  32. }
  33. #endregion Public Properties
  34. #region Public Constructors
  35. public FastM1nesweeperForm()
  36. {
  37. InitializeComponent();
  38. Localize();
  39. }
  40. #endregion Public Constructors
  41. #region Public Methods
  42. public override void Localize()
  43. {
  44. base.Localize();
  45. MyRes res = new MyRes("Forms,FastM1nesweeper");
  46. Text = res.Get("");
  47. lWelcome.Text = res.Get("Welcome");
  48. gbSettings.Text = res.Get("Settings");
  49. lDifficulty.Text = res.Get("Difficulty");
  50. cbDifficulty.Items.Add(res.Get("Custom"));
  51. cbDifficulty.Items.Add(res.Get("Easy"));
  52. cbDifficulty.Items.Add(res.Get("Medium"));
  53. cbDifficulty.Items.Add(res.Get("Hard"));
  54. cbDifficulty.Items.Add(res.Get("Master"));
  55. for (int i = 1; i <= 13; i++)
  56. {
  57. cbDifficulty.Items.Add("T" + i.ToString());
  58. }
  59. presets = new DifPreset[5 + 13];
  60. presets[0] = new DifPreset(0, 0, 0);
  61. presets[1] = new DifPreset(10, 8, 8);
  62. presets[2] = new DifPreset(20, 12, 12);
  63. presets[3] = new DifPreset(40, 16, 16);
  64. presets[4] = new DifPreset(80, 20, 20);
  65. for (int i = 1; i <= 13; i++)
  66. {
  67. presets[4 + i] = new DifPreset(80 + i * 10, 25, 25);
  68. }
  69. lBombs.Text = res.Get("Bombs");
  70. lColumns.Text = res.Get("Columns");
  71. lRows.Text = res.Get("Rows");
  72. cbDifficulty.SelectedIndex = 2;
  73. }
  74. #endregion Public Methods
  75. #region Private Methods
  76. private void cbDifficulty_SelectedIndexChanged(object sender, EventArgs e)
  77. {
  78. if (lockUpdate)
  79. return;
  80. try
  81. {
  82. lockUpdate = true;
  83. if (cbDifficulty.SelectedIndex > 0)
  84. {
  85. int i = cbDifficulty.SelectedIndex;
  86. tbBombs.Value = presets[i].bombs;
  87. tbColumns.Value = presets[i].columns;
  88. tbRows.Value = presets[i].rows;
  89. }
  90. }
  91. finally
  92. {
  93. lockUpdate = false;
  94. }
  95. }
  96. private void Settings_ValueChanged(object sender, EventArgs e)
  97. {
  98. if (lockUpdate)
  99. return;
  100. try
  101. {
  102. lockUpdate = true;
  103. for (int i = 0; i < presets.Length; i++)
  104. {
  105. if (presets[i].bombs == tbBombs.Value && presets[i].columns == tbColumns.Value && presets[i].rows == tbRows.Value)
  106. {
  107. cbDifficulty.SelectedIndex = i;
  108. return;
  109. }
  110. }
  111. cbDifficulty.SelectedIndex = 0;
  112. }
  113. finally
  114. {
  115. lockUpdate = false;
  116. }
  117. }
  118. #endregion Private Methods
  119. #region Private Structs
  120. private struct DifPreset
  121. {
  122. #region Public Fields
  123. public int bombs;
  124. public int columns;
  125. public int rows;
  126. #endregion Public Fields
  127. #region Public Constructors
  128. public DifPreset(int bombs, int rows, int columns)
  129. {
  130. this.bombs = bombs;
  131. this.rows = rows;
  132. this.columns = columns;
  133. }
  134. #endregion Public Constructors
  135. }
  136. #endregion Private Structs
  137. }
  138. }