コード例 #1
0
    protected void setNewRandomCard()
    {
        /*card to guess*/

        int randomNum;

        do
        {
            randomNum = ran.Next(sizeTablero * sizeTablero);
            //            if (usedCards.IndexOf(randomNum) == -1)
            int returnVal = usedCards.IndexOf((arrCardsTablero[randomNum] as CartasDTO).ID);
            if (returnVal == -1)
            //if (usedCards.IndexOf((arrTablero[randomNum] as CartasDTO).ID) == -1)
            {
                //int randomNum = ran.Next(((int)ViewState["ctrCardsRemaining"]) - 1);
                cardAtHand = (arrCardsTablero[randomNum] as CartasDTO);
                if (isHard)
                {
                    lblCardAtHand.Text = cardAtHand.Statement;
                }
                else
                {
                    lblCardAtHand.Text = cardAtHand.Name;
                }
                imgCardAtHand.ImageUrl  = cardAtHand.Path;
                imgCardAtHand.Visible   = false;
                ViewState["cardAtHand"] = cardAtHand;
                ViewState["ctrImage"]   = ctrImage;

                cardStatics.Add(cardAtHand);
                ViewState["cardStatics"] = cardStatics;
                if (!isHard)
                {
                    imgBtnShowImage.Enabled = true;
                }
                hdnUsedSound.Value = "0";
                break;
            }
            else
            {
                if (usedCards.ToArray().Length >= (sizeTablero * sizeTablero))
                {
                    bool isGameFinished = true;
                    imgBtnShowImage.Enabled = false;
                    imgBtnMakeNoise.Enabled = false;
                    lblGameFinished.Visible = true;

                    ScriptManager.RegisterStartupScript(Page, Page.GetType(), "popup",
                                                        "window.open('" + "Recompensa.aspx?total=" + (sizeTablero * sizeTablero) + "&correct=" + ctrTotalCorrect + "','_blank', " +
                                                        "'width=250,height=350,toolbar=no,location = no,status = no," +
                                                        "menubar = no,scrollbars = yes,resizable = yes,width = SomeSize,height = SomeSize')", true);
                    break;
                }
            }
        } while (true);
    }
コード例 #2
0
 protected void redrawBoard()
 {
     for (int row = 0; row < sizeTablero; row++)
     {
         TableRow tr = new TableRow();
         for (int col = 0; col < sizeTablero; col++)
         {
             TableCell   tc    = new TableCell();
             ImageButton imgbt = new ImageButton();
             CartasDTO   cdto  = (arrCardsTablero[(row * sizeTablero) + col] as CartasDTO);
             imgbt.ImageUrl      = cdto.Path;
             imgbt.AlternateText = cdto.ID.ToString();
             imgbt.Click        += new ImageClickEventHandler(imgbtn1_Click);
             imgbt.ID            = cdto.ID.ToString();
             tc.Controls.Add(imgbt);
             //tc.Width = new Unit("33px");
             tr.Cells.Add(tc);
         }
         tbTablero.Rows.Add(tr);
     }
 }
コード例 #3
0
    /// <summary>
    /// Main function.
    /// Load the data into the Tablero, then create the ViewState to keep info between postbacks
    /// and reloads the info after postbacks
    /// </summary>
    /// <param name="sender">The page</param>
    /// <param name="e"></param>
    protected void Page_Load(object sender, EventArgs e)
    {
        isJugadorLoggedIn();

        Int32.TryParse(Request.QueryString["size"], out sizeTablero);
        Boolean.TryParse(Request.QueryString["hard"], out isHard);
        if (!IsPostBack)
        {
            /*ctrCardsRemaining = sizeTablero * sizeTablero;
             * ViewState["ctrCardsRemaining"] = sizeTablero* sizeTablero;*/


            if (isHard)
            {
                imgBtnShowImage.Visible = false;
            }

            /*Load cards data*/
            arrCardsAvailable = loteria.getCartasByJugador(JugadorID);

            if (arrCardsAvailable.ToArray().Length < (sizeTablero * sizeTablero))
            {
                ScriptManager.RegisterStartupScript(Page, Page.GetType(), "showalert",
                                                    "alert('El Jugador no cuenta con las suficientes cartas para jugar, " +
                                                    "intente con un tablero mas pequeño'); window.close();", true);

                return;
            }
            else
            {
                foreach (var card in arrCardsAvailable)
                {
                    (card as CartasDTO).Frases = loteria.getFrasesPerCard((card as CartasDTO).ID);
                }
            }

            /*Set the available cards to be used in the board*/
            setCardsTablero();

            /*card to guess*/
            setNewRandomCard();

            ViewState["arrTablero"] = arrCardsAvailable;

            ViewState["usedCards"]  = usedCards;
            ViewState["usedFrases"] = usedFrases;

            ViewState["cardStatics"]         = cardStatics;
            ViewState["ctrSoundTotal"]       = ctrSoundTotal;
            ViewState["arrCardsTablero"]     = arrCardsTablero;
            ViewState["ctrSort"]             = ctrSort;
            ViewState["ctrTotalCorrect"]     = ctrTotalCorrect;
            ViewState["ctrTotalIncorrect"]   = ctrTotalIncorrect;
            ViewState["ctrTotalCardsPlayer"] = ctrTotalCardsPlayer;
        }
        else
        {
            arrCardsAvailable = ViewState["arrTablero"] as ArrayList;
            cardAtHand        = ViewState["cardAtHand"] as CartasDTO;
            fraseAtHandID     = Int32.Parse(ViewState["fraseAtHandID"].ToString());

            usedCards  = ViewState["usedCards"] as List <int>;
            usedFrases = ViewState["usedFrases"] as Dictionary <string, int>;

            arrFrasesTablero = ViewState["arrFrasesTablero"] as Dictionary <string, int>;

            cardStatics         = ViewState["cardStatics"] as List <CartasDTO>;
            ctrImage            = Int32.Parse(ViewState["ctrImage"].ToString());
            ctrSoundTotal       = Int32.Parse(ViewState["ctrSoundTotal"].ToString());
            arrCardsTablero     = ViewState["arrCardsTablero"] as ArrayList;
            ctrSort             = Int32.Parse(ViewState["ctrSort"].ToString());
            ctrTotalCorrect     = Int32.Parse(ViewState["ctrTotalCorrect"].ToString());
            ctrTotalIncorrect   = Int32.Parse(ViewState["ctrTotalIncorrect"].ToString());
            ctrTotalCardsPlayer = Int32.Parse(ViewState["ctrTotalCardsPlayer"].ToString());
        }

        redrawBoard();
    }
