{"id":144,"date":"2015-02-19T00:04:56","date_gmt":"2015-02-19T00:04:56","guid":{"rendered":"http:\/\/insia.wordpress.forinsia.com\/comacesso\/?page_id=144"},"modified":"2020-09-14T23:38:12","modified_gmt":"2020-09-14T23:38:12","slug":"adivinhar-numeros-1-a-10","status":"publish","type":"page","link":"https:\/\/sites.ipleiria.pt\/comAcesso\/biblioteca\/jogos\/adivinhar-numeros-1-a-10\/","title":{"rendered":"Adivinhar n\u00fameros 1 a 10"},"content":{"rendered":"\n<p>Jogo de adivinhar n\u00fameros de 1 a 10.<\/p>\n\n\n\n<p>Instru\u00e7\u00f5es: Neste jogo tem de adivinhar um n\u00famero entre 1 e 10. Insira um n\u00famero na caixa de edi\u00e7\u00e3o e pressione &#8220;Enter&#8221; ou o bot\u00e3o &#8220;Verificar resposta&#8221; para submeter a resposta.<br>Uma mensagem de alerta anuncia e mostra os resultados da sua aposta. Para voltar a jogar pressione o bot\u00e3o &#8220;Jogar novamente&#8221;.<\/p>\n\n\n\n<section class=\"game-wrapper\" aria-live=\"polite\" aria-busy=\"true\">\n  <div id=\"loading\">A carregar&#8230;<\/div>\n  <div id=\"guess1\" class=\"guess game\" style=\"display: none;\">\n    <p class=\"input\">\n        <label id=\"guess1_label\" for=\"guess1_text\">Escolha um n\u00famero entre 1 e 10<\/label>\n        <input type=\"text\" id=\"guess1_text\" size=\"5\" aria-labelledby=\"guess1_label\" aria-invalid=\"false\">\n    <\/p>\n    <p class=\"input\">\n        <button class=\"button btn btn-primary mr-2\" id=\"guess1_check\">Verificar resposta<\/button><button class=\"button btn btn-secondary\" id=\"guess1_again\" type=\"button\">Jogar novamente<\/button>\n    <\/p>\n    <p id=\"guess1_alert\" role=\"alert\" class=\"feedback alert alert-info font-weight-bold\"><\/p>\n  <\/div>\n<\/section>\n<script>\n    window.addEventListener(\"load\", function() {\n        (function($) {\n            if ($ === false) {\n                return false;\n            }\n            document.querySelector(\"#loading\").remove();\n            document.querySelector(\".game-wrapper>.game\").style.display='block';\n            document.querySelector(\".game-wrapper\").setAttribute(\"aria-busy\", false);\n\n            \/\/ GAME START\n            \/\/\n            \/\/ @param (max integer) min is the maximum number to guess.\n            \/\/\n            \/\/ @param (text_id string) text_id is the id of the text box where player enters a guess.\n            \/\/\n            \/\/ @param (check_id string) check_id is the id of the check guess button.\n            \/\/\n            \/\/ @param (again_id string) again_id is the id of the play again button.\n            \/\/\n            \/\/ @param (alert_id string) alert_id is the id of the alert element where game messages will\n            \/\/ be printed.\n            \/\/\n            \/\/ @return N\/A\n            \/\/\n            function guess(min, max, text_id, check_id, again_id, alert_id) {\n\n                \/\/ define class properties\n                this.minGuess = min; \/\/ the minimum number to guess\n                this.maxGuess = max; \/\/ the maximum number to guess\n                this.$text = $('#' + text_id); \/\/ the jQuery object pointer to the text box\n                this.$check = $('#' + check_id); \/\/ the jQuery object pointer to the check guess button\n                this.$again = $('#' + again_id); \/\/ the jQuery object pointer to the play again button\n                this.$alert = $('#' + alert_id); \/\/ the jQuery object pointer to the alert area\n\n                this.guessVal = -1; \/\/ the number for the player to guess\n                this.guessCount = 0; \/\/ the number of attempts the player has made\n\n                this.enterKey = 13; \/\/ key code for the enter key\n\n                \/\/ bind event handlers\n                this.bindHandlers();\n\n                \/\/ initialize the game\n                this.newGame();\n\n            } \/\/ end guess object constructor\n\n            \/\/\n            \/\/ newGame() is a member function to set up a new game. The function chooses a number\n            \/\/ between 1 and the max number specified at instantiation, sets the guess count to 0, and\n            \/\/ show the user a message to make a guess.\n            \/\/\n            \/\/ @return N\/A\n            guess.prototype.newGame = function() {\n\n                \/\/ get a new random number for the player to guess\n                this.guessVal = Math.floor(Math.random() * (this.maxGuess - this.minGuess + 1)) + this.minGuess;\n\n                \/\/ reset the guess count\n                this.guessCount = 0;\n\n                \/\/ reset the guess text box\n                this.$text.val('');\n                this.$text.attr('aria-invalid', 'false');\n\n                \/\/ Re-enable the buttons\n                this.$text.removeAttr('disabled');\n                this.$check.removeAttr('disabled');\n\n                \/\/ invite the user to make a guess\n                this.$alert.text('Fa\u00e7a uma aposta.');\n\n                \/\/ set focus on the guest text box\n                this.$text.focus();\n\n            } \/\/ end newGame\n\n            \/\/\n            \/\/ bindHandlers() is a function to bind the event handlers for the game controls\n            \/\/\n            \/\/ @return N\/A\n            \/\/\n            guess.prototype.bindHandlers = function() {\n                var thisObj = this; \/\/ Store the this pointer\n                \/\/ bind a focus handler for the guess text box\n                this.$text.focus(function(e) {\n                    thisObj.handleTextFocus(e);\n                    return true;\n                });\n\n                \/\/ bind a keydown handler for the guess text box\n                this.$text.keydown(function(e) {\n                    return thisObj.handleTextKeyDown(e);\n                });\n\n                \/\/ bind a keypress handler for the guess text box\n                this.$text.keypress(function(e) {\n                    return thisObj.handleTextKeyPress(e);\n                });\n\n                \/\/ bind a click handler for the check guess button\n                this.$check.click(function(e) {\n                    return thisObj.handleCheckClick(e);\n                });\n\n                \/\/ bind a click handler for the play again button\n                this.$again.click(function(e) {\n                    return thisObj.handleAgainClick(e);\n                });\n\n            } \/\/ end bindHandlers()\n\n            \/\/\n            \/\/ handleTextFocus() is a member function to process focus events for the guess text box\n            \/\/\n            \/\/ @input (evt obj) evt is the event object associated with the keydown event\n            \/\/\n            \/\/ @return N\/A\n            \/\/\n            guess.prototype.handleTextFocus = function(evt) {\n\n                \/\/ Select any text in the text box\n                this.$text.select();\n\n            } \/\/ end handleTextFocus()\n\n            \/\/\n            \/\/ handleTextKeyDown() is a member function to process keydown events for the guess text box\n            \/\/\n            \/\/ @input (evt obj) evt is the event object associated with the keydown event\n            \/\/\n            \/\/ @return (boolean) false if consuming event, true if propagating\n            \/\/\n            guess.prototype.handleTextKeyDown = function(evt) {\n\n                \/\/ do nothing if shift, alt, or ctrl key pressed.\n                if (evt.shiftKey || evt.altKey || evt.ctrlKey) {\n                    return true;\n                }\n\n                if (evt.keyCode == this.enterKey) {\n\n                    \/\/ validate the guess\n                    if (this.validateGuess() == true) {\n\n                        \/\/ increment the guess count\n                        this.guessCount++;\n\n                        \/\/ see if the player has won\n                        if (this.checkGuess() == true) {\n                            \/\/ disable the guess text box and the check guess button\n                            this.$text.attr('disabled', 'true');\n                            this.$check.attr('disabled', 'true');\n\n                            \/\/ Set the focus on the play again button\n                            this.$again.focus();\n                        } else {\n                            \/\/ Game is still in progress. Set focus on the guess text box\n                            this.$text.focus();\n                        }\n                    } else {\n                        \/\/ not a valid guess\n                        this.$text.focus();\n                    }\n\n                    evt.stopPropagation;\n                    return false;\n                }\n\n                return true;\n\n            } \/\/ end handleTextKeyDown()\n\n            \/\/\n            \/\/ handleTextKeyPress() is a member function to process keypress events for the guess text box. This function\n            \/\/ is included to handle browsers that perform window scrolling, etc. on keypress rather than keydown.\n            \/\/\n            \/\/ @input (evt obj) evt is the event object associated with the keypress event\n            \/\/\n            \/\/ @return (boolean) false if consuming event, true if propagating\n            \/\/\n            guess.prototype.handleTextKeyPress = function(evt) {\n\n                \/\/ do nothing if shift, alt, or ctrl key pressed.\n                if (evt.shiftKey || evt.altKey || evt.ctrlKey) {\n                    return true;\n                }\n\n                if (evt.keyCode == this.enterKey) {\n\n                    \/\/ consume the event\n                    evt.stopPropagation;\n                    return false;\n                }\n\n                return true;\n\n            } \/\/ end handleTextKeyPress()\n\n            \/\/\n            \/\/ handleCheckClick() is a member function to process click events for the check guess button\n            \/\/\n            \/\/ @input (evt obj) evt is the event object associated with the click event\n            \/\/\n            \/\/ @return (boolean) false if consuming event, true if propagating\n            \/\/\n            guess.prototype.handleCheckClick = function(evt) {\n\n                \/\/ do nothing if shift, alt, or ctrl key pressed.\n                if (evt.shiftKey || evt.altKey || evt.ctrlKey) {\n                    return true;\n                }\n\n                \/\/ validate the guess\n                if (this.validateGuess() == true) {\n\n                    \/\/ increment the guess count\n                    this.guessCount++;\n\n                    \/\/ see if the player has won\n                    if (this.checkGuess() == true) {\n                        \/\/ disable the guess text box and the check guess button\n                        this.$text.attr('disabled', 'true');\n                        this.$check.attr('disabled', 'true');\n\n                        \/\/ Set the focus on the play again button\n                        this.$again.focus();\n                    } else {\n                        \/\/ Game is still in progress. Set focus on the guess text box\n                        this.$text.focus();\n                    }\n                } else {\n                    \/\/ not a valid guess\n                    this.$text.focus();\n                }\n\n                evt.stopPropagation;\n                return false;\n\n            } \/\/ end handleCheckClick()\n\n            \/\/\n            \/\/ handleAgainClick() is a member function to process click events for the play again button\n            \/\/\n            \/\/ @input (evt obj) evt is the event object associated with the click event\n            \/\/\n            \/\/ @return (boolean) false if consuming event, true if propagating\n            \/\/\n            guess.prototype.handleAgainClick = function(evt) {\n\n                \/\/ do nothing if shift, alt, or ctrl key pressed.\n                if (evt.shiftKey || evt.altKey || evt.ctrlKey) {\n                    return true;\n                }\n\n                \/\/ Setup a new game\n                this.newGame();\n\n                \/\/ Set focus to the guess text box\n                this.$text.focus();\n\n                evt.stopPropagation;\n                return false;\n\n            } \/\/ end handleTextKeyDown()\n\n            \/\/\n            \/\/ validateGuess() is a member function to validate a player's guess. If the guess is not a number, is less than\n            \/\/ the minimum allowed guess, or is greater than the maximum allowed guess, the user is warned that the guess is invalid\n            \/\/\n            \/\/ @return (boolean) true if guess is valid; false if guess is invalid\n            \/\/\n            guess.prototype.validateGuess = function() {\n                var val = this.$text.val();\n\n                if (this.$text.val() == '') {\n                    \/\/ guess is empty\n                    this.$text.attr('aria-invalid', 'true');\n                    this.$alert.html('Tem de inserir um n\u00famero!');\n\n                    return false;\n                } else if (isNaN(val) == true) {\n\n                    \/\/ guess is not a number\n                    this.$text.attr('aria-invalid', 'true');\n                    this.$alert.html('\\'' + this.$text.val() + '\\' n\u00e3o \u00e9 um n\u00famero!');\n\n                    return false;\n                } else if (val < this.minGuess || val > this.maxGuess) {\n\n                    \/\/ guess is out of range\n                    this.$text.attr('aria-invalid', 'true');\n                    this.$alert.html('Tem de escolher um n\u00famero entre ' + this.minGuess + ' e ' + this.maxGuess + '!');\n\n                    return false;\n                }\n\n                this.$text.attr('aria-invalid', 'false');\n\n                return true;\n\n            } \/\/ end validateGuess()\n\n            \/\/\n            \/\/ checkGuess() is a member function to check the player's guess to see if he or she has won the game\n            \/\/\n            \/\/ @return (boolean) true if the player has won; false if not\n            guess.prototype.checkGuess = function() {\n\n                var guess = this.$text.val();\n\n                if (guess == this.guessVal) {\n\n                    \/\/ The player has won. Tell the player how many tries it took\n\n                    if (this.guessCount == 1) {\n                        this.$alert.html('\\'' + guess + '\\' Certo. Acertou logo na primeira tentativa!');\n                    } else {\n                        this.$alert.html('\\'' + guess + '\\' Certo. Conseguiu adivinhar em ' + this.guessCount + ' tentativas!');\n                    }\n                    return true;\n                }\n\n                \/\/ Player did not guess the correct number. Tell the player if he or she is too high or too low\n                if (guess < this.guessVal) {\n                    this.$alert.html('\\'' + guess + '\\' \u00e9 muito baixo. Tente um n\u00famero mais alto.');\n                } else {\n                    this.$alert.html('\\'' + guess + '\\' \u00e9 muito alto. Tente um n\u00famero mais baixo.');\n                }\n\n                return false;\n\n            } \/\/ end checkGuess()\n            $(document).ready(function() {\n                var guess1 = new guess(1, 10, 'guess1_text', 'guess1_check', 'guess1_again', 'guess1_alert');\n            });\n        })(jQuery || false);\n    });\n<\/script>\n<noscript>\n<div class=\"alert alert-warning\" role=\"alert\">N\u00e3o \u00e9 poss\u00edvel jogar este jogo sem suporte para JavaScript!<\/div>\n<\/noscript>\n","protected":false},"excerpt":{"rendered":"Jogo de adivinhar n\u00fameros de 1 a 10. Instru\u00e7\u00f5es: Neste jogo tem de adivinhar um n\u00famero entre 1 e 10. Insira um n\u00famero na caixa de edi\u00e7\u00e3o e pressione &#8220;Enter&#8221; ou o bot\u00e3o &#8220;Verificar resposta&#8221; para submeter a resposta.Uma mensagem de alerta anuncia e mostra os resultados da sua aposta. Para voltar a jogar pressione [&hellip;]","protected":false},"author":539,"featured_media":0,"parent":142,"menu_order":0,"comment_status":"closed","ping_status":"closed","template":"","meta":{"footnotes":""},"class_list":["post-144","page","type-page","status-publish","hentry"],"_links":{"self":[{"href":"https:\/\/sites.ipleiria.pt\/comAcesso\/wp-json\/wp\/v2\/pages\/144","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/sites.ipleiria.pt\/comAcesso\/wp-json\/wp\/v2\/pages"}],"about":[{"href":"https:\/\/sites.ipleiria.pt\/comAcesso\/wp-json\/wp\/v2\/types\/page"}],"author":[{"embeddable":true,"href":"https:\/\/sites.ipleiria.pt\/comAcesso\/wp-json\/wp\/v2\/users\/539"}],"replies":[{"embeddable":true,"href":"https:\/\/sites.ipleiria.pt\/comAcesso\/wp-json\/wp\/v2\/comments?post=144"}],"version-history":[{"count":22,"href":"https:\/\/sites.ipleiria.pt\/comAcesso\/wp-json\/wp\/v2\/pages\/144\/revisions"}],"predecessor-version":[{"id":437,"href":"https:\/\/sites.ipleiria.pt\/comAcesso\/wp-json\/wp\/v2\/pages\/144\/revisions\/437"}],"up":[{"embeddable":true,"href":"https:\/\/sites.ipleiria.pt\/comAcesso\/wp-json\/wp\/v2\/pages\/142"}],"wp:attachment":[{"href":"https:\/\/sites.ipleiria.pt\/comAcesso\/wp-json\/wp\/v2\/media?parent=144"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}