protected override void OnPaint(PaintEventArgs pe) { base.OnPaint(pe); Graphics g = pe.Graphics; int grosor = 7; // Variable que controla el grosor del lápiz //Esta propiedad provoca mejoras en la apariencia o en la eficiencia a la hora de dibujar g.SmoothingMode = System.Drawing.Drawing2D.SmoothingMode.AntiAlias; Pen lapiz = new Pen(Color.Black, grosor); // Dibujo la base del ahorcado g.DrawLine(lapiz, this.Width, this.Height, 0, this.Height); g.DrawLine(lapiz, 0, this.Height, 0, 0); g.DrawLine(lapiz, 0, 0, this.Width / 2, 0); // Cambio el grosor del lápiz para dibujar el apoyo y la cuerda con el muñeco grosor = 5; lapiz = new Pen(Color.Black, grosor); g.DrawLine(lapiz, 0, this.Height / 5, this.Width / 5, 0); switch (errores) { case 1: // Dibujo la cuerda g.DrawLine(lapiz, this.Width / 2, 0, this.Width / 2, this.Height / 5); break; case 2: // Añado la cabeza g.DrawEllipse(lapiz, this.Width / 2.35f, this.Height / 5, this.Width / 6.5f, this.Width / 6.5f); goto case 1; case 3: // Añado el torso g.DrawLine(lapiz, this.Width / 2f, this.Height / 5 + this.Width / 6.5f, this.Width / 2f, (this.Height / 5 + this.Width / 6.5f) * 2); goto case 2; case 4: // Añado brazo derecho g.DrawLine(lapiz, this.Width / 2f, (this.Height / 5 + this.Width / 6.5f) * 1.25f, this.Width / 1.45f, (this.Height / 5 + this.Width / 6.5f) * 1.25f); goto case 3; case 5: // Añado brazo izquierdo g.DrawLine(lapiz, this.Width / 2f, (this.Height / 5 + this.Width / 6.5f) * 1.25f, this.Width / 3.5f, (this.Height / 5 + this.Width / 6.5f) * 1.25f); goto case 4; case 6: // Añado pierna izquierda g.DrawLine(lapiz, this.Width / 2f, (this.Height / 5 + this.Width / 6.5f) * 2, this.Width / 3f, ((this.Height / 5 + this.Width / 6.5f) * 2) * 1.25f); goto case 5; case 7: // Añado pierna derecha g.DrawLine(lapiz, this.Width / 2f, (this.Height / 5 + this.Width / 6.5f) * 2, this.Width / 1.45f, ((this.Height / 5 + this.Width / 6.5f) * 2) * 1.25f); Ahorcado?.Invoke(this, EventArgs.Empty); // Lanzo el evento Ahorcado cuando llega al final goto case 6; } }
/*============================================================================== * ____ _ _ ___ ____ _ _ _ ___ | | |\ | |__] |__| | |\ | | |__| | \| | | | | | \| | | ==============================================================================*/ protected override void OnPaint(PaintEventArgs pe) { base.OnPaint(pe); this.tile = this.anchoComponente / 7; this.alto = this.tile * 4; Graphics g = pe.Graphics; Pen pen = new Pen(this.color); //linea g.DrawLine(pen, 0f, this.alto, this.anchoComponente, this.alto); //cruces g.DrawLine(pen, tile * 0.1f, tile * 2.3f, tile * 0.9f, tile * 2.3f); //horizontal g.DrawLine(pen, tile * 0.5f, tile * 2f, tile * 0.5f, this.alto); //vertical g.DrawLine(pen, tile * 4.7f, tile * 3.2f, tile * 5.3f, tile * 3.2f); //horizontal g.DrawLine(pen, tile * 5f, tile * 3f, tile * 5f, this.alto); //vertical g.DrawLine(pen, tile * 5.2f, tile * 2.8f, tile * 5.8f, tile * 2.8f); //horizontal g.DrawLine(pen, tile * 5.5f, tile * 2.5f, tile * 5.5f, this.alto); //vertical g.DrawLine(pen, tile * 6f, tile * 3.2f, tile * 6.6f, tile * 3.2f); //horizontal g.DrawLine(pen, tile * 6.3f, tile * 3f, tile * 6.3f, this.alto); //vertical //plataforma g.DrawRectangle(pen, tile * 1f, tile * 3.7f, tile * 3, tile * 0.3f); g.DrawRectangle(pen, tile * 1.2f, 0, tile * 0.2f, tile * 3.7f); g.DrawRectangle(pen, tile * 1f, tile * 0.1f, tile * 0.2f, tile * 0.2f); g.DrawRectangle(pen, tile * 1.4f, tile * 0.1f, tile * 2.4f, tile * 0.2f); //ahorcado switch (errores) { case 1: g.DrawLine(pen, tile * 3.3f, tile * 0.3f, tile * 3.3f, tile * 0.7f); //cuerda break; case 2: g.DrawEllipse(pen, tile * 3f, tile * 0.7f, tile * 0.6f, tile * 0.6f); //cabeza goto case 1; case 3: g.DrawLine(pen, tile * 3.3f, tile * 1.3f, tile * 3.3f, tile * 2.4f); //cuerpo goto case 2; case 4: g.DrawLine(pen, tile * 3.3f, tile * 1.4f, tile * 3f, tile * 2f); //brazo derecho goto case 3; case 5: g.DrawLine(pen, tile * 3.3f, tile * 1.4f, tile * 3.6f, tile * 2f); //brazo izquierdo goto case 4; case 6: g.DrawLine(pen, tile * 3.3f, tile * 2.4f, tile * 3f, tile * 3.2f); //pierna dcha goto case 5; case 7: g.DrawLine(pen, tile * 3.3f, tile * 2.4f, tile * 3.6f, tile * 3.2f); //pierna izq Ahorcado?.Invoke(this, EventArgs.Empty); goto case 6; default: break; } pen.Dispose(); }