コード例 #4
0
    /// <summary>
    /// Set a new random card from the cards available into the Tablero, and set the initial default values
    /// </summary>
    protected void setNewRandomCard()
    {
        /*card to guess*/

        int randomNum;

        do
        {
            randomNum = ran.Next(sizeTablero * sizeTablero);
            //            if (usedCards.IndexOf(randomNum) == -1)
            int returnVal = usedCards.IndexOf((arrCardsTablero[randomNum] as CartasDTO).ID);
            if (returnVal == -1 && !isGameFinished)//card not existing or isGameFinished is false
            {
                //set a new random card
                cardAtHand = (arrCardsTablero[randomNum] as CartasDTO);
                //if (isHard && cardAtHand.Frases.ToArray().Length >= 1)
                if (isHard && arrFrasesTablero.ElementAt(randomNum).Value >= 1)
                {
                    //if cards help disabled (hard mode), then use frases
                    //AND there is at least one Frase for the card

                    /*todo: move this code to the setCardsTablero function to add in parallel to the
                     * available cards at random the Frase instead here because this causes problems with the saving in the other todo*/
                    /*int tmpRandNum = ran.Next(cardAtHand.Frases.ToArray().Length);
                     * lblCardAtHand.Text = cardAtHand.Frases.ToArray().ElementAt(tmpRandNum).Key;
                     * fraseAtHandID = cardAtHand.Frases.ToArray().ElementAt(tmpRandNum).Value;*/
                    lblCardAtHand.Text = arrFrasesTablero.ElementAt(randomNum).Key;
                    fraseAtHandID      = arrFrasesTablero.ElementAt(randomNum).Value;
                }
                else
                {
                    //help is enabled AND/OR there are no more than 1 Frases for the card
                    lblCardAtHand.Text = cardAtHand.Name;
                    fraseAtHandID      = 0;
                }
                imgCardAtHand.ImageUrl     = cardAtHand.Path;
                imgCardAtHand.Visible      = false;
                ViewState["fraseAtHandID"] = fraseAtHandID;
                ViewState["cardAtHand"]    = cardAtHand;
                ViewState["ctrImage"]      = ctrImage;

                cardStatics.Add(cardAtHand);
                ViewState["cardStatics"] = cardStatics;
                if (!isHard)
                {
                    imgBtnShowImage.Enabled = true;
                    imgBtnShowImage.Visible = true;
                }
                hdnUsedSound.Value = "0";
                break;
            }
            else
            {
                if (usedCards.ToArray().Length >= (sizeTablero * sizeTablero) || isGameFinished)//game is ended?
                {
                    imgBtnShowImage.Enabled = false;
                    imgBtnMakeNoise.Enabled = false;
                    lblGameFinished.Visible = true;

                    int gameID = loteria.insertGameInfo(JugadorID,
                                                        DateTime.Now, ctrTotalCorrect, ctrTotalIncorrect,
                                                        ((double)ctrTotalCorrect) / ((double)ctrTotalCardsPlayer) * 10.0, //grade
                                                        ctrTotalCardsPlayer, isHard, ctrSoundTotal);
                    if (gameID >= 1)
                    {
                        for (int i = 0; i < cardStatics.ToArray().Length; i++)
                        //foreach(CartasDTO carta in cardStatics)
                        {
                            CartasDTO carta = cardStatics.ToArray().ElementAt(i);
                            loteria.insertGameDetails(gameID, usedCards[i], carta.UsedSound, carta.UsedImage,
                                                      carta.GuessedCorrectly, usedFrases.ElementAt(i).Value);
                        }

                        ScriptManager.RegisterStartupScript(Page, Page.GetType(), "popup",
                                                            "window.open('" + "Recompensa.aspx?total=" + (sizeTablero * sizeTablero) + "&correct=" + ctrTotalCorrect + "','_blank', " +
                                                            "'width=250,height=350,toolbar=no,location = no,status = no," +
                                                            "menubar = no,scrollbars = yes,resizable = yes,width = SomeSize,height = SomeSize')", true);
                    }
                    else
                    {
                        //problem when trying to save the game, let them know
                        lblGameFinished.Text = "Ha habido algun problema, contacta al administrador";
                    }

                    break;
                }
            }
        } while (true);
    }
