2018-01-05 22:18:28 +01:00
|
|
|
|
using System;
|
|
|
|
|
using System.Collections.Generic;
|
|
|
|
|
using System.ComponentModel;
|
|
|
|
|
using System.Data;
|
|
|
|
|
using System.Drawing;
|
2018-01-09 13:49:11 +01:00
|
|
|
|
using System.IO;
|
2018-01-05 22:18:28 +01:00
|
|
|
|
using System.Linq;
|
2018-01-09 13:49:11 +01:00
|
|
|
|
using System.Media;
|
2018-01-05 22:18:28 +01:00
|
|
|
|
using System.Text;
|
|
|
|
|
using System.Threading;
|
|
|
|
|
using System.Threading.Tasks;
|
|
|
|
|
using System.Windows.Forms;
|
|
|
|
|
|
|
|
|
|
namespace Bonhomme02
|
|
|
|
|
{
|
|
|
|
|
public partial class Form1 : Form
|
|
|
|
|
{
|
|
|
|
|
private Bonhomme bonhomme;
|
2018-01-11 14:33:44 +01:00
|
|
|
|
private Bonhomme bonhomme2;
|
2018-01-05 22:18:28 +01:00
|
|
|
|
private Marcher marche;
|
2018-01-11 14:33:44 +01:00
|
|
|
|
private Marcher marche2;
|
2018-01-05 22:18:28 +01:00
|
|
|
|
private BufferedGraphics bufferG = null;
|
|
|
|
|
private Graphics g;
|
2018-01-09 13:49:11 +01:00
|
|
|
|
SoundPlayer player = new SoundPlayer();
|
2018-01-09 20:19:49 +01:00
|
|
|
|
Stream str;
|
2018-01-09 13:49:11 +01:00
|
|
|
|
List<Task> tasks = new List<Task>();
|
2018-01-05 22:18:28 +01:00
|
|
|
|
public Form1()
|
|
|
|
|
{
|
|
|
|
|
InitializeComponent();
|
|
|
|
|
// Modification contre le scintillement - Creation d'une mémoire tampon graphique
|
|
|
|
|
bufferG = BufferedGraphicsManager.Current.Allocate(TV.CreateGraphics(), TV.DisplayRectangle);
|
|
|
|
|
g = bufferG.Graphics;
|
2018-01-09 13:49:11 +01:00
|
|
|
|
|
2018-01-05 22:18:28 +01:00
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
private void timerImage_Tick(object sender, EventArgs e)
|
|
|
|
|
{
|
|
|
|
|
if (/*this.bonhomme.Origine.X + this.bonhomme.Lhorizontal >= this.TV.Width*/1==2)
|
|
|
|
|
{
|
|
|
|
|
this.timerImage.Stop();
|
2018-01-09 21:04:00 +01:00
|
|
|
|
|
2018-01-05 22:18:28 +01:00
|
|
|
|
}
|
|
|
|
|
else
|
|
|
|
|
{
|
2018-01-09 20:19:49 +01:00
|
|
|
|
bonhomme.Cacher(g);
|
2018-01-05 22:18:28 +01:00
|
|
|
|
bonhomme.coordonnee = new Point(bonhomme.coordonnee.X + 3, bonhomme.coordonnee.Y + 0);
|
2018-01-06 16:56:46 +01:00
|
|
|
|
bonhomme.jambe1.BougerBas(+3, -3);
|
2018-01-09 20:19:49 +01:00
|
|
|
|
bonhomme.Afficher(g);
|
2018-01-05 22:18:28 +01:00
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
private void btnStopDeplacerCTick_Click(object sender, EventArgs e)
|
|
|
|
|
{
|
|
|
|
|
this.timerImage.Stop();
|
2018-01-09 21:04:00 +01:00
|
|
|
|
|
2018-01-05 22:18:28 +01:00
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
private void btnEffacer_Click(object sender, EventArgs e)
|
|
|
|
|
{
|
|
|
|
|
Graphics gr = Graphics.FromHwnd(this.TV.Handle);
|
|
|
|
|
gr.FillRectangle(new SolidBrush(this.TV.BackColor), 0, 0, this.TV.Bounds.Width, this.TV.Bounds.Height);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
private void btnCreationCarrosse_Click(object sender, EventArgs e)
|
|
|
|
|
{
|
2018-01-09 13:49:11 +01:00
|
|
|
|
|
2018-01-09 21:04:00 +01:00
|
|
|
|
|
2018-01-09 13:49:11 +01:00
|
|
|
|
if (tasks.Count == 0)
|
|
|
|
|
{
|
2018-01-11 14:33:44 +01:00
|
|
|
|
bonhomme = new Bonhomme(ref this.TV, 200, 80, 50, 20, Math.PI / 2);
|
|
|
|
|
bonhomme2 = new Bonhomme(ref this.TV, this.Width - 2 * 80, 80, 50, 20, Math.PI / 2);
|
2018-01-09 21:04:00 +01:00
|
|
|
|
bonhomme.jambe1.Bas.Fond = bonhomme.jambe1.Millieux.Fond = bonhomme.jambe1.Haut.Fond = Color.Pink;
|
|
|
|
|
bonhomme.jambe2.Bas.Fond = bonhomme.jambe2.Millieux.Fond = bonhomme.jambe2.Haut.Fond = Color.DeepPink;
|
|
|
|
|
bonhomme.tete.Fond = Color.Pink;
|
2018-01-11 14:33:44 +01:00
|
|
|
|
bonhomme2.jambe1.Bas.Fond = bonhomme2.jambe1.Millieux.Fond = bonhomme2.jambe1.Haut.Fond = Color.Beige;
|
|
|
|
|
bonhomme2.jambe2.Bas.Fond = bonhomme2.jambe2.Millieux.Fond = bonhomme2.jambe2.Haut.Fond = Color.Bisque;
|
|
|
|
|
bonhomme2.tete.Fond = Color.Brown;
|
2018-01-09 21:04:00 +01:00
|
|
|
|
marche = new Marcher(ref bonhomme, bufferG, this.Sol.Location.Y - this.TV.Location.Y);
|
2018-01-11 14:33:44 +01:00
|
|
|
|
marche2 = new Marcher(ref bonhomme2, bufferG, this.Sol.Location.Y - this.TV.Location.Y);
|
|
|
|
|
bonhomme2.Cacher(g);
|
|
|
|
|
bufferG.Render();
|
2018-01-09 21:04:00 +01:00
|
|
|
|
Thread.Sleep(1000);
|
|
|
|
|
|
2018-01-09 20:19:49 +01:00
|
|
|
|
str = global::Bonhomme02.Properties.Resources.NyanCatoriginal;
|
2018-01-09 13:49:11 +01:00
|
|
|
|
player.Stream = str;
|
2018-01-09 20:19:49 +01:00
|
|
|
|
this.NyanCatGif.Image = global::Bonhomme02.Properties.Resources.tumblr_opsismTLqh1vghf22o1_400;
|
2018-01-09 13:49:11 +01:00
|
|
|
|
player.Play();
|
2018-01-09 21:04:00 +01:00
|
|
|
|
tasks.Add(Task.Factory.StartNew(() => {
|
2018-01-09 20:47:44 +01:00
|
|
|
|
marche.Saut(ref this.Obstacle, 5);
|
2018-01-09 13:49:11 +01:00
|
|
|
|
}));
|
2018-01-09 21:04:00 +01:00
|
|
|
|
var continuation = Task.WhenAll(tasks); //https://docs.microsoft.com/en-us/dotnet/standard/parallel-programming/chaining-tasks-by-using-continuation-tasks
|
|
|
|
|
Task continuationTask = continuation.ContinueWith((antecedent) => {
|
|
|
|
|
tasks.RemoveAt(0);
|
|
|
|
|
if (tasks.Count == 0)
|
|
|
|
|
{
|
|
|
|
|
player.Stop();
|
|
|
|
|
str = str = global::Bonhomme02.Properties.Resources.Super_Mario_Bros_Win_Stage_Sound_Effect;
|
|
|
|
|
player.Stream = str;
|
2018-01-11 14:33:44 +01:00
|
|
|
|
|
|
|
|
|
marche2.SautY(80,5);
|
|
|
|
|
bufferG.Render();
|
2018-01-09 21:04:00 +01:00
|
|
|
|
player.Play();
|
|
|
|
|
this.NyanCatGif.Image = null;
|
|
|
|
|
}
|
|
|
|
|
});
|
|
|
|
|
}
|
|
|
|
|
// https://msdn.microsoft.com/fr-be/Library/dd270696(v=vs.110).aspx
|
|
|
|
|
|
|
|
|
|
|
2018-01-05 22:18:28 +01:00
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
private void Form1_Load(object sender, EventArgs e)
|
|
|
|
|
{
|
|
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
private void Form1_MouseMove(object sender, MouseEventArgs e)
|
|
|
|
|
{
|
|
|
|
|
MousePosition.Offset(this.Location);
|
|
|
|
|
Console.WriteLine(MousePosition);
|
|
|
|
|
}
|
2018-01-11 14:33:44 +01:00
|
|
|
|
|
|
|
|
|
private void pictureBox1_Click(object sender, EventArgs e)
|
|
|
|
|
{
|
|
|
|
|
|
|
|
|
|
}
|
2018-01-05 22:18:28 +01:00
|
|
|
|
}
|
|
|
|
|
}
|