Skip to content

Commit

Permalink
Fix thomaspark#193. Add short answers. Improve auto clicking of the N…
Browse files Browse the repository at this point in the history
…ext button.
  • Loading branch information
glebkema committed Oct 19, 2020
1 parent 3350560 commit 054f3e9
Show file tree
Hide file tree
Showing 2 changed files with 15 additions and 7 deletions.
20 changes: 13 additions & 7 deletions js/game.js
Original file line number Diff line number Diff line change
Expand Up @@ -69,20 +69,25 @@ var game = {
return;
}

var max = $(this).data('lines');
var max = $(this).data('max');
var min = $(this).data('min');
var code = $(this).val();
var trim = code.trim();
var codeLength = code.split('\n').length;
var trimLength = trim.split('\n').length;

if (codeLength >= max) {
if (codeLength >= min) {

if (codeLength === trimLength) {
if (! $('#next').hasClass('disabled')) {
e.preventDefault();
$('#next').click();
} else {
$('#code').focus().val('').val(trim);
return;
}

if (trimLength >= max) {
e.preventDefault();
}
$('#code').focus().val('').val(trim);
}
}
}).on('input', game.debounce(game.check, 500))
Expand Down Expand Up @@ -125,7 +130,7 @@ var game = {
var $instructions = $('#instructions');
var height = $instructions.height();
$instructions.css('height', height);

if (game.difficulty == 'hard' || game.difficulty == 'medium') {
$instructions.slideUp();
} else {
Expand Down Expand Up @@ -264,7 +269,8 @@ var game = {
this.loadDocs();

var lines = Object.keys(level.style).length;
$('#code').height(20 * lines).data("lines", lines);
var min = level.styleShort ? Object.keys(level.styleShort).length : lines;
$('#code').height(20 * lines).data('max', lines).data('min', min);

var string = level.board;
var markup = '';
Expand Down
2 changes: 2 additions & 0 deletions js/levels.js

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

0 comments on commit 054f3e9

Please sign in to comment.