|
|
Line 24: |
Line 24: |
| $(this).append("<br> " + $("input[id=currentRoom]").value); | | $(this).append("<br> " + $("input[id=currentRoom]").value); |
| }); | | }); |
|
| |
| function getPossibleTeleports(currentRoom, currentCount, answerNumberIni) {
| |
| let isPossible = false;
| |
| let a = 0;
| |
| let b = 0;
| |
| let c = 0;
| |
| let outputText = '';
| |
| let roomsLeft = totalRooms - currentRoom;
| |
| let answerNumber = answerNumberIni - currentCount;
| |
|
| |
| if (validateValues(roomsLeft, answerNumber, currentRoom, currentCount, answerNumberIni)){
| |
| outputText = 'Not valid values: Los valores introducidos no son validos';
| |
| return outputText;
| |
| }
| |
| //if (isCorrect === false) {
| |
| //return true;
| |
| // getPossibleTeleports();
| |
| // }
| |
|
| |
| while (c <= roomsLeft) {
| |
| a = calculateA(answerNumber, roomsLeft, c);
| |
| b = calculateB(answerNumber, roomsLeft, c);
| |
| if (a !== -1 && b !== -1 && ((a + b + c) === roomsLeft) && ((a + (2 * b) + (3 * c)) === answerNumber)){
| |
| //outputText += 'sum1: ' + (a + b + c) + ' sum2: ' + (a + (2 * b) + (3 * c)) + ' -> a: ' + a + ', b: ' + b + ', c: ' + c + ' - Rooms: ' + roomsLeft + ', AnswerNumber: ' + answerNumber + '<br>';
| |
| //alert(`sum1: ` + (a + b + c) + ' sum2: ' + (a + (2 * b) + (3 * c)) + ` -> a: ` + a + `, b: ` + b + `, c: ` + c + ` - Rooms: ` + roomsLeft + `, AnswerNumber: ` + answerNumber);
| |
| isPossible = true;
| |
| break;
| |
| }
| |
| //console.log("sum1: ", (a + b + c), ", sum2: ", (a + (2 * b) + (3 * c))," -> a: ", a,", b: ", b,", c: ", c," - Rooms: ", roomsLeft, ", AnswerNumber: ", answerNumber);
| |
| //alert(`sum1: ` + (a + b + c) + ' sum2: ' + (a + (2 * b) + (3 * c)) + ` -> a: ` + a + `, b: ` + b + `, c: ` + c + ` - Rooms: ` + roomsLeft + `, AnswerNumber: ` + answerNumber);
| |
| c++;
| |
| }
| |
|
| |
| if (isPossible === true) {
| |
| outputText += 'Puedes tomar (' + a + ') veces el Teleport 1, (' + b + ') veces el Teleport 2, (' + c + ') veces el teleport 3.';
| |
| //alert(`Puedes tomar (` + a + `) veces T1, (` + b + `) veces T2, (` + c + `) veces T3.`);
| |
| } else {
| |
| outputText += 'Debes ir hasta el ultimo Teleport para reiniciar tu Cuenta, no es posible completar la Quest con tu cuenta actual.';
| |
| //alert(`no es posible, debes reiniciar tu cuenta ${c} !`);
| |
| }
| |
| //getPossibleTeleports();
| |
| // alert(`Existen en total ${totalRooms} habitaciones!`);
| |
| //document.getElementById("answer").innerHTML = outputText;
| |
| return outputText;
| |
| }
| |
|
| |
| function validateValues(roomsLeft, answerNumber, currentRoom, currentCount, answerNumberIni){
| |
| let isError = false;
| |
| let outputText = '';
| |
| if (currentRoom < 1) {
| |
| outputText += 'El numero de tu habitacion actual no puede ser menor a 1.<br>';
| |
| isError = true;
| |
| }
| |
|
| |
| if (currentRoom > totalRooms) {
| |
| outputText += 'El numero de tu habitacion actual no puede ser mayor a ' + totalRooms + '.<br>';
| |
| isError = true;
| |
| }
| |
|
| |
| if (currentCount < 0) {
| |
| outputText += 'Tu cuenta no puede ser menor a 0.<br>';
| |
| isError = true;
| |
| }
| |
|
| |
| if (answerNumber < 0) {
| |
| outputText += 'Tu cuenta es muy alta debes reiniciar.<br>';
| |
| isError = true;
| |
| }
| |
|
| |
| if (answerNumberIni < minCount) {
| |
| outputText += 'la cuenta total no puede ser menor a ' + minCount + '.<br>';
| |
| isError = true;
| |
| }
| |
|
| |
| if (answerNumberIni > maxCount) {
| |
| outputText += 'la cuenta total no puede ser mayor a ' + maxCount + '.<br>';
| |
| isError = true;
| |
| }
| |
|
| |
| if (isError) {
| |
| document.getElementById("answer").innerHTML = outputText;
| |
| }
| |
| return isError;
| |
| }
| |
|
| |
| function calculateA(answerNumber, roomsLeft, c){
| |
| let a = c + (2 * roomsLeft) - answerNumber;
| |
| //console.log(a, " = ", c , " + (2 * ", roomsLeft, ") - ",answerNumber)
| |
| if (a < 0 || a % 1 !== 0){
| |
| //console.log("a % 1 = ",a % 1);
| |
| return -1;
| |
| }
| |
| return a;
| |
| }
| |
|
| |
| function calculateB(answerNumber, roomsLeft, c){
| |
| let b = answerNumber - roomsLeft - (2 * c);
| |
| //console.log(b, " = ", answerNumber , " - ",roomsLeft ," - (2 * ", c, ")")
| |
| if (b < 0 || b % 1 !== 0){
| |
| //console.log("b % 1 = ",b % 1)
| |
| return -1;
| |
| }
| |
| return b;
| |
| }
| |