コード例 #5
0
    protected void Page_Load(object sender, EventArgs e)
    {
        Int32.TryParse(Request.QueryString["size"], out sizeTablero);
        //isHard = Request.QueryString["hard"].Equals("True") ? true : false;
        Boolean.TryParse(Request.QueryString["hard"], out isHard);
        if (!IsPostBack)
        {
            /*ctrCardsRemaining = sizeTablero * sizeTablero;
             * ViewState["ctrCardsRemaining"] = sizeTablero* sizeTablero;*/


            if (isHard)
            {
                imgBtnShowImage.Visible = false;
            }

            /*Load cards data*/
            arrCardsAvailable.Add(new CartasDTO(1, "Elefante", "~/images/fijo/elefante.jpg", "El Elefante tiene orejas grandes", 1));
            arrCardsAvailable.Add(new CartasDTO(2, "Delfín", "~/images/fijo/delfin.jpg", "El Delfín nada rápido", 2));
            arrCardsAvailable.Add(new CartasDTO(3, "Gato", "~/images/fijo/gato.jpg", "El Gato maulla", 5));
            arrCardsAvailable.Add(new CartasDTO(4, "León", "~/images/fijo/leon.jpg", "El León es el rey de la sabana", 6));
            arrCardsAvailable.Add(new CartasDTO(5, "Oveja", "~/images/fijo/oveja.jpg", "La oveja esta cubierta de lana", 5));
            arrCardsAvailable.Add(new CartasDTO(6, "Perro", "~/images/fijo/perro.jpg", "Al Perro le gustan los huesos", 4));
            arrCardsAvailable.Add(new CartasDTO(7, "Puerco", "~/images/fijo/puerco.jpg", "El Puerco esta gordito", 9));
            arrCardsAvailable.Add(new CartasDTO(8, "Rana", "~/images/fijo/rana.jpg", "La Rana hace ribit", 3));
            arrCardsAvailable.Add(new CartasDTO(9, "Tortuga", "~/images/fijo/tortuga.gif", "La tortuga camina lento", 7));


            /*Set the available cards to be used in the board*/
            setCardsTablero();

            /*card to guess*/
            setNewRandomCard();

            /*
             * Random ran = new Random();
             * int randomNum = ran.Next(sizeTablero* sizeTablero-1);
             * //int randomNum = ran.Next(((int)ViewState["ctrCardsRemaining"]) - 1);
             * cardAtHand = (arrTablero[randomNum] as CartasDTO);
             * lblCardAtHand.Text = cardAtHand.Name;
             * //arrTablero.RemoveAt(randomNum);
             * //ctrCardsRemaining -= 1;*/

            ViewState["arrTablero"] = arrCardsAvailable;

            ViewState["usedCards"]       = usedCards;
            ViewState["cardStatics"]     = cardStatics;
            ViewState["ctrSoundTotal"]   = ctrSoundTotal;
            ViewState["arrCardsTablero"] = arrCardsTablero;
            ViewState["ctrSort"]         = ctrSort;
            ViewState["ctrTotalCorrect"] = ctrTotalCorrect;
        }
        else
        {
            arrCardsAvailable = ViewState["arrTablero"] as ArrayList;
            cardAtHand        = ViewState["cardAtHand"] as CartasDTO;
            usedCards         = ViewState["usedCards"] as List <int>;
            cardStatics       = ViewState["cardStatics"] as List <CartasDTO>;
            ctrImage          = Int32.Parse(ViewState["ctrImage"].ToString());
            ctrSoundTotal     = Int32.Parse(ViewState["ctrSoundTotal"].ToString());
            arrCardsTablero   = ViewState["arrCardsTablero"] as ArrayList;
            ctrSort           = Int32.Parse(ViewState["ctrSort"].ToString());
            ctrTotalCorrect   = Int32.Parse(ViewState["ctrTotalCorrect"].ToString());
            //todo: show results as variable for testing
            //tbTablero = ViewState["tbTablero"] as Table;
        }

        redrawBoard();

        //tbTablero.Rows.Add(new TableRow());
        //tbTablero.Width = new Unit("800px");



        //ViewState["ctrCardsRemaining"] = (((int)ViewState["ctrCardsRemaining"]) - 1);
        //Session["tablero"] = tbTablero;

        /*}
         * else
         * {
         *  tbTablero = Session["tablero"] as Table;
         * }*/
    }