예제 #1
0
        private void menuFichierScores_Click(object sender, EventArgs e)
        {
            if (!tmrAvancer.Enabled)
            {
                frmScores frmScore = new frmScores();

                frmScore.Text = "Tableaux des scores";
                frmScore.SetPnlNewScoreVisible(false);

                frmScore.ShowDialog();
            }
            else
            {
                MessageBox.Show("Veuillez attendre que le personnage ai fini de se déplacer");
            }
        }
예제 #2
0
        private void tmrAvancer_Tick(object sender, EventArgs e)
        {
            bool arrive = false;

            if (instruction.Count != 0)
            {
                string instrucAcruelle = instruction.ElementAt(compteur).ToString();
                bool   collision       = false;

                if (instrucAcruelle == "Avancer")
                {
                    p.Avancer();

                    foreach (Bloc b in labyrinthe)
                    {
                        //si il n'y a pas deja eu une collision, analise chaque bloc pour voir si on collisionne (empeche le clignottement)
                        if (!collision)
                        {
                            if (new PointF(p.Position.X - 5, p.Position.Y - 5) == b.Position)
                            {
                                string arriveePrecedente = lblArrivee.Text;
                                if (!(b is BlocInvisible))
                                {
                                    collision = true;
                                }

                                if (b.Position == modele.Position)
                                {
                                    tmrAvancer.Enabled = false;
                                    swTempsEcoule.Stop();

                                    MessageBox.Show("Bravo tu as réussi! Tu est beau.");

                                    frmScores frmScore = new frmScores();
                                    frmScore.Text = "Bravo vous avez gagné!";
                                    frmScore.SetPnlNewScoreVisible(true);
                                    frmScore.SetSortieDemande(arriveDemande);
                                    frmScore.SetDifficulte(lblDifficulteTaille.Text);
                                    frmScore.SetTempsEcoule(swTempsEcoule.ElapsedMilliseconds);

                                    frmScore.ShowDialog();

                                    btnReset_Click(sender, e);
                                    lbxInstruction.Enabled = true;
                                    inPlay = false;
                                    arrive = true;

                                    while (lblArrivee.Text == arriveePrecedente)
                                    {
                                        nouvelleArrivee();
                                    }
                                    break;
                                }
                            }
                            else
                            {
                                collision = false;
                            }
                        }
                    }

                    if (collision && !arrive)
                    {
                        switch (p.Orientation)
                        {
                        case "gauche":
                            p.Orientation = "droite";
                            p.Avancer();
                            p.Orientation = "gauche";
                            break;

                        case "droite":
                            p.Orientation = "gauche";
                            p.Avancer();
                            p.Orientation = "droite";
                            break;

                        case "bas":
                            p.Orientation = "haut";
                            p.Avancer();
                            p.Orientation = "bas";
                            break;

                        case "haut":
                            p.Orientation = "bas";
                            p.Avancer();
                            p.Orientation = "haut";
                            break;
                        }
                        tmrAvancer.Enabled = false;

                        DialogResult dr = MessageBox.Show("Réessayer ?", "Vous avez perdu", MessageBoxButtons.YesNo);
                        inPlay = false;

                        if (dr == DialogResult.Yes)
                        {
                            btnReset_Click(sender, e);
                            lbxInstruction.Enabled = true;
                        }
                        else
                        {
                            btnPlay.Enabled = false;
                        }
                    }
                }
                else
                {
                    if (instrucAcruelle == "Tourner à droite")
                    {
                        p.PivoterDroite();
                    }
                    else
                    {
                        if (instrucAcruelle == "Tourner à gauche")
                        {
                            p.PivoterGauche();
                        }
                    }
                }

                if (compteur == lbxInstruction.Items.Count - 1)
                {
                    tmrAvancer.Enabled = false;
                }

                if (!arrive)
                {
                    if (tmrAvancer.Enabled)
                    {
                        compteur++;
                    }
                }

                if (lbxInstruction.SelectedIndex < lbxInstruction.Items.Count - 1)
                {
                    lbxInstruction.SelectedIndex += 1;
                }
            }
        }