Exemple #1
0
        public Renderer(Jogador jogador, TabForm tabForm)
        {
            this.mJogador    = jogador;
            this.tabForm     = tabForm;
            tabForm.Renderer = this;

            tabForm.ClientSize = new Size(xspan * jogador.Largura, yspan * jogador.Altura);

            Cavalinho = ResizeBitmap(Properties.Resources._40px_Chess_ndt45_svg, xspan, yspan);
            Render(tabForm.CreateGraphics());
        }
Exemple #2
0
        private void abrirToolStripButton1_Click(object sender, EventArgs e)
        {
            Jogador currentJogador = jog;

            bool enabled = timer1.Enabled;

            if (enabled)
            {
                timer1.Stop();
            }

            OpenFileDialog openDIalog = new OpenFileDialog();

            openDIalog.Filter          = "Knight Simulator File (*.knight)|*.knight";
            openDIalog.CheckPathExists = true;
            openDIalog.CheckFileExists = true;
            openDIalog.Title           = "Choose a file with a simulation to load";

            if (openDIalog.ShowDialog() == DialogResult.OK)
            {
                try
                {
                    BinaryFormatter bf = new BinaryFormatter();
                    using (Stream input = File.OpenRead(openDIalog.FileName))
                    {
                        jog = (Jogador)bf.Deserialize(input);
                    }
                }
                catch (Exception ex)
                {
                    MessageBox.Show("Unable to read the simulation file\r\n"
                                    + ex.Message, "Knight Simulator Error", MessageBoxButtons.OK,
                                    MessageBoxIcon.Error);
                    jog = currentJogador;
                }
            }
            if (mStatus == MyStatusForm.Completado_Parado_Cancelado)
            {
                tabForm = new TabForm();
                render  = new Renderer(jog, tabForm);
                tabForm.Show(this);
            }
            else
            {
                render.mJogador = jog;
                render.ResizeTabuleiro(jog.Largura, jog.Altura);
            }
            jog.StObserver       = iStateMessage;
            jog.MovementObserver = iMoveMessage;

            jog.Start();

            if (enabled)
            {
                mStatus = MyStatusForm.PasseioInterativo;
            }
            else
            {
                mStatus = MyStatusForm.Pausado;
            }


            txLargura.Text             = jog.Largura.ToString();
            txAltura.Text              = jog.Altura.ToString();
            txPosX.Text                = jog.posInicial.X.ToString();
            txPosY.Text                = jog.posInicial.Y.ToString();
            ckTodasSolucoes.ThreeState = jog.TotalSolution;

            MoveChildForms();
            UpdateForm();

            if (enabled)
            {
                timer1.Start();
            }
        }
Exemple #3
0
        private void lbStart_Click(object sender, EventArgs e)
        {
            if (mStatus == MyStatusForm.Completado_Parado_Cancelado)
            {
                int larg, alt, px, py;

                int tempInt;
                if (int.TryParse(txLargura.Text, out tempInt))
                {
                    larg = tempInt;
                }
                else
                {
                    throw new ArgumentNullException();
                }

                if (int.TryParse(txAltura.Text, out tempInt))
                {
                    alt = tempInt;
                }
                else
                {
                    throw new ArgumentNullException();
                }

                if (int.TryParse(txPosX.Text, out tempInt))
                {
                    px = tempInt;
                }
                else
                {
                    throw new ArgumentNullException();
                }

                if (int.TryParse(txPosY.Text, out tempInt))
                {
                    py = tempInt;
                }
                else
                {
                    throw new ArgumentNullException();
                }

                if ((px >= alt) || (py >= larg))
                {
                    MessageBox.Show("Posição Inicial fora do Tabuleiro", "Erro Knight Rider",
                                    MessageBoxButtons.OK,
                                    MessageBoxIcon.Error);
                    return;
                }

                jog = InitializeJogador();

                tabForm = new TabForm();
                render  = new Renderer(jog, tabForm);
                tabForm.Show(this);


                jog.Start();
                timer1.Start();

                mStatus = MyStatusForm.PasseioInterativo;
                MoveChildForms();
                UpdateForm();
            }
            else
            {
                if (mStatus == MyStatusForm.PasseioInterativo)
                {
                    timer1.Stop();
                    mStatus = MyStatusForm.Pausado;
                }
                else
                {
                    timer1.Start();
                    mStatus = MyStatusForm.PasseioInterativo;
                }
            }
            UpdateForm();
        }