Common.js: Difference between revisions
From Necroxia Origin
mNo edit summary |
mNo edit summary |
||
Line 26: | Line 26: | ||
function getPossibleTeleports(currentRoom, currentCount, answerNumberIni) { | function getPossibleTeleports(currentRoom, currentCount, answerNumberIni) { | ||
var isPossible = false; | |||
var a = 0; | |||
var b = 0; | |||
var c = 0; | |||
var outputText = ''; | |||
var roomsLeft = totalRooms - currentRoom; | |||
var answerNumber = answerNumberIni - currentCount; | |||
if (validateValues(roomsLeft, answerNumber, currentRoom, currentCount, answerNumberIni)){ | if (validateValues(roomsLeft, answerNumber, currentRoom, currentCount, answerNumberIni)){ |
Revision as of 09:52, 1 September 2020
/* Any JavaScript here will be loaded for all users on every page load. */ $("#testdiv").each(function() { var parent = $(this); //var inputs = ['currentRoom', 'currentCount', 'answerNumber']; var inputs = [ ['currentRoom', 1, 32, 1, 'Escribe aqui el numero de la habitacion en que te encuentras:'], ['currentCount', 0, 999, 0,'Escribe aqui tu cuenta actual:'], ['answerNumber', 31, 93, 77,'Escribe aqui el numero al que necesitas llegar:'] ]; var textToPrint = ""; //var d = document.createElement('div'); $(this).append("<table id='table1'></table>"); for (i = 0; i < inputs.length; i++) { $('#table1').append("<tr><td>"+inputs[i][4]+"</td><td><input type='number' id='" + inputs[i][0] + "' name='"+inputs[i][0]+"' min='"+inputs[i][1]+"' max='"+inputs[i][2]+"' value='"+inputs[i][3]+"' maxLength='4' style='width:70px'/></td></tr>"); //$(this).append("<input type='number' id='" + inputs[i][0] + "' name='"+inputs[i][0]+"' min='"+inputs[i][1]+"' max='"+inputs[i][2]+"' value='"+inputs[i][3]+"' maxLength='4' style='width:70px'/>"); $(this).append("<br> id="+inputs[i][0]+" name="+inputs[i][0]+" min="+inputs[i][1]+" max="+inputs[i][2]+" value="+inputs[i][3]); } $(this).append("<button id='button1'>getChance</button>"); $('#button1').click( function() { textToPrint = getPossibleTeleports( $('#currentRoom').val(), $('#currentCount').val(), $('#answerNumber').val()); }); //var currentRoom = $('#currentRoom').val(); $(this).append("<br>"+currentRoom); $(this).append("<br> " + $("input[id=currentRoom]").value); }); function getPossibleTeleports(currentRoom, currentCount, answerNumberIni) { var isPossible = false; var a = 0; var b = 0; var c = 0; var outputText = ''; var roomsLeft = totalRooms - currentRoom; var 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; }