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 void Page_Load(object sender, EventArgs e) { Usuario usr = (Usuario)Session["Usuario"]; if (usr != null) { if (!IsPostBack) { Palabra pal; if ((bool)Session["testMode"]) { pal = new Palabra("salero"); } else { pal = new Palabra(); } Ahorcado ah = new Ahorcado(pal, usr); Session["Juego"] = new AhorcadoLogic(ah); } ahlogic = (AhorcadoLogic)Session["Juego"]; generarLabelsLetras(ahlogic.Ahorcado); actualizarJuego(); } else { Response.Redirect("Inicio.aspx"); } lblUserName.Text = usr.UserName; }
// GET: Admin/Ahorcado/Delete/5 public ActionResult Delete(int?id) { if (id == null) { return(new HttpStatusCodeResult(HttpStatusCode.BadRequest)); } Ahorcado Ahorcado = db.Ahorcado.Find(id); if (Ahorcado == null) { return(HttpNotFound()); } if (Ahorcado.UrlImagen != null) { string fullPath = Request.MapPath("~/media/upload/Ahorcado/" + Ahorcado.UrlImagen); if (System.IO.File.Exists(fullPath)) { System.IO.File.Delete(fullPath); } } if (Ahorcado.Audio != null) { string fullPath = Request.MapPath("~/media/upload/Ahorcado/Audios/" + Ahorcado.Audio); if (System.IO.File.Exists(fullPath)) { System.IO.File.Delete(fullPath); } } db.Ahorcado.Remove(Ahorcado); db.SaveChanges(); return(RedirectToAction("Create", "Ahorcado", new { id = Ahorcado.JuegoOnlineId })); }
public void ControlaListaCorrecta() { //Arrange Usuario u = new Usuario(); Palabra p = new Palabra("salero"); Ahorcado a = new Ahorcado(p, u); AhorcadoLogic Juego = new AhorcadoLogic(a); List <char> ListDeLetras = new List <char>(); ListDeLetras.Add('a'); ListDeLetras.Add('s'); ListDeLetras.Add('t'); ListDeLetras.Add('y'); ListDeLetras.Add('l'); List <char> letrasCorrectas = new List <char>(); letrasCorrectas.Add('a'); letrasCorrectas.Add('s'); letrasCorrectas.Add('l'); //Act foreach (var i in ListDeLetras) { Juego.JuegaLetra(i); } //Assert Assert.IsTrue(letrasCorrectas.All(Juego.Ahorcado.LetrasCorrectas.Contains)); }
public void ControlaVictoria() { //Arrange Usuario u = new Usuario(); Palabra p = new Palabra("salero"); Ahorcado a = new Ahorcado(p, u); AhorcadoLogic Juego = new AhorcadoLogic(a); List <char> ListDeLetras = new List <char>(); ListDeLetras.Add('s'); ListDeLetras.Add('a'); ListDeLetras.Add('l'); ListDeLetras.Add('e'); ListDeLetras.Add('r'); ListDeLetras.Add('o'); //Act foreach (var i in ListDeLetras) { Juego.JuegaLetra(i); } bool bandera = Juego.Ahorcado.Palabra.PalabraActual.All(Juego.Ahorcado.LetrasCorrectas.Contains); //Assert Assert.IsTrue(bandera); }
public void ControlaCantIntentosQuedan5() { //Arrange Usuario u = new Usuario(); Palabra p = new Palabra("salero"); Ahorcado a = new Ahorcado(p, u); AhorcadoLogic Juego = new AhorcadoLogic(a); List <char> ListDeLetras = new List <char>(); ListDeLetras.Add('a'); ListDeLetras.Add('s'); ListDeLetras.Add('t'); ListDeLetras.Add('y'); ListDeLetras.Add('l'); //Act foreach (var i in ListDeLetras) { Juego.JuegaLetra(i); } //Assert Assert.AreEqual(5, Juego.Ahorcado.CantIntentos); }
public void CantidadIntetosDerrota() { //Arrange Usuario u = new Usuario(); Palabra p = new Palabra("salero"); Ahorcado a = new Ahorcado(p, u); AhorcadoLogic Juego = new AhorcadoLogic(a); List <char> ListDeLetras = new List <char>(); ListDeLetras.Add('v'); ListDeLetras.Add('x'); ListDeLetras.Add('t'); ListDeLetras.Add('y'); ListDeLetras.Add('s'); ListDeLetras.Add('a'); ListDeLetras.Add('w'); ListDeLetras.Add('q'); ListDeLetras.Add('m'); //Act foreach (var i in ListDeLetras) { Juego.JuegaLetra(i); } bool bandera = Juego.Ahorcado.CantIntentos == 0; //Assert Assert.IsTrue(bandera); }
public string InicializarAhorcadoMultijugador([FromBody] PalabraInput request) { Ahorcado.Init(request.Palabra); Result result = new Result { Success = true, Value = Ahorcado.Instance.GetPalabra(), Info = "Juego Multijugador inicializado" }; string json = JsonConvert.SerializeObject(result); return(json); }
public string InicializarAhorcado() { Ahorcado.Init(); Result result = new Result { Success = true, Value = Ahorcado.Instance.GetPalabra(), Info = "Juego inicializado" }; string json = JsonConvert.SerializeObject(result); return(json); }
public JsonResult GetAhorcado(int id) { Ahorcado Ahorcado = db.Ahorcado.Find(id); PreguntaAhorcado pregunta = new PreguntaAhorcado() { Audio = Ahorcado.Audio, Imagen = Ahorcado.UrlImagen, Enunciado = Ahorcado.Descripcion, MascaraInicial = GenerarMascara(Ahorcado.Respuesta, new List <string>()) }; return(Json(pregunta, JsonRequestBehavior.AllowGet)); }
public void VerificarLetraPerteneceAPalabraLogic() { //Arrange Usuario u = new Usuario(); Palabra p = new Palabra("salero"); Ahorcado a = new Ahorcado(p, u); AhorcadoLogic Juego = new AhorcadoLogic(a); //Act bool bandera = Juego.PreguntaLetra('a'); //Assert Assert.IsTrue(bandera); }
public void VerificarNombreUsuario() { //Arrange Usuario u = new Usuario(); Palabra p = new Palabra("salero"); Ahorcado a = new Ahorcado(p, u); AhorcadoLogic Juego = new AhorcadoLogic(a); //Act bool bandera = Juego.ControlaSoloLetras("pepito"); //Assert Assert.IsTrue(bandera); }
public void ControlaValidezLetraIngresada() { //Arrange Usuario u = new Usuario(); Palabra p = new Palabra("salero"); Ahorcado a = new Ahorcado(p, u); AhorcadoLogic Juego = new AhorcadoLogic(a); //Act bool bandera = Juego.ControlaLetraActual('s'); //Assert Assert.IsTrue(bandera); }
// GET: Admin/Ahorcado/Edit public ActionResult Edit(int id) { if (id == null) { return(new HttpStatusCodeResult(HttpStatusCode.BadRequest)); } Ahorcado Ahorcado = db.Ahorcado.Find(id); if (Ahorcado == null) { return(HttpNotFound()); } AhorcadoEditViewModel viewModel = new AhorcadoEditViewModel(); viewModel.Inicializar(Ahorcado.JuegoOnlineId); viewModel.Ahorcado = Ahorcado; return(View(viewModel)); }
private void generarLabelsLetras(Ahorcado ahorcado) { phLetters.Controls.Clear(); int largo = ahorcado.Palabra.PalabraActual.Length; for (int i = 0; i < largo; i++) { Label label = new Label(); label.ID = "lblLetter" + i.ToString(); label.CssClass = "lead p-2 text-white"; if (ahorcado.LetrasCorrectas.Contains(ahorcado.Palabra.PalabraActual[i])) { label.Text = ahorcado.Palabra.PalabraActual[i].ToString(); } else { label.Text = "_"; } phLetters.Controls.Add(label); } }
/*============================================================================== * ____ _ _ ___ ____ _ _ _ ___ | | |\ | |__] |__| | |\ | | |__| | \| | | | | | \| | | ==============================================================================*/ 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(); }