コード例 #1
0
        private void btnOpenFile_Click(object sender, EventArgs e)
        {
            try
            {
                OpenFileDialog openDialog = new OpenFileDialog();
                DialogResult   result     = openDialog.ShowDialog();
                if (result == DialogResult.OK)
                {
                    this.Text = "SE2GameForm " + openDialog.SafeFileName;

                    Type          moveLogic = null;
                    AI.IMoveLogic selected  = cmbAI.SelectedItem as AI.IMoveLogic;
                    if (selected != null)
                    {
                        moveLogic = selected.GetType();
                    }

                    World.Instance.Create(picGameWorld.ClientSize,
                                          Convert.ToInt32(nudEnemyCount.Value),
                                          moveLogic,
                                          true,
                                          openDialog.FileName);
                }
            }
            catch (InvalidMapException IME)
            {
                IME.GetType();
                MessageBox.Show(IME.Message, "Error Invalid Map", MessageBoxButtons.OK, MessageBoxIcon.Error);
            }
            finally
            {
                picGameWorld.Refresh();
            }
        }
コード例 #2
0
        private void CreateWorld(bool createNewMap)
        {
            try
            {
                // Variable to hold the type of AI to use
                Type moveLogic = null;

                // Variable to hold the selected item in the combobox. Note that,
                // as the selected item is cast to IMoveLogic, it might fail as the
                // combobox also contains a string. As the only string in the
                // combobox indicates a random AI, we can use that fact to differ
                // between a specific or any AI.
                AI.IMoveLogic selected = cmbAI.SelectedItem as AI.IMoveLogic;

                // Check if the cast succeeded
                if (selected != null)
                {
                    // If so, get the type of the selected movelogic
                    moveLogic = selected.GetType();
                }

                World.Instance.Create(picGameWorld.ClientSize,
                                      Convert.ToInt32(nudEnemyCount.Value),
                                      moveLogic,
                                      createNewMap,
                                      null);
            }
            catch (InvalidMapException IME)
            {
                IME.GetType();
                MessageBox.Show(IME.Message, "Error Invalid Map", MessageBoxButtons.OK, MessageBoxIcon.Error);
            }
            finally
            {
                picGameWorld.Refresh();
            }
        }