1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105
   | using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Text;
using System.Windows.Forms;
 
namespace Proj_jungle
{
    public partial class frmJungle : Form
    {//objet de la classe Graphics, permettant de dessiner la jungle
        jungle laJungle;
        Graphics objGraphics;
        public frmJungle()
        {
            InitializeComponent();
            objGraphics = picbJungle.CreateGraphics();
            pnAjoutCarni.Enabled = false;
            pnAjoutHerbivore.Enabled = false;
 
        }
 
        private void btnOk_Click(object sender, EventArgs e)
        {
            if (txtPays.Text != "")
            {//instanciation et initialisation de l'objet jungle
                //laJungle = new jungle(txtPays.Text);
                laJungle = new jungle();
                laJungle.init(txtPays.Text);
 
                pnJungle.Enabled = false;
                pnAjoutCarni.Enabled = true;
                pnAjoutHerbivore.Enabled = true;
 
            }
 
        }
        private void btnajoutcarni_Click(object sender, EventArgs e)
        {
 
            animal animal1;
            carnivore carni1 = new carnivore();
            if (txtajoutespececarni.Text != "" && txtAjoutNomCarni.Text != "")
            {//instanciation et initialisation de l'objet animal
                //animal1 = new animal(txtNom.Text, txtEspece.Text);
                animal1 = new animal();
                //animal1.init(txtNom.Text, txtEspece.Text);
                carni1.init(txtAjoutNomCarni.Text, txtajoutespececarni.Text, 10);
                //carni1.affiche();
                animal1 = carni1;
                animal1.affiche();
 
                txtajoutespececarni.Text = "";
                txtAjoutNomCarni.Text = "";
                txtAjoutNomCarni.Focus();
                laJungle.ajouterAnimal(carni1);
            }
        }
 
 
 
        private void btnGo_Click(object sender, EventArgs e)
        {
            pnAjoutCarni.Enabled = false;
            pnAjoutHerbivore.Enabled = false;
 
            laJungle.dessiner(objGraphics);
            //afficher les infos des animaux
            laJungle.affiche();
            timer1.Start();
        }
 
        private void timer1_Tick(object sender, EventArgs e)
        {// à chaque exécution de cette procédure, on fait évoluer les animaux (ils vieillissent)
            laJungle.evoluer();
            laJungle.affiche();
            laJungle.dessiner(objGraphics);
 
        }
 
        private void btnAjoutHerbi_Click(object sender, EventArgs e)
        {
            animal animal1;
            herbivore carni1 = new herbivore();
            if (txtajoutespeherbi.Text != "" && txtajoutnomherbi.Text != "")
            {//instanciation et initialisation de l'objet animal
                //animal1 = new animal(txtNom.Text, txtEspece.Text);
                animal1 = new animal();
                //animal1.init(txtNom.Text, txtEspece.Text);
                carni1.init(txtajoutnomherbi.Text, txtajoutespeherbi.Text, 10);
                //carni1.affiche();
                animal1 = carni1;
                animal1.affiche();
 
                txtajoutespeherbi.Text = "";
                txtajoutnomherbi.Text = "";
                txtajoutnomherbi.Focus();
                laJungle.ajouterAnimal(carni1);
            }
 
        }
 
        }
    } | 
Partager