Example #1
0
 private void btn_save_Click(object sender, EventArgs e)
 {
     if (!CheckIfLegalNumberOfElements(2) && !CheckIfLegalNumberOfElements(3))
     {
         SaveMaze();
         ResultMazeDialog result = new ResultMazeDialog(5);
         if (result.ShowDialog() == DialogResult.Cancel)
         {
             this.DialogResult = DialogResult.OK;
         }
     }
     else
     {
         ResultMazeDialog result = new ResultMazeDialog(6);
         result.ShowDialog();
     }
 }
Example #2
0
        private void SetComPort()
        {
            string[] ports = SerialPort.GetPortNames();
            foreach (string port in ports)
            {
                try
                {
                    currentPort = new SerialPort(port, 9600);
                    if (DetectArduino())
                    {
                        lbl_connected.Text      = "Status: Connected";
                        lbl_connected.ForeColor = Purple;
                        if (isAllowed)
                        {
                            btn_solve.Enabled   = true;
                            btn_connect.Enabled = true;
                            btn_retry.Enabled   = true;
                            btn_exit.Enabled    = true;
                        }
                        portFound = true;
                        return;
                    }
                }
                catch
                { }
            }
            lbl_connected.Text      = "Status: Not Connected";
            lbl_connected.ForeColor = Purple;
            this.Enabled            = false;
            ResultMazeDialog result = new ResultMazeDialog(2);

            if (result.ShowDialog() == DialogResult.OK)
            {
                this.Enabled      = true;
                btn_solve.Enabled = true;
                this.Activate();
                SetComPort();
                return;
            }
            this.Enabled = true;
            this.Activate();
            btn_connect.Enabled = true;
            btn_retry.Enabled   = true;
            btn_solve.Enabled   = false;
            btn_exit.Enabled    = true;
        }
Example #3
0
        private void CustomGameCreator_Load(object sender, EventArgs e)
        {
            this.Icon                 = RealLifeScratch.Properties.Resources.BlockyLogo;
            lbl_title.Font            = new Font("Uni Sans Heavy", 10);
            btn_purpleblock.BackColor = Purple;
            btn_blackblock.BackColor  = Black;
            btn_whiteblock.BackColor  = AlmostBlack;

            ResultMazeDialog dialog = new ResultMazeDialog(4);
            var res = dialog.ShowDialog();

            if (res == DialogResult.Yes)
            {
                this.DialogResult = DialogResult.Yes;
            }
            else if (res == DialogResult.Abort)
            {
                this.DialogResult = DialogResult.Abort;
            }
            LoadMaze();
        }
Example #4
0
        private void TrySolution()
        {
            if (isLegalCode())
            {
                if (isInLineWithParameters())
                {
                    Point  goal = GetCoordinatesOfGoal();
                    string a    = "";
                    foreach (var i in listOfLinesFunctions)
                    {
                        a += i.vResistor + " ";
                    }
                    //MessageBox.Show(a);
                    for (int i = 0; i < listOfLinesFunctions.Count; i++)
                    {
                        listOfLinesFunctions[i].FunctionToRun(i);

                        if (!(listOfLinesFunctions[i].vResistor.In(vMoveForward, vTurnLeft, vTurnRight, vBreak)))
                        {
                            if (listOfLinesFunctions[i].vResistor.In(vIfElsePathAhead, vIfElsePathLeft, vIfElsePathRight, vWhileElsePathAhead, vWhileElsePathLeft, vWhileElsePathRight))
                            {
                                i = GetIndexOfEnd(i);
                            }
                            i = GetIndexOfEnd(i);
                        }

                        if (stopExecution)
                        {
                            return;
                        }
                        if (isBreak)
                        {
                            isBreak = false;
                            break;
                        }
                    }

                    if (goal == GetCoordinatesOfPlayer())
                    {
                        btn_next.Enabled = true;
                        ResultMazeDialog dialog = new ResultMazeDialog(0);
                        this.Enabled = false;
                        DialogResult result = dialog.ShowDialog();
                        if (result == DialogResult.Yes)
                        {
                            this.Enabled = true;
                            btn_next.PerformClick();
                        }
                        else if (result == DialogResult.Retry)
                        {
                            returnCode        = 0;
                            this.DialogResult = DialogResult.OK;
                        }
                        else if (result == DialogResult.Cancel)
                        {
                            returnCode        = 21;
                            this.DialogResult = DialogResult.OK;
                        }
                        else
                        {
                            this.Enabled     = true;
                            btn_next.Enabled = true;
                        }
                    }
                    else
                    {
                        ResultMazeDialog dialog = new ResultMazeDialog(1);
                        this.Enabled = false;
                        DialogResult result = dialog.ShowDialog();
                        if (result == DialogResult.Retry)
                        {
                            returnCode        = 0;
                            this.DialogResult = DialogResult.OK;
                        }
                        else if (result == DialogResult.Cancel)
                        {
                            returnCode        = 21;
                            this.DialogResult = DialogResult.OK;
                        }
                        else
                        {
                            dialog.Dispose();
                            this.Enabled = true;
                            this.Focus();
                            this.WindowState = FormWindowState.Normal;
                        }
                        this.Activate();
                    }
                }
                else
                {
                    ResultMazeDialog dialog = new ResultMazeDialog(7);
                    this.Enabled      = false;
                    btn_solve.Enabled = true;
                    dialog.ShowDialog();
                    this.Activate();
                }
            }
            else
            {
                ResultMazeDialog dialog = new ResultMazeDialog(3);
                this.Enabled      = false;
                btn_solve.Enabled = true;
                dialog.ShowDialog();
            }
            btn_connect.Enabled = true;
            this.Enabled        = true;
            isAllowed           = false;
            this.Activate();
        }