diff --git a/EnVoiture/Controlleur/BoiteAOutils.cs b/EnVoiture/Controlleur/BoiteAOutils.cs new file mode 100644 index 0000000..110b5f0 --- /dev/null +++ b/EnVoiture/Controlleur/BoiteAOutils.cs @@ -0,0 +1,62 @@ +using EnVoiture.Modele; +using EnVoiture.Vue; +using System; +using System.Collections.Generic; +using System.Drawing; +using System.Linq; +using System.Text; +using System.Threading.Tasks; +using System.Windows.Forms; + +namespace EnVoiture.Controller +{ + public class BoiteAOutils : UserControl + { + public GenerateurWidget GenerateurWidget { get; private set; } + + public Route RouteSelectionnee + { + get + { + return GenerateurWidget.RouteWidget.Route; + } + } + + /// + /// Constructeur par défaut + /// + public BoiteAOutils() + { + InitializeComponent(); + GenerateurWidget = new GenerateurWidget(new Generateur()); + Paint += new PaintEventHandler((source, e) => { GenerateurWidget.DessinerSurOrigine(e.Graphics); }); + MouseClick += new MouseEventHandler(this.RouteBouton_MouseClick); + //panel.Location = new Point(this.Location.X + this.Size.Width / 2, 0); + } + + private void RouteBouton_MouseClick(object sender, MouseEventArgs e) + { + if (e.Button == MouseButtons.Left) + { + if (GenerateurWidget.Detectcontenu(e.Location)) + { + GenerateurWidget.Generateur.EditionRoute(GenerateurWidget.DetectionOrientation(e.Location)); + } + Invalidate(); + } + } + + private void InitializeComponent() + { + this.SuspendLayout(); + // + // BoiteAOutils + // + this.AutoScroll = true; + this.Name = "BoiteAOutils"; + this.Size = new System.Drawing.Size(311, 194); + this.ResumeLayout(false); + + } + } +} diff --git a/EnVoiture/Controlleur/BoiteAOutils.resx b/EnVoiture/Controlleur/BoiteAOutils.resx new file mode 100644 index 0000000..1af7de1 --- /dev/null +++ b/EnVoiture/Controlleur/BoiteAOutils.resx @@ -0,0 +1,120 @@ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + text/microsoft-resx + + + 2.0 + + + System.Resources.ResXResourceReader, System.Windows.Forms, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089 + + + System.Resources.ResXResourceWriter, System.Windows.Forms, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089 + + \ No newline at end of file diff --git a/EnVoiture/Controlleur/EnVoitureForm.Designer.cs b/EnVoiture/Controlleur/EnVoitureForm.Designer.cs new file mode 100644 index 0000000..53a1b0c --- /dev/null +++ b/EnVoiture/Controlleur/EnVoitureForm.Designer.cs @@ -0,0 +1,107 @@ +namespace EnVoiture.Controller +{ + partial class EnVoitureForm + { + /// + /// Required designer variable. + /// + private System.ComponentModel.IContainer components = null; + + /// + /// Clean up any resources being used. + /// + /// true if managed resources should be disposed; otherwise, false. + protected override void Dispose(bool disposing) + { + if (disposing && (components != null)) + { + components.Dispose(); + } + base.Dispose(disposing); + } + + #region Windows Form Designer generated code + + /// + /// Required method for Designer support - do not modify + /// the contents of this method with the code editor. + /// + private void InitializeComponent() + { + this.components = new System.ComponentModel.Container(); + this.timer = new System.Windows.Forms.Timer(this.components); + this.alignment = new System.Windows.Forms.TableLayoutPanel(); + this.enVoiturePanel = new EnVoiture.Controller.EnVoiturePanel(); + this.toolsBox = new EnVoiture.Controller.BoiteAOutils(); + this.alignment.SuspendLayout(); + this.SuspendLayout(); + // + // timer + // + this.timer.Enabled = true; + this.timer.Interval = 10; + this.timer.Tick += new System.EventHandler(this.timer_Tick); + // + // alignment + // + this.alignment.ColumnCount = 2; + this.alignment.ColumnStyles.Add(new System.Windows.Forms.ColumnStyle()); + this.alignment.ColumnStyles.Add(new System.Windows.Forms.ColumnStyle(System.Windows.Forms.SizeType.Percent, 100F)); + this.alignment.Controls.Add(this.enVoiturePanel, 1, 0); + this.alignment.Controls.Add(this.toolsBox, 0, 0); + this.alignment.Dock = System.Windows.Forms.DockStyle.Fill; + this.alignment.Location = new System.Drawing.Point(0, 0); + this.alignment.Name = "alignment"; + this.alignment.RowCount = 1; + this.alignment.RowStyles.Add(new System.Windows.Forms.RowStyle(System.Windows.Forms.SizeType.Percent, 100F)); + this.alignment.Size = new System.Drawing.Size(762, 537); + this.alignment.TabIndex = 0; + // + // enVoiturePanel + // + this.enVoiturePanel.Dock = System.Windows.Forms.DockStyle.Fill; + this.enVoiturePanel.Location = new System.Drawing.Point(183, 3); + this.enVoiturePanel.Name = "enVoiturePanel"; + this.enVoiturePanel.Size = new System.Drawing.Size(576, 531); + this.enVoiturePanel.TabIndex = 0; + this.enVoiturePanel.BoiteAOutils = null; + this.enVoiturePanel.KeyDown += new System.Windows.Forms.KeyEventHandler(this.EnVoitureForm_KeyDown); + this.enVoiturePanel.KeyUp += new System.Windows.Forms.KeyEventHandler(this.EnVoitureForm_KeyUp); + this.enVoiturePanel.MouseDown += new System.Windows.Forms.MouseEventHandler(this.EnVoitureForm_MouseDown); + // + // toolsBox + // + this.toolsBox.AutoScroll = true; + this.toolsBox.BackColor = System.Drawing.Color.Silver; + this.toolsBox.Location = new System.Drawing.Point(0, 0); + this.toolsBox.Margin = new System.Windows.Forms.Padding(0); + this.toolsBox.Name = "toolsBox"; + this.toolsBox.Size = new System.Drawing.Size(180, 537); + this.toolsBox.TabIndex = 1; + this.toolsBox.Visible = false; + // + // EnVoitureForm + // + this.AutoScaleDimensions = new System.Drawing.SizeF(6F, 13F); + this.AutoScaleMode = System.Windows.Forms.AutoScaleMode.Font; + this.ClientSize = new System.Drawing.Size(762, 537); + this.Controls.Add(this.alignment); + this.Name = "EnVoitureForm"; + this.Text = "En Voiture !"; + this.KeyDown += new System.Windows.Forms.KeyEventHandler(this.EnVoitureForm_KeyDown); + this.KeyUp += new System.Windows.Forms.KeyEventHandler(this.EnVoitureForm_KeyUp); + this.MouseDown += new System.Windows.Forms.MouseEventHandler(this.EnVoitureForm_MouseDown); + this.alignment.ResumeLayout(false); + this.ResumeLayout(false); + + } + + #endregion + + private System.Windows.Forms.Timer timer; + private System.Windows.Forms.TableLayoutPanel alignment; + private EnVoiturePanel enVoiturePanel; + private BoiteAOutils toolsBox; + } +} + diff --git a/EnVoiture/Controlleur/EnVoitureForm.cs b/EnVoiture/Controlleur/EnVoitureForm.cs new file mode 100644 index 0000000..14b591d --- /dev/null +++ b/EnVoiture/Controlleur/EnVoitureForm.cs @@ -0,0 +1,118 @@ +using System; +using System.Collections.Generic; +using System.Drawing; +using System.Drawing.Drawing2D; +using System.Windows.Forms; +using EnVoiture.Modele; +using EnVoiture.Vue; +using Orientation = EnVoiture.Modele.Orientation; + +namespace EnVoiture.Controller +{ + /// + /// Classe principale du projet. + /// + public partial class EnVoitureForm : Form + { + // Liste des elements qui seront affichés + private List _usagers = new List(); + + Voiture voiture; + bool bAvancer = false, bReculer = false, bDroite = false, bGauche = false; + + // Liste des routes + private List _routes = new List(); + + /// + /// Constructeur par défaut. + /// + public EnVoitureForm() + { + InitializeComponent(); + VoitureWidget v = new VoitureWidget(0,0,10,20,80); + this._usagers.Add(v); + this.voiture = v.Voiture; + enVoiturePanel.BoiteAOutils = toolsBox; + } + + /// + /// On crée une route en fonction des cordonnées reçu en paramètre + /// + /// + /// + /// + public Route creationRoute(int x, int y) + { + Route RouteBase = new Route(x, y, 100, 100, new List() { Orientation.NORD }); + return RouteBase; + } + + /// + /// + /// + /// + /// + private void EnVoitureForm_KeyDown(object sender, KeyEventArgs e) + { + if (e.KeyCode == Keys.E && e.Control) + toolsBox.Visible = !toolsBox.Visible; + enVoiturePanel.OnKeyDown(sender, e); + } + /// + /// + /// + /// + /// + private void EnVoitureForm_KeyUp(object sender, KeyEventArgs e) + { + if (e.KeyCode == Keys.Escape) + this.Close(); + enVoiturePanel.OnKeyUp(sender, e); + } + + /// + /// est appelé quand on fait: pEnVoiture.Invalidate(); + /// + /// + /// + private void pEnVoiture_Paint(object sender, PaintEventArgs e) + { + Graphics g = e.Graphics; + + if (toolsBox.Visible) + { + // mode edition + foreach (UsagerWidget usager in _usagers) + { + if (!(usager is VoitureWidget)) + usager.Dessiner(g); + } + } + else + { + foreach (UsagerWidget user in _usagers) + { + user.Dessiner(g); + } + } + } + /// + /// + /// + /// + /// + private void timer_Tick(object sender, System.EventArgs e) + { + enVoiturePanel.Tick(sender, e); + } + /// + /// + /// + /// + /// + private void EnVoitureForm_MouseDown(object sender, MouseEventArgs e) + { + enVoiturePanel.OnMouseDown(sender, e); + } + } +} diff --git a/EnVoiture/Controlleur/EnVoitureForm.resx b/EnVoiture/Controlleur/EnVoitureForm.resx new file mode 100644 index 0000000..e6966ff --- /dev/null +++ b/EnVoiture/Controlleur/EnVoitureForm.resx @@ -0,0 +1,126 @@ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + text/microsoft-resx + + + 2.0 + + + System.Resources.ResXResourceReader, System.Windows.Forms, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089 + + + System.Resources.ResXResourceWriter, System.Windows.Forms, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089 + + + 17, 17 + + + 57 + + \ No newline at end of file diff --git a/EnVoiture/Controlleur/EnVoiturePanel.cs b/EnVoiture/Controlleur/EnVoiturePanel.cs new file mode 100644 index 0000000..ecd54b9 --- /dev/null +++ b/EnVoiture/Controlleur/EnVoiturePanel.cs @@ -0,0 +1,312 @@ +using System; +using System.Collections.Generic; +using System.Drawing; +using System.Drawing.Drawing2D; +using System.Linq; +using System.Text; +using System.Threading.Tasks; +using System.Windows.Forms; +using EnVoiture.Modele; +using EnVoiture.Vue; +using Orientation = EnVoiture.Modele.Orientation; +using Newtonsoft.Json; +using Newtonsoft.Json.Linq; +using System.IO; + +namespace EnVoiture.Controller +{ + public class EnVoiturePanel : UserControl + { + private Voiture voiture; + private List _usagers; + private bool bAvancer = false; + private bool bReculer = false; + private bool bDroite = false; + private bool bGauche = false; + private RouteWidget _prevRouteWidget = new RouteWidget(new Route(0, 0, 1, 1, new List { })); + private float zoomRate = 1f; + savePrefab sauvegarde; + private string RunningPath; + private string resourcePath; + + //Variables de détection de la voiture + private GraphicsPath _graphicsPath; + private Region _region; + + private List Routes; + + public BoiteAOutils BoiteAOutils + { + get; + set; + } + + /// + /// Constructeur par défaut. + /// + public EnVoiturePanel() + { + this.Enabled = true; + + DoubleBuffered = true; + + this._usagers = new List(); + this._usagers.Add(new VoitureWidget(0, 0, 10, 20, 80)); + this._usagers.Add(new VoitureWidget(150, 150, 10, 20, 80)); + this._usagers.Add(new VoitureWidget(240, 240, 10, 20, 80)); + this.voiture = (_usagers[0] as VoitureWidget).Voiture; + BoiteAOutils = new BoiteAOutils(); + this.Routes = new List(); + foreach (Route route in Route.Generer(6,5)) + { + Routes.Add(new RouteWidget(route)); + } + + foreach (Route route in Route.Generer(6,6)) + { + Routes.Add(new RouteWidget(route)); + } + this.Paint += new PaintEventHandler(EnVoiture_Paint); + InitializeComponent(); + + RunningPath = AppDomain.CurrentDomain.BaseDirectory; + resourcePath = string.Format("{0}Resources", Path.GetFullPath(Path.Combine(RunningPath, @"..\..\"))); + } + + /// + /// + /// + /// + /// + public void EnVoiture_Paint(object sender, PaintEventArgs e) + { + Graphics g = e.Graphics; + //RotateTransform tourne tout le panel donc la voiture avec. Il faut tourner uniquement les routes ou le tout et appliquer une rotation inverse à la voiture + //g.RotateTransform(35); + + + //Centrage de la caméra sur la voiture séléctionnée de base + g.TranslateTransform(-voiture.Position.X * this.zoomRate + this.Width / 2, -voiture.Position.Y * this.zoomRate + this.Height / 2); + + //Effectue un zoom par rapport au zoomRate + g.ScaleTransform(this.zoomRate, this.zoomRate); + /*if (bDroite) + { + float angle = (float)this.voiture.Angle + 1; + g.RotateTransform(-angle); + this.voiture.Angle = angle; + + //Console.WriteLine("Droite: "+ (_usagers[0] as VoitureWidget).Voiture.Angle); + }else if (bGauche) + { + float angle = (float)this.voiture.Angle - 1; + g.RotateTransform(-angle); + this.voiture.Angle = angle; + }*/ + + foreach (RouteWidget way in Routes) + { + way.Dessiner(g); + } + if (!BoiteAOutils.Visible) + { + foreach (UsagerWidget user in _usagers) + { + user.Dessiner(g); + } + + } + else + _prevRouteWidget.Dessiner(g, 50, Color.Black); + + //g.DrawRectangle(new Pen(Color.Red), voiture.Position.X, voiture.Position.Y, 10, 10); + } + public void OnKeyDown(object sender, KeyEventArgs e) + { + if (e.KeyCode == Keys.W && bReculer == false || e.KeyCode == Keys.Up && bReculer == false) + { + bAvancer = true; + } + + if (e.KeyCode == Keys.S && bAvancer == false || e.KeyCode == Keys.Down && bAvancer == false) + { + bReculer = true; + } + + if (e.KeyCode == Keys.A && bDroite == false || e.KeyCode == Keys.Left && bDroite == false) + { + bGauche = true; + } + + if (e.KeyCode == Keys.D && bGauche == false || e.KeyCode == Keys.Right && bGauche == false) + { + bDroite = true; + } + //Zoom sur le panel + if(e.KeyCode == Keys.F2) + { + this.zoomRate *= 1.2f; + } + if (e.KeyCode == Keys.F3) + { + this.zoomRate /= 1.2f; + } + + + //Fonction de test de prise de contrôle d'une voiture + if (e.KeyCode == Keys.F1) + { + Random r = new Random(); + this.voiture = (_usagers[r.Next(0, _usagers.Count())] as VoitureWidget).Voiture; + } + + if (e.KeyCode == Keys.F6) + { + this.sauvegarder(); + } + + if (e.KeyCode == Keys.F7) + { + this.restaurer(); + } + + + } + public void OnKeyUp(object sender, KeyEventArgs e) + { + if (e.KeyCode == Keys.W || e.KeyCode == Keys.Up) + { + bAvancer = false; + } + + if (e.KeyCode == Keys.S || e.KeyCode == Keys.Down) + { + bReculer = false; + } + + if (e.KeyCode == Keys.A || e.KeyCode == Keys.Left) + { + bGauche = false; + } + + if (e.KeyCode == Keys.D || e.KeyCode == Keys.Right) + { + bDroite = false; + } + + } + /// + /// + /// + /// + /// + public void Tick(object sender, System.EventArgs e) + { + if (bAvancer) + { + voiture.Accelerer(); + } + else if (bReculer) + { + if(voiture.Vitesse <= 0) + { + voiture.Reculer(); + } + else + { + voiture.Freiner(); + } + } + else if(!bReculer && !bAvancer) + { + voiture.Ralentir(); + } + voiture.Avancer(); + + if (bGauche) + { + voiture.TournerGauche(); + } + + if (bDroite) + { + voiture.TournerDroite(); + } + + if (BoiteAOutils.Visible && _prevRouteWidget != null) + { + Point p = PointToClient(Cursor.Position); + Route r = BoiteAOutils.GenerateurWidget.Generateur.Route; + + _prevRouteWidget.Route = r; + _prevRouteWidget.Route.Position = new Point(p.X / 100, p.Y / 100); + } + Invalidate(); + } + + public void OnMouseDown(object sender, MouseEventArgs e) + { //Besoin de changer le système de séléction d'une voiture + foreach (UsagerWidget roaduser in _usagers) + { + VoitureWidget voitureCourante = roaduser as VoitureWidget; + if (voitureCourante.Voiture.estClique(e.Location)) + voiture = voitureCourante.Voiture; + } + + + // creation de la route si en mode edition + if (BoiteAOutils.Visible) + { + Route w = Route.VersPositionCase(e.X, e.Y, BoiteAOutils.RouteSelectionnee); + if (w != null) + { + List routes = new List(); + foreach (RouteWidget r in Routes) + { + if (r.Route.Position != w.Position) + routes.Add(r); + } + routes.Add(new RouteWidget(w)); + Routes = routes; + } + } + } + + private void InitializeComponent() + { + this.SuspendLayout(); + // + // EnVoiturePanel + // + this.Name = "EnVoiturePanel"; + this.ResumeLayout(false); + } + + private void sauvegarder() + { + this.sauvegarde = new savePrefab(); + sauvegarde.voiture = voiture; + sauvegarde.usagers = _usagers; + sauvegarde.zoomrate = zoomRate; + sauvegarde.routes = Routes; + + using (StreamWriter file = File.CreateText(resourcePath + @"\sauvegarde\save.json")) + { + JsonSerializer serializer = new JsonSerializer(); + //serialize object directly into file stream + serializer.Serialize(file, sauvegarde); + } + } + + private void restaurer() + { + /*using (StreamReader re = new StreamReader(resourcePath + @"\sauvegarde\save.json")) + { + JsonTextReader reader = new JsonTextReader(re); + JsonSerializer se = new JsonSerializer(); + object parsedData = se.Deserialize(reader); + Console.WriteLine(parsedData); + }*/ + } + } +} diff --git a/EnVoiture/Controlleur/EnVoiturePanel.resx b/EnVoiture/Controlleur/EnVoiturePanel.resx new file mode 100644 index 0000000..1af7de1 --- /dev/null +++ b/EnVoiture/Controlleur/EnVoiturePanel.resx @@ -0,0 +1,120 @@ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + text/microsoft-resx + + + 2.0 + + + System.Resources.ResXResourceReader, System.Windows.Forms, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089 + + + System.Resources.ResXResourceWriter, System.Windows.Forms, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089 + + \ No newline at end of file diff --git a/EnVoiture/EnVoiture.csproj b/EnVoiture/EnVoiture.csproj index 1192ba1..cac8c48 100644 --- a/EnVoiture/EnVoiture.csproj +++ b/EnVoiture/EnVoiture.csproj @@ -32,6 +32,9 @@ 4 + + ..\packages\Newtonsoft.Json.11.0.2\lib\net45\Newtonsoft.Json.dll + @@ -45,38 +48,36 @@ - + UserControl - - - + + + + Form - + EnVoitureForm.cs - + UserControl - - + + - - + + - - - - UserControl - - - + + + + EnVoitureForm.cs - + EnVoiturePanel.cs @@ -89,10 +90,11 @@ Resources.resx True - + BoiteAOutils.cs + SettingsSingleFileGenerator Settings.Designer.cs @@ -107,7 +109,16 @@ - + + + + + + + + + + + @@ -68,9 +69,10 @@ - + + @@ -85,9 +87,10 @@ - + + @@ -109,9 +112,22 @@ 2.0 - System.Resources.ResXResourceReader, System.Windows.Forms, Version=2.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089 + System.Resources.ResXResourceReader, System.Windows.Forms, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089 - System.Resources.ResXResourceWriter, System.Windows.Forms, Version=2.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089 + System.Resources.ResXResourceWriter, System.Windows.Forms, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089 + + + ..\Resources\voiture_bleue.png;System.Drawing.Bitmap, System.Drawing, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a + + + ..\Resources\voiture_jaune.png;System.Drawing.Bitmap, System.Drawing, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a + + + ..\Resources\voiture_rouge.png;System.Drawing.Bitmap, System.Drawing, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a + + + ..\Resources\voiture_violette.png;System.Drawing.Bitmap, System.Drawing, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a + \ No newline at end of file diff --git a/EnVoiture/Resources/sauvegarde/save.json b/EnVoiture/Resources/sauvegarde/save.json new file mode 100644 index 0000000..2395e1e --- /dev/null +++ b/EnVoiture/Resources/sauvegarde/save.json @@ -0,0 +1 @@ +{"voiture":{"Vitesse":0.0,"VitesseMax":80.0,"Bornes":{"Location":{"IsEmpty":true,"X":0.0,"Y":0.0},"Size":"10, 20","X":0.0,"Y":0.0,"Width":10.0,"Height":20.0,"Left":0.0,"Top":0.0,"Right":10.0,"Bottom":20.0,"IsEmpty":false},"Position":{"IsEmpty":true,"X":0.0,"Y":0.0},"Taille":"10, 20","Largeur":10.0,"Hauteur":20.0,"Gauche":0.0,"Droite":10.0,"Haut":0.0,"Bas":20.0,"Angle":0.0},"usagers":[{"Voiture":{"Vitesse":0.0,"VitesseMax":80.0,"Bornes":{"Location":{"IsEmpty":true,"X":0.0,"Y":0.0},"Size":"10, 20","X":0.0,"Y":0.0,"Width":10.0,"Height":20.0,"Left":0.0,"Top":0.0,"Right":10.0,"Bottom":20.0,"IsEmpty":false},"Position":{"IsEmpty":true,"X":0.0,"Y":0.0},"Taille":"10, 20","Largeur":10.0,"Hauteur":20.0,"Gauche":0.0,"Droite":10.0,"Haut":0.0,"Bas":20.0,"Angle":0.0}},{"Voiture":{"Vitesse":0.0,"VitesseMax":80.0,"Bornes":{"Location":{"IsEmpty":false,"X":150.0,"Y":150.0},"Size":"10, 20","X":150.0,"Y":150.0,"Width":10.0,"Height":20.0,"Left":150.0,"Top":150.0,"Right":160.0,"Bottom":170.0,"IsEmpty":false},"Position":{"IsEmpty":false,"X":150.0,"Y":150.0},"Taille":"10, 20","Largeur":10.0,"Hauteur":20.0,"Gauche":150.0,"Droite":160.0,"Haut":150.0,"Bas":170.0,"Angle":0.0}},{"Voiture":{"Vitesse":0.0,"VitesseMax":80.0,"Bornes":{"Location":{"IsEmpty":false,"X":240.0,"Y":240.0},"Size":"10, 20","X":240.0,"Y":240.0,"Width":10.0,"Height":20.0,"Left":240.0,"Top":240.0,"Right":250.0,"Bottom":260.0,"IsEmpty":false},"Position":{"IsEmpty":false,"X":240.0,"Y":240.0},"Taille":"10, 20","Largeur":10.0,"Hauteur":20.0,"Gauche":240.0,"Droite":250.0,"Haut":240.0,"Bas":260.0,"Angle":0.0}}],"zoomrate":1.0,"routes":[{"Route":{"Position":"0, 0","Gauche":0,"Haut":0,"Taille":"1, 1","Orientations":null,"DictionnaireObstacles":{"NORD":1,"EST":2,"SUD":2,"OUEST":2}}},{"Route":{"Position":"1, 0","Gauche":1,"Haut":0,"Taille":"1, 1","Orientations":null,"DictionnaireObstacles":{"NORD":2,"EST":0,"SUD":2,"OUEST":2}}},{"Route":{"Position":"2, 0","Gauche":2,"Haut":0,"Taille":"1, 1","Orientations":null,"DictionnaireObstacles":{"NORD":0,"EST":2,"SUD":2,"OUEST":0}}},{"Route":{"Position":"3, 0","Gauche":3,"Haut":0,"Taille":"1, 1","Orientations":null,"DictionnaireObstacles":{"NORD":2,"EST":0,"SUD":2,"OUEST":2}}},{"Route":{"Position":"4, 0","Gauche":4,"Haut":0,"Taille":"1, 1","Orientations":null,"DictionnaireObstacles":{"NORD":0,"EST":1,"SUD":1,"OUEST":0}}},{"Route":{"Position":"5, 0","Gauche":5,"Haut":0,"Taille":"1, 1","Orientations":null,"DictionnaireObstacles":{"NORD":1,"EST":2,"SUD":0,"OUEST":1}}},{"Route":{"Position":"0, 1","Gauche":0,"Haut":1,"Taille":"1, 1","Orientations":null,"DictionnaireObstacles":{"NORD":2,"EST":1,"SUD":0,"OUEST":2}}},{"Route":{"Position":"1, 1","Gauche":1,"Haut":1,"Taille":"1, 1","Orientations":null,"DictionnaireObstacles":{"NORD":2,"EST":2,"SUD":2,"OUEST":1}}},{"Route":{"Position":"2, 1","Gauche":2,"Haut":1,"Taille":"1, 1","Orientations":null,"DictionnaireObstacles":{"NORD":2,"EST":0,"SUD":0,"OUEST":2}}},{"Route":{"Position":"3, 1","Gauche":3,"Haut":1,"Taille":"1, 1","Orientations":null,"DictionnaireObstacles":{"NORD":2,"EST":2,"SUD":2,"OUEST":0}}},{"Route":{"Position":"4, 1","Gauche":4,"Haut":1,"Taille":"1, 1","Orientations":null,"DictionnaireObstacles":{"NORD":1,"EST":0,"SUD":1,"OUEST":2}}},{"Route":{"Position":"5, 1","Gauche":5,"Haut":1,"Taille":"1, 1","Orientations":null,"DictionnaireObstacles":{"NORD":0,"EST":2,"SUD":1,"OUEST":0}}},{"Route":{"Position":"0, 2","Gauche":0,"Haut":2,"Taille":"1, 1","Orientations":null,"DictionnaireObstacles":{"NORD":0,"EST":2,"SUD":1,"OUEST":1}}},{"Route":{"Position":"1, 2","Gauche":1,"Haut":2,"Taille":"1, 1","Orientations":null,"DictionnaireObstacles":{"NORD":2,"EST":2,"SUD":1,"OUEST":2}}},{"Route":{"Position":"2, 2","Gauche":2,"Haut":2,"Taille":"1, 1","Orientations":null,"DictionnaireObstacles":{"NORD":0,"EST":0,"SUD":1,"OUEST":2}}},{"Route":{"Position":"3, 2","Gauche":3,"Haut":2,"Taille":"1, 1","Orientations":null,"DictionnaireObstacles":{"NORD":2,"EST":0,"SUD":2,"OUEST":0}}},{"Route":{"Position":"4, 2","Gauche":4,"Haut":2,"Taille":"1, 1","Orientations":null,"DictionnaireObstacles":{"NORD":1,"EST":2,"SUD":0,"OUEST":0}}},{"Route":{"Position":"5, 2","Gauche":5,"Haut":2,"Taille":"1, 1","Orientations":null,"DictionnaireObstacles":{"NORD":1,"EST":2,"SUD":1,"OUEST":2}}},{"Route":{"Position":"0, 3","Gauche":0,"Haut":3,"Taille":"1, 1","Orientations":null,"DictionnaireObstacles":{"NORD":1,"EST":1,"SUD":0,"OUEST":0}}},{"Route":{"Position":"1, 3","Gauche":1,"Haut":3,"Taille":"1, 1","Orientations":null,"DictionnaireObstacles":{"NORD":1,"EST":1,"SUD":0,"OUEST":1}}},{"Route":{"Position":"2, 3","Gauche":2,"Haut":3,"Taille":"1, 1","Orientations":null,"DictionnaireObstacles":{"NORD":1,"EST":2,"SUD":0,"OUEST":1}}},{"Route":{"Position":"3, 3","Gauche":3,"Haut":3,"Taille":"1, 1","Orientations":null,"DictionnaireObstacles":{"NORD":2,"EST":0,"SUD":2,"OUEST":2}}},{"Route":{"Position":"4, 3","Gauche":4,"Haut":3,"Taille":"1, 1","Orientations":null,"DictionnaireObstacles":{"NORD":0,"EST":1,"SUD":1,"OUEST":0}}},{"Route":{"Position":"5, 3","Gauche":5,"Haut":3,"Taille":"1, 1","Orientations":null,"DictionnaireObstacles":{"NORD":1,"EST":2,"SUD":2,"OUEST":1}}},{"Route":{"Position":"0, 4","Gauche":0,"Haut":4,"Taille":"1, 1","Orientations":null,"DictionnaireObstacles":{"NORD":0,"EST":2,"SUD":2,"OUEST":2}}},{"Route":{"Position":"1, 4","Gauche":1,"Haut":4,"Taille":"1, 1","Orientations":null,"DictionnaireObstacles":{"NORD":0,"EST":2,"SUD":0,"OUEST":2}}},{"Route":{"Position":"2, 4","Gauche":2,"Haut":4,"Taille":"1, 1","Orientations":null,"DictionnaireObstacles":{"NORD":0,"EST":1,"SUD":2,"OUEST":2}}},{"Route":{"Position":"3, 4","Gauche":3,"Haut":4,"Taille":"1, 1","Orientations":null,"DictionnaireObstacles":{"NORD":2,"EST":2,"SUD":2,"OUEST":1}}},{"Route":{"Position":"4, 4","Gauche":4,"Haut":4,"Taille":"1, 1","Orientations":null,"DictionnaireObstacles":{"NORD":1,"EST":2,"SUD":0,"OUEST":2}}},{"Route":{"Position":"5, 4","Gauche":5,"Haut":4,"Taille":"1, 1","Orientations":null,"DictionnaireObstacles":{"NORD":2,"EST":1,"SUD":1,"OUEST":2}}},{"Route":{"Position":"0, 0","Gauche":0,"Haut":0,"Taille":"1, 1","Orientations":null,"DictionnaireObstacles":{"NORD":1,"EST":2,"SUD":2,"OUEST":2}}},{"Route":{"Position":"1, 0","Gauche":1,"Haut":0,"Taille":"1, 1","Orientations":null,"DictionnaireObstacles":{"NORD":2,"EST":0,"SUD":2,"OUEST":2}}},{"Route":{"Position":"2, 0","Gauche":2,"Haut":0,"Taille":"1, 1","Orientations":null,"DictionnaireObstacles":{"NORD":0,"EST":2,"SUD":2,"OUEST":0}}},{"Route":{"Position":"3, 0","Gauche":3,"Haut":0,"Taille":"1, 1","Orientations":null,"DictionnaireObstacles":{"NORD":2,"EST":0,"SUD":2,"OUEST":2}}},{"Route":{"Position":"4, 0","Gauche":4,"Haut":0,"Taille":"1, 1","Orientations":null,"DictionnaireObstacles":{"NORD":0,"EST":1,"SUD":1,"OUEST":0}}},{"Route":{"Position":"5, 0","Gauche":5,"Haut":0,"Taille":"1, 1","Orientations":null,"DictionnaireObstacles":{"NORD":1,"EST":2,"SUD":0,"OUEST":1}}},{"Route":{"Position":"0, 1","Gauche":0,"Haut":1,"Taille":"1, 1","Orientations":null,"DictionnaireObstacles":{"NORD":2,"EST":1,"SUD":0,"OUEST":2}}},{"Route":{"Position":"1, 1","Gauche":1,"Haut":1,"Taille":"1, 1","Orientations":null,"DictionnaireObstacles":{"NORD":2,"EST":2,"SUD":2,"OUEST":1}}},{"Route":{"Position":"2, 1","Gauche":2,"Haut":1,"Taille":"1, 1","Orientations":null,"DictionnaireObstacles":{"NORD":2,"EST":0,"SUD":0,"OUEST":2}}},{"Route":{"Position":"3, 1","Gauche":3,"Haut":1,"Taille":"1, 1","Orientations":null,"DictionnaireObstacles":{"NORD":2,"EST":2,"SUD":2,"OUEST":0}}},{"Route":{"Position":"4, 1","Gauche":4,"Haut":1,"Taille":"1, 1","Orientations":null,"DictionnaireObstacles":{"NORD":1,"EST":0,"SUD":1,"OUEST":2}}},{"Route":{"Position":"5, 1","Gauche":5,"Haut":1,"Taille":"1, 1","Orientations":null,"DictionnaireObstacles":{"NORD":0,"EST":2,"SUD":1,"OUEST":0}}},{"Route":{"Position":"0, 2","Gauche":0,"Haut":2,"Taille":"1, 1","Orientations":null,"DictionnaireObstacles":{"NORD":0,"EST":2,"SUD":1,"OUEST":1}}},{"Route":{"Position":"1, 2","Gauche":1,"Haut":2,"Taille":"1, 1","Orientations":null,"DictionnaireObstacles":{"NORD":2,"EST":2,"SUD":1,"OUEST":2}}},{"Route":{"Position":"2, 2","Gauche":2,"Haut":2,"Taille":"1, 1","Orientations":null,"DictionnaireObstacles":{"NORD":0,"EST":0,"SUD":1,"OUEST":2}}},{"Route":{"Position":"3, 2","Gauche":3,"Haut":2,"Taille":"1, 1","Orientations":null,"DictionnaireObstacles":{"NORD":2,"EST":0,"SUD":2,"OUEST":0}}},{"Route":{"Position":"4, 2","Gauche":4,"Haut":2,"Taille":"1, 1","Orientations":null,"DictionnaireObstacles":{"NORD":1,"EST":2,"SUD":0,"OUEST":0}}},{"Route":{"Position":"5, 2","Gauche":5,"Haut":2,"Taille":"1, 1","Orientations":null,"DictionnaireObstacles":{"NORD":1,"EST":2,"SUD":1,"OUEST":2}}},{"Route":{"Position":"0, 3","Gauche":0,"Haut":3,"Taille":"1, 1","Orientations":null,"DictionnaireObstacles":{"NORD":1,"EST":1,"SUD":0,"OUEST":0}}},{"Route":{"Position":"1, 3","Gauche":1,"Haut":3,"Taille":"1, 1","Orientations":null,"DictionnaireObstacles":{"NORD":1,"EST":1,"SUD":0,"OUEST":1}}},{"Route":{"Position":"2, 3","Gauche":2,"Haut":3,"Taille":"1, 1","Orientations":null,"DictionnaireObstacles":{"NORD":1,"EST":2,"SUD":0,"OUEST":1}}},{"Route":{"Position":"3, 3","Gauche":3,"Haut":3,"Taille":"1, 1","Orientations":null,"DictionnaireObstacles":{"NORD":2,"EST":0,"SUD":2,"OUEST":2}}},{"Route":{"Position":"4, 3","Gauche":4,"Haut":3,"Taille":"1, 1","Orientations":null,"DictionnaireObstacles":{"NORD":0,"EST":1,"SUD":1,"OUEST":0}}},{"Route":{"Position":"5, 3","Gauche":5,"Haut":3,"Taille":"1, 1","Orientations":null,"DictionnaireObstacles":{"NORD":1,"EST":2,"SUD":2,"OUEST":1}}},{"Route":{"Position":"0, 4","Gauche":0,"Haut":4,"Taille":"1, 1","Orientations":null,"DictionnaireObstacles":{"NORD":0,"EST":2,"SUD":2,"OUEST":2}}},{"Route":{"Position":"1, 4","Gauche":1,"Haut":4,"Taille":"1, 1","Orientations":null,"DictionnaireObstacles":{"NORD":0,"EST":2,"SUD":0,"OUEST":2}}},{"Route":{"Position":"2, 4","Gauche":2,"Haut":4,"Taille":"1, 1","Orientations":null,"DictionnaireObstacles":{"NORD":0,"EST":1,"SUD":2,"OUEST":2}}},{"Route":{"Position":"3, 4","Gauche":3,"Haut":4,"Taille":"1, 1","Orientations":null,"DictionnaireObstacles":{"NORD":2,"EST":2,"SUD":2,"OUEST":1}}},{"Route":{"Position":"4, 4","Gauche":4,"Haut":4,"Taille":"1, 1","Orientations":null,"DictionnaireObstacles":{"NORD":1,"EST":2,"SUD":0,"OUEST":2}}},{"Route":{"Position":"5, 4","Gauche":5,"Haut":4,"Taille":"1, 1","Orientations":null,"DictionnaireObstacles":{"NORD":2,"EST":1,"SUD":1,"OUEST":2}}},{"Route":{"Position":"0, 5","Gauche":0,"Haut":5,"Taille":"1, 1","Orientations":null,"DictionnaireObstacles":{"NORD":2,"EST":2,"SUD":1,"OUEST":1}}},{"Route":{"Position":"1, 5","Gauche":1,"Haut":5,"Taille":"1, 1","Orientations":null,"DictionnaireObstacles":{"NORD":0,"EST":2,"SUD":2,"OUEST":2}}},{"Route":{"Position":"2, 5","Gauche":2,"Haut":5,"Taille":"1, 1","Orientations":null,"DictionnaireObstacles":{"NORD":2,"EST":1,"SUD":1,"OUEST":2}}},{"Route":{"Position":"3, 5","Gauche":3,"Haut":5,"Taille":"1, 1","Orientations":null,"DictionnaireObstacles":{"NORD":2,"EST":0,"SUD":2,"OUEST":1}}},{"Route":{"Position":"4, 5","Gauche":4,"Haut":5,"Taille":"1, 1","Orientations":null,"DictionnaireObstacles":{"NORD":0,"EST":2,"SUD":2,"OUEST":0}}},{"Route":{"Position":"5, 5","Gauche":5,"Haut":5,"Taille":"1, 1","Orientations":null,"DictionnaireObstacles":{"NORD":1,"EST":0,"SUD":0,"OUEST":2}}}]} \ No newline at end of file diff --git a/EnVoiture/Resources/voiture_bleue.png b/EnVoiture/Resources/voiture_bleue.png new file mode 100644 index 0000000..1324149 Binary files /dev/null and b/EnVoiture/Resources/voiture_bleue.png differ diff --git a/EnVoiture/Resources/voiture_jaune.png b/EnVoiture/Resources/voiture_jaune.png new file mode 100644 index 0000000..1df4f7a Binary files /dev/null and b/EnVoiture/Resources/voiture_jaune.png differ diff --git a/EnVoiture/Resources/voiture_rouge.png b/EnVoiture/Resources/voiture_rouge.png new file mode 100644 index 0000000..a422877 Binary files /dev/null and b/EnVoiture/Resources/voiture_rouge.png differ diff --git a/EnVoiture/Resources/voiture_violette.png b/EnVoiture/Resources/voiture_violette.png new file mode 100644 index 0000000..dae0aee Binary files /dev/null and b/EnVoiture/Resources/voiture_violette.png differ diff --git a/EnVoiture/Usager.cs b/EnVoiture/Usager.cs index e00f04d..6700f88 100644 --- a/EnVoiture/Usager.cs +++ b/EnVoiture/Usager.cs @@ -1,5 +1,6 @@ using System; using System.Drawing; +using Newtonsoft.Json; namespace EnVoiture { @@ -11,9 +12,9 @@ public abstract class Usager private RectangleF bornes; private float dblVitesse; private float dblVitesseMax; - private const float ACCELERATION = 10; - private const float DECCELERATION = 2; - private const float FREINAGE = 15; + private const float ACCELERATION = .1f; + private const float DECCELERATION = .2f; + private const float FREINAGE = .15f; /// /// propriété règlant la vitesse diff --git a/EnVoiture/Vue/GenerateurWidget.cs b/EnVoiture/Vue/GenerateurWidget.cs index 17bff79..b95a2dc 100644 --- a/EnVoiture/Vue/GenerateurWidget.cs +++ b/EnVoiture/Vue/GenerateurWidget.cs @@ -1,11 +1,10 @@ -using EnVoiture.Modele; -using System; +using System; using System.Collections.Generic; using System.Drawing; using System.Linq; using System.Text; using System.Threading.Tasks; -using System.Windows.Forms; +using EnVoiture.Modele; namespace EnVoiture.Vue { diff --git a/EnVoiture/Vue/PietonWidget.cs b/EnVoiture/Vue/PietonWidget.cs new file mode 100644 index 0000000..783e2f2 --- /dev/null +++ b/EnVoiture/Vue/PietonWidget.cs @@ -0,0 +1,31 @@ +using System; +using System.Collections.Generic; +using System.Drawing; +using System.Linq; +using System.Text; +using System.Threading.Tasks; +using EnVoiture.Modele; + +namespace EnVoiture.Vue +{ + class PietonWidget : UsagerWidget + { + public Pieton Pieton { get; private set; } + + public PietonWidget(Rectangle rectangle, float v, float vmax) + { + this.Pieton = new Pieton(rectangle,v,vmax); + } + + public PietonWidget(int x, int y, int width, int height, float v, float vmax) + { + this.Pieton = new Pieton(x, y, width, height, 15, 30); + } + + public override void Dessiner(Graphics g) + { + g.FillEllipse(Brushes.Black, Pieton.Bornes); + } + + } +} diff --git a/EnVoiture/Vue/RouteWidget.cs b/EnVoiture/Vue/RouteWidget.cs new file mode 100644 index 0000000..5b5f211 --- /dev/null +++ b/EnVoiture/Vue/RouteWidget.cs @@ -0,0 +1,147 @@ +using EnVoiture.Modele; +using System; +using System.Collections.Generic; +using System.Drawing; +using System.Linq; +using System.Text; +using System.Threading.Tasks; +using EnVoiture.Modele; + +namespace EnVoiture.Vue +{ + public class RouteWidget + { + public static int TAILLE = 100; + public Route Route { get; set; } + + public RouteWidget(Route route) + { + Route = route; + } + + public void Dessiner(Graphics g, int opacite, Color color) + { + int x = Route.Position.X * TAILLE; + int y = Route.Position.Y * TAILLE; + int largeur = Route.Taille.Width * TAILLE; + int hauteur = Route.Taille.Height * TAILLE; + Brush b = new SolidBrush(Color.FromArgb(opacite, color)); + g.FillRectangle(b, x, y, largeur, hauteur); + } + + public void Dessiner(Graphics g) + { + int Left = Route.Position.X * TAILLE; + int Top = Route.Position.Y * TAILLE; + int TailleX = Route.Taille.Width * TAILLE; + int TailleY = Route.Taille.Height * TAILLE; + Dessiner(g, Left, Top, TailleX, TailleY); + } + + public void DessinerSurOrigine(Graphics g) + { + Dessiner(g, 0, 0, 100, 100); + } + + private void Dessiner(Graphics g, int x, int y, int largeur, int hauteur) + { + g.FillRectangle(Brushes.Gray, x, y, largeur, hauteur); + //Pen BlackPen = new Pen(Color.Black, 20); + Point point2 = new Point(x + hauteur / 2, y + hauteur / 2); + //Point point1; + + + //g.FillRectangle(Brushes.Gray, Route.Position.X * TAILLE, Route.Position.Y * TAILLE, Route.Taille.Width * TAILLE, Route.Taille.Height * TAILLE); + //Point point2 = new Point(Route.Position.X * TAILLE + Route.Taille.Height * TAILLE / 2, Route.Position.Y * TAILLE + Route.Taille.Height * TAILLE / 2); + + + + g.FillEllipse(Brushes.Black, point2.X - 10, point2.Y - 10, 20, 20); + + if (Route.DictionnaireObstacles.ContainsKey(Orientation.NORD)) + { + + /*point1 = new Point(x + largeur / 2, y); + g.DrawLine(BlackPen, point1, point2);*/ + + + DessinerSegment(g, Orientation.NORD, Route.DictionnaireObstacles[Orientation.NORD], x, y, largeur, hauteur); + + } + if (Route.DictionnaireObstacles.ContainsKey(Orientation.SUD)) + { + + /*point1 = new Point(x + largeur / 2, y + hauteur); + g.DrawLine(BlackPen, point1, point2);*/ + + DessinerSegment(g, Orientation.SUD, Route.DictionnaireObstacles[Orientation.SUD], x, y, largeur, hauteur); + + + } + if (Route.DictionnaireObstacles.ContainsKey(Orientation.EST)) + { + + /* point1 = new Point(x + largeur, y + hauteur / 2); + g.DrawLine(BlackPen, point1, point2);*/ + + DessinerSegment(g, Orientation.EST, Route.DictionnaireObstacles[Orientation.EST], x, y, largeur, hauteur); + + + } + if (Route.DictionnaireObstacles.ContainsKey(Orientation.OUEST)) + { + + /*point1 = new Point(x, y + hauteur / 2); + g.DrawLine(BlackPen, point1, point2);*/ + + DessinerSegment(g, Orientation.OUEST, Route.DictionnaireObstacles[Orientation.OUEST], x, y, largeur, hauteur); + + } + } + + public void DessinerSegment(Graphics g, Orientation orientation, Obstacle obstacle, int x, int y, int largeur, int hauteur) + { + Point point2 = new Point(x + hauteur / 2, y + hauteur / 2); + Pen pen; + switch (obstacle) + { + case Obstacle.RIEN: + pen = new Pen(Brushes.Transparent, 20); + break; + case Obstacle.ROUTE: + pen = new Pen(Brushes.Black, 20); + break; + case Obstacle.ROUTETROTTOIR: + pen = new Pen(Brushes.Blue, 20); + break; + default: + pen = new Pen(Brushes.Gainsboro, 20); + break; + } + Point point1; + + switch (orientation) + { + case Orientation.NORD: + point1 = new Point(x + largeur / 2, y); + g.DrawLine(pen, point1, point2); + break; + case Orientation.EST: + point1 = new Point(x + largeur, y + hauteur/ 2); + g.DrawLine(pen, point1, point2); + break; + case Orientation.SUD: + point1 = new Point(x + largeur / 2, y + hauteur); + g.DrawLine(pen, point1, point2); + break; + case Orientation.OUEST: + point1 = new Point(x, y + hauteur / 2); + g.DrawLine(pen, point1, point2); + break; + default: + break; + } + } + + } +} diff --git a/EnVoiture/Vue/UsagerWidget.cs b/EnVoiture/Vue/UsagerWidget.cs new file mode 100644 index 0000000..3335dcc --- /dev/null +++ b/EnVoiture/Vue/UsagerWidget.cs @@ -0,0 +1,17 @@ +using System; +using System.Collections.Generic; +using System.Drawing; +using System.Linq; +using System.Text; + +namespace EnVoiture.Vue +{ + public abstract class UsagerWidget + { + /// + /// Permet de dessiner l'usager sur un context graphic. + /// + /// L'endroit où dessiner l'usager + public abstract void Dessiner(Graphics g); + } +} diff --git a/EnVoiture/Vue/VoitureWidget.cs b/EnVoiture/Vue/VoitureWidget.cs new file mode 100644 index 0000000..d40bfca --- /dev/null +++ b/EnVoiture/Vue/VoitureWidget.cs @@ -0,0 +1,72 @@ + +using System; +using System.Threading; +using System.Drawing; +using EnVoiture.Modele; + +namespace EnVoiture.Vue +{ + /// + /// Représentation visuelle d'une voiture dans l'application. + /// + public class VoitureWidget : UsagerWidget + { + private static Random _random = new Random(); + private Bitmap _textureVoiture; + + /// + /// La voiture liée à cet afficheur. + /// + public Voiture Voiture { get; private set; } + + /// + /// Constructeur définissant la texture de la voiture. + /// + private VoitureWidget() + { + switch (_random.Next(4)) + { + case 0: + this._textureVoiture = Properties.Resources.voiture_bleue; + break; + case 1: + this._textureVoiture = Properties.Resources.voiture_jaune; + break; + case 2: + this._textureVoiture = Properties.Resources.voiture_rouge; + break; + case 3: + this._textureVoiture = Properties.Resources.voiture_violette; + break; + default: + break; + } + } + + /// + /// Constructeur permettant de définir la position et la taille d'une voiture d'après un rectangle. + /// + /// Rectangle sur lequel baser la géométrie de la voiture + public VoitureWidget(Rectangle rectangle) : this() + { + this.Voiture = new Voiture(rectangle, 0.0F); + } + + /// + /// Constructeur permettant de définir la position et la taille d'une voiture en donnant directement les valeurs. + /// + /// Position x du côté gauche + /// Position y du haut + /// Largeur + /// Hauteur + public VoitureWidget(int x, int y, int largeur, int hauteur, float vMax) : this() + { + this.Voiture = new Voiture(x, y, largeur, hauteur, vMax); + } + + public override void Dessiner(Graphics g) + { + g.DrawImage(_textureVoiture, Voiture.Position); + } + } +} diff --git a/EnVoiture/packages.config b/EnVoiture/packages.config new file mode 100644 index 0000000..c8b3ae6 --- /dev/null +++ b/EnVoiture/packages.config @@ -0,0 +1,4 @@ + + + + \ No newline at end of file diff --git a/EnVoiture/savePrefab.cs b/EnVoiture/savePrefab.cs new file mode 100644 index 0000000..52f4890 --- /dev/null +++ b/EnVoiture/savePrefab.cs @@ -0,0 +1,71 @@ +using EnVoiture.Modele; +using EnVoiture.Vue; +using System; +using System.Collections.Generic; +using System.Linq; +using System.Text; +using System.Threading.Tasks; +using Newtonsoft.Json; +using System.IO; + +namespace EnVoiture +{ + class savePrefab + { + private Voiture Voiture; + private List _usagers; + private float zoomRate; + private List Routes; + + public savePrefab() {} + + public Voiture voiture + { + get + { + return Voiture; + } + set + { + Voiture = value; + } + } + + public List usagers + { + get + { + return _usagers; + } + set + { + _usagers = value; + } + } + + public float zoomrate + { + get + { + return zoomRate; + } + set + { + zoomRate = value; + } + } + + public List routes + { + get + { + return Routes; + } + set + { + Routes = value; + } + } + + } +} diff --git a/EnVoitureUnitTest/EnVoitureUnitTest.csproj b/EnVoitureUnitTest/EnVoitureUnitTest.csproj index 6485564..ac4dc5a 100644 --- a/EnVoitureUnitTest/EnVoitureUnitTest.csproj +++ b/EnVoitureUnitTest/EnVoitureUnitTest.csproj @@ -53,7 +53,7 @@ - + diff --git a/EnVoitureUnitTest/TestGenerateur.cs b/EnVoitureUnitTest/TestGenerateur.cs index 94da9cb..2c6056b 100644 --- a/EnVoitureUnitTest/TestGenerateur.cs +++ b/EnVoitureUnitTest/TestGenerateur.cs @@ -26,7 +26,7 @@ public void TestEditionRouteNordNullRoute() Generateur generateur = new Generateur(new Route(0, 0, 1, 1, null)); generateur.EditionRoute(orientation); - Assert.AreEqual(generateur.Route.DictionaireObstacles[orientation], Obstacle.ROUTE); + Assert.AreEqual(generateur.Route.DictionnaireObstacles[orientation], Obstacle.ROUTE); } /// @@ -42,7 +42,7 @@ public void TestEditionRouteNordRienRoute() })); generateur.EditionRoute(orientation); - Assert.AreEqual(generateur.Route.DictionaireObstacles[orientation], Obstacle.ROUTE); + Assert.AreEqual(generateur.Route.DictionnaireObstacles[orientation], Obstacle.ROUTE); } /// @@ -58,7 +58,7 @@ public void TestEditionRouteNordRouteTrottoir() })); generateur.EditionRoute(orientation); - Assert.AreEqual(generateur.Route.DictionaireObstacles[orientation], Obstacle.ROUTETROTTOIR); + Assert.AreEqual(generateur.Route.DictionnaireObstacles[orientation], Obstacle.ROUTETROTTOIR); } /// @@ -74,7 +74,7 @@ public void TestEditionRouteNordTrottoirRien() })); generateur.EditionRoute(orientation); - Assert.AreEqual(generateur.Route.DictionaireObstacles[orientation], Obstacle.RIEN); + Assert.AreEqual(generateur.Route.DictionnaireObstacles[orientation], Obstacle.RIEN); } /* @@ -93,7 +93,7 @@ public void TestEditionRouteEstNullRoute() Generateur generateur = new Generateur(new Route(0, 0, 1, 1, null)); generateur.EditionRoute(orientation); - Assert.AreEqual(generateur.Route.DictionaireObstacles[orientation], Obstacle.ROUTE); + Assert.AreEqual(generateur.Route.DictionnaireObstacles[orientation], Obstacle.ROUTE); } /// @@ -109,7 +109,7 @@ public void TestEditionRouteEstRienRoute() })); generateur.EditionRoute(orientation); - Assert.AreEqual(generateur.Route.DictionaireObstacles[orientation], Obstacle.ROUTE); + Assert.AreEqual(generateur.Route.DictionnaireObstacles[orientation], Obstacle.ROUTE); } /// @@ -125,7 +125,7 @@ public void TestEditionRouteEstRouteTrottoir() })); generateur.EditionRoute(orientation); - Assert.AreEqual(generateur.Route.DictionaireObstacles[orientation], Obstacle.ROUTETROTTOIR); + Assert.AreEqual(generateur.Route.DictionnaireObstacles[orientation], Obstacle.ROUTETROTTOIR); } /// @@ -141,7 +141,7 @@ public void TestEditionRouteEstTrottoirRien() })); generateur.EditionRoute(orientation); - Assert.AreEqual(generateur.Route.DictionaireObstacles[orientation], Obstacle.RIEN); + Assert.AreEqual(generateur.Route.DictionnaireObstacles[orientation], Obstacle.RIEN); } /* @@ -160,7 +160,7 @@ public void TestEditionRouteSudNullRoute() Generateur generateur = new Generateur(new Route(0, 0, 1, 1, null)); generateur.EditionRoute(orientation); - Assert.AreEqual(generateur.Route.DictionaireObstacles[orientation], Obstacle.ROUTE); + Assert.AreEqual(generateur.Route.DictionnaireObstacles[orientation], Obstacle.ROUTE); } /// @@ -176,7 +176,7 @@ public void TestEditionRouteSudRienRoute() })); generateur.EditionRoute(orientation); - Assert.AreEqual(generateur.Route.DictionaireObstacles[orientation], Obstacle.ROUTE); + Assert.AreEqual(generateur.Route.DictionnaireObstacles[orientation], Obstacle.ROUTE); } /// @@ -192,7 +192,7 @@ public void TestEditionRouteSudRouteTrottoir() })); generateur.EditionRoute(orientation); - Assert.AreEqual(generateur.Route.DictionaireObstacles[orientation], Obstacle.ROUTETROTTOIR); + Assert.AreEqual(generateur.Route.DictionnaireObstacles[orientation], Obstacle.ROUTETROTTOIR); } /// @@ -208,7 +208,7 @@ public void TestEditionRouteSudTrottoirRien() })); generateur.EditionRoute(orientation); - Assert.AreEqual(generateur.Route.DictionaireObstacles[orientation], Obstacle.RIEN); + Assert.AreEqual(generateur.Route.DictionnaireObstacles[orientation], Obstacle.RIEN); } /* @@ -227,7 +227,7 @@ public void TestEditionRouteOuestNullRoute() Generateur generateur = new Generateur(new Route(0, 0, 1, 1, null)); generateur.EditionRoute(orientation); - Assert.AreEqual(generateur.Route.DictionaireObstacles[orientation], Obstacle.ROUTE); + Assert.AreEqual(generateur.Route.DictionnaireObstacles[orientation], Obstacle.ROUTE); } /// @@ -243,7 +243,7 @@ public void TestEditionRouteOuestRienRoute() })); generateur.EditionRoute(orientation); - Assert.AreEqual(generateur.Route.DictionaireObstacles[orientation], Obstacle.ROUTE); + Assert.AreEqual(generateur.Route.DictionnaireObstacles[orientation], Obstacle.ROUTE); } /// @@ -259,7 +259,7 @@ public void TestEditionRouteOuestRouteTrottoir() })); generateur.EditionRoute(orientation); - Assert.AreEqual(generateur.Route.DictionaireObstacles[orientation], Obstacle.ROUTETROTTOIR); + Assert.AreEqual(generateur.Route.DictionnaireObstacles[orientation], Obstacle.ROUTETROTTOIR); } /// @@ -275,7 +275,7 @@ public void TestEditionRouteOuestTrottoirRien() })); generateur.EditionRoute(orientation); - Assert.AreEqual(generateur.Route.DictionaireObstacles[orientation], Obstacle.RIEN); + Assert.AreEqual(generateur.Route.DictionnaireObstacles[orientation], Obstacle.RIEN); } } } diff --git a/EnVoitureUnitTest/TestGenerationRoutes.cs b/EnVoitureUnitTest/TestGenerationRoutes.cs new file mode 100644 index 0000000..fcf8400 --- /dev/null +++ b/EnVoitureUnitTest/TestGenerationRoutes.cs @@ -0,0 +1,42 @@ +using Microsoft.VisualStudio.TestTools.UnitTesting; +using System; +using System.Collections.Generic; +using System.Linq; +using System.Text; +using System.Threading.Tasks; +using EnVoiture.Modele; + +namespace EnVoitureUnitTest +{ + [TestClass] + public class TestGenerationRoutes + { + [TestMethod] + public void TestCreationVille() + { + List routes = new List(); + routes = Route.Generer(3, 3); + Assert.AreEqual(9, routes.Count); + } + + [TestMethod] + public void TestCorrespondanceOrientations() + { + List routes = new List(); + routes = Route.Generer(3, 3); + + Assert.AreEqual(routes[0].DictionnaireObstacles[Orientation.EST], routes[1].DictionnaireObstacles[Orientation.OUEST]); + Assert.AreEqual(routes[1].DictionnaireObstacles[Orientation.EST], routes[2].DictionnaireObstacles[Orientation.OUEST]); + Assert.AreEqual(routes[3].DictionnaireObstacles[Orientation.EST], routes[4].DictionnaireObstacles[Orientation.OUEST]); + Assert.AreEqual(routes[4].DictionnaireObstacles[Orientation.EST], routes[5].DictionnaireObstacles[Orientation.OUEST]); + Assert.AreEqual(routes[6].DictionnaireObstacles[Orientation.EST], routes[7].DictionnaireObstacles[Orientation.OUEST]); + Assert.AreEqual(routes[7].DictionnaireObstacles[Orientation.EST], routes[8].DictionnaireObstacles[Orientation.OUEST]); + Assert.AreEqual(routes[0].DictionnaireObstacles[Orientation.SUD], routes[3].DictionnaireObstacles[Orientation.NORD]); + Assert.AreEqual(routes[1].DictionnaireObstacles[Orientation.SUD], routes[4].DictionnaireObstacles[Orientation.NORD]); + Assert.AreEqual(routes[2].DictionnaireObstacles[Orientation.SUD], routes[5].DictionnaireObstacles[Orientation.NORD]); + Assert.AreEqual(routes[3].DictionnaireObstacles[Orientation.SUD], routes[6].DictionnaireObstacles[Orientation.NORD]); + Assert.AreEqual(routes[4].DictionnaireObstacles[Orientation.SUD], routes[7].DictionnaireObstacles[Orientation.NORD]); + Assert.AreEqual(routes[5].DictionnaireObstacles[Orientation.SUD], routes[8].DictionnaireObstacles[Orientation.NORD]); + } + } +} diff --git a/EnVoitureUnitTest/TestPieton.cs b/EnVoitureUnitTest/TestPieton.cs index 913195b..3e34c30 100644 --- a/EnVoitureUnitTest/TestPieton.cs +++ b/EnVoitureUnitTest/TestPieton.cs @@ -1,7 +1,7 @@ using System; using Microsoft.VisualStudio.TestTools.UnitTesting; using System.Drawing; -using EnVoiture; +using EnVoiture.Modele; namespace EnVoitureUnitTest { @@ -16,7 +16,7 @@ public class TestPieton [TestMethod] public void TestCreatePieton() { - Pieton pieton1 = new Pieton(30, 30, 10, 10, 0.0, 150.0); + Pieton pieton1 = new Pieton(30, 30, 10, 10, 0.0f, 150.0f); Assert.IsNotNull(pieton1); } } diff --git a/EnVoitureUnitTest/TestRoadUser.cs b/EnVoitureUnitTest/TestRoadUser.cs index ac83aed..65a046c 100644 --- a/EnVoitureUnitTest/TestRoadUser.cs +++ b/EnVoitureUnitTest/TestRoadUser.cs @@ -1,7 +1,7 @@ using System; using Microsoft.VisualStudio.TestTools.UnitTesting; using System.Drawing; -using EnVoiture; +using EnVoiture.Modele; namespace EnVoitureUnitTest { @@ -144,7 +144,7 @@ public void TestReculer() public void TestStopDeplacement() { Usager car = new Voiture(0, 0, 10, 10, 80); - car.StopDeplacement(); + car.FreinageUrgence(); Assert.AreEqual(0, car.Position.Y); //teste si la position su l'axe y est restée la même Assert.AreEqual(0, car.Position.X);//teste si la position su l'axe x est restée la même } diff --git a/EnVoitureUnitTest/TestWay.cs b/EnVoitureUnitTest/TestWay.cs index 1c4e84b..434b53e 100644 --- a/EnVoitureUnitTest/TestWay.cs +++ b/EnVoitureUnitTest/TestWay.cs @@ -3,6 +3,7 @@ using System.Collections.Generic; using EnVoiture; using System.Drawing; +using EnVoiture.Modele; namespace EnVoitureUnitTest { diff --git a/EnVoitureUnitTest/testAcceleration.cs b/EnVoitureUnitTest/testAcceleration.cs index dd59044..166b6c7 100644 --- a/EnVoitureUnitTest/testAcceleration.cs +++ b/EnVoitureUnitTest/testAcceleration.cs @@ -1,7 +1,7 @@ using System; using Microsoft.VisualStudio.TestTools.UnitTesting; -using EnVoiture; using System.Drawing; +using EnVoiture.Modele; namespace EnVoitureUnitTest {