HTML/Javascript Bulls and Cows Game Mobile Tutorial
โœ‚๐Ÿƒ๐Ÿพโ€โ™€๏ธ๐Ÿƒ๐Ÿผโ€โ™‚๏ธ
๐Ÿ“–

HTML/Javascript Bulls and Cows Game Mobile Tutorial

HTML/Javascript Bulls and Cows Game Mobile Tutorial

With yesterdayโ€™s HTML/Javascript Bulls and Cows Game Primer Tutorial we separated โ€ฆ

  • player 1 using mouse (or touch)
  • player 2 on keyboard

โ€ฆ as the arrangement for two players to use the one computer, playing our Bullsโœ‚and Cows game. But what if that โ€œcomputerโ€ is a mobile device? You canโ€™t decouple โ€œtouchโ€ from โ€œkeyboardโ€ using a mobile device. Youโ€™ll notice writing web applications for mobile devices, their reticence to allow you to programmatically focus to HTML elements. A lot of this would have to be to do with how the keyboard is presented to a mobile user (usually only) when they deliberately focus onto a textbox through a human action, not as readily via a programmatical action.

Does this ruin our game premise, for mobile devices? Well, itโ€™s not as strong, but it still works. It can be a better user experience, though, attending to โ€ฆ

  • CSS tweaks โ€ฆ
    <style>


    input[type=password] { font-size: 24px; }




    @media only screen and (min-device-width: 320px) and (max-device-width: 765px) and (orientation: portrait) {

    .tablek { text-align: right; }

    .tablem { text-align: left; }

    #pwd1 { width:50%; text-align:right; }

    #pwd2 { width:50%; text-align:left; }


    input[type=password] { font-size: 24px; }

    }




    @media only screen and (min-device-width: 320px) and (max-device-width: 765px) and (orientation: landscape) {

    .tablek { text-align: right; }

    .tablem { text-align: left; }

    #pwd1 { width:50%; text-align:right; }

    #pwd2 { width:50%; text-align:left; }


    input[type=password] { font-size: 24px; }

    }


    </style>
  • text-align settings to help with the narrower devices โ€ฆ
  • Javascript use of [element].scrollIntoView() โ€ฆ


    function postsiv() {

    document.getElementById('tcell').scrollIntoView();

    }



    function siv() {

    if (navigator.userAgent.match(/Android|BlackBerry|iPhone|iPJUNKad|iPod|Opera Mini|IEMobile/i)) {

    setTimeout(postsiv, 2000); //document.getElementById('tcell').scrollIntoView(); //versus=versus;

    }

    }


    โ€ฆ called via tweaked HTML โ€ฆ


    <input onblur="vstwo=this.value; assesstwo();" onkeydown=pwdonkd(event); type=password id=pwd2 onfocus=siv(); value=''></input>

  • programmatic focus restrictions for mobile devices โ€ฆ


    function pfocus() {

    if (navigator.userAgent.match(/Android|BlackBerry|iPhone|iPJUNKad|iPod|Opera Mini|IEMobile/i)) {

    document.getElementById('tablel').style.align='right'; //versus=versus;

    } else {

    document.getElementById('pwd2').focus();

    }

    }

  • have a set of backup placeholder arrangements in that middle cell of the 3 column table โ€ฆ


    var versus="", fgo=true; // global variable initialization ... and then later within the document.body onload linking Javascript function ...



    if (fgo && versus == "") {

    if (document.getElementById('player1').placeholder != '' && document.getElementById('splayer1').innerHTML == 'Player 1 Name') { document.getElementById('splayer1').innerHTML=document.getElementById('player1').placeholder; }

    if (document.getElementById('player2').placeholder != '' && document.getElementById('splayer2').innerHTML == 'Player 2 Name') { document.getElementById('splayer2').innerHTML=document.getElementById('player2').placeholder; }

    if (document.getElementById('player1').placeholder == '') { document.getElementById('player1').placeholder=document.getElementById('player1').value; document.getElementById('splayer1').innerHTML=document.getElementById('player1').value; document.getElementById('player1').value=''; }

    if (document.getElementById('player2').placeholder == '') { document.getElementById('player2').placeholder=document.getElementById('player2').value; document.getElementById('splayer2').innerHTML=document.getElementById('player2').value; document.getElementById('player2').value=''; }

    }


    โ€ฆ because with the narrower devices the extra textbox view of the emoji Bulls and Cows in the middle can help out the qwerty button pressing users

โ€ฆ in thechanged second draft bullsandcowsโšซhtmlโ€˜s Bullsโœ‚and Cows game you can also try below.



Previous relevant HTML/Javascript Bulls and Cows Game Primer Tutorial is shown below.

HTML/Javascript Bulls and Cows Game Primer Tutorial

HTML/Javascript Bulls and Cows Game Primer Tutorial

Today weโ€™ve got an inhouse version of a well known word (but you donโ€™t have to be a wordsmith to play) game called Bulls and Cows which we used to play in lunchtimes at school, a bit like the Word Guessing game of Word Guessing or Synonym Game Right Click Tutorial times past.

Again, best as a game for two โ€ฆ

This game, which can also be called โ€œMastermindโ€ or โ€œJottoโ€ involves one player thinking up a secret word of a set number of letters. The second player guesses a word; the first player tells them how many letters match in the right position (bulls) and how many letters are correct but in the wrong position (cows).

โ€ฆ that we encourage players to play around the one computer, where one player is at a mouse (or touch) and one is on the keyboard, trying to guess the same computer generated (rather than โ€œthe other player settingโ€) 4 to 9 length English word.

Feel free to try our first draft bullsandcowsโšซhtml Bullsโœ‚and Cows game you can try in a new window, or below โ€ฆ

If this was interesting you may be interested in this too.


If this was interesting you may be interested in this too.

This entry was posted in eLearning, Event-Driven Programming, Tutorials and tagged , , , , , , , , , , , , , , , , , , , , , . Bookmark the permalink.

Leave a Reply

Your email address will not be published. Required fields are marked *