Quantcast
Channel: SCN: Message List
Viewing all articles
Browse latest Browse all 3019

Managed rules for an SAPUI5 Tic Tac Toe

$
0
0

Hi,

I tried to develop an SAPUI5 Tic Tac Toe, to learn JavaScript. I can play to the game, but I can write in only one input and not in all. How can I do to can write in the 9 inputs before finish a game please?

 

jouer:function(oEvent)

    {   

        var oValue = oEvent.getParameter("value");

        //var nombreTours = 0;

        var i;

        var x = 0;

        var y = 0;

        var gagne = false;

       

        for(var nombreTours = 0; nombreTours <= 9; nombreTours+=1)

        {   

            switch(oValue)

            {

                case "o":

                    oValue = "o";

                    break;

                case "O":

                    oValue = "O";

                    break;

                case "x":

                    oValue = "x";

                    break;

                case "X":

                    oValue = "X";

                    break;

                default:

                    break;

            }

            oData[x][y] = oValue;

           

            for(i = 0; i < 3; i++)

            {   

                if(oData[i][0] != " " && oData[i][0] == oData[i][1] && oData[i][0] == oData[i][2])

                {

                    gagne = true;

                }

            }

           

            for(i = 0; i < 3; i++)

            {

                if(oData[0][i] != " " && oData[0][i] == oData[1][i] && oData[0][i] == oData[2][i])

                {

                    gagne = true;

                }

            }

           

            if(oData[1][1] != " " && ((oData[0][0] == oData[1][1] && oData[0][0] == oData[2][2])

                || (oData[0][2] == oData[1][1] && oData[0][2] == oData[2][0])))

            {

                gagne = true;

            }

        }

       

        if(gagne && ((oValue == "o") || (oValue =="O") || (oValue == "x") || (oValue == "X")))

        {

            alert(oValue + " a gagné");

        }

        else if(oValue != "o" && oValue != "O" && oValue != "x" && oValue != "X")

        {

            alert("Veuillez saisir O/o ou X/x");

        }

        else

        {

            alert("Personne ne gagne");

        }

    },

 

 

 

Best regards,

Ewen.


Viewing all articles
Browse latest Browse all 3019

Trending Articles



<script src="https://jsc.adskeeper.com/r/s/rssing.com.1596347.js" async> </script>