Skip to content

Commit 71e3e55

Browse files
authored
fix-row-column-limits (#193)
1 parent 391ae5e commit 71e3e55

File tree

3 files changed

+28
-17
lines changed

3 files changed

+28
-17
lines changed

README.md

+17-12
Original file line numberDiff line numberDiff line change
@@ -1,23 +1,28 @@
1-
Karel.js
2-
========
1+
# Karel.js
32

43
Compilador y evaluador de Karel en Javascript
54

65
## Cómo descargar Karel.js
76

8-
* Clona el repositorio en tu máquina usando
9-
`git clone https://github.com/omegaup/karel.js.git`.
10-
* Haz `git submodule update --init` al repo, para incluir CodeMirror en tu
11-
copia del proyecto.
7+
- Clona el repositorio en tu máquina usando
8+
`git clone https://github.com/omegaup/karel.js.git`.
9+
- Haz `git submodule update --init` al repo, para incluir CodeMirror en tu
10+
copia del proyecto.
1211

1312
## Cómo correr Karel.js en tu máquina
1413

15-
* `npm install && npm start`
14+
- `npm install && npm start`
1615

1716
## Cómo correr Karel.js de línea de comandos
1817

19-
* `sudo npm install -g`
20-
* `kareljs compile archivo.karel` compila el programa y genera un
21-
archivo `.kx`.
22-
* `kareljs run archivo.kx < entrada.in` ejecuta el programa con el mundo
23-
especificado por `entrada.in`.
18+
- `sudo npm install -g`
19+
- `kareljs compile archivo.karel` compila el programa y genera un
20+
archivo `.kx`.
21+
- `kareljs run archivo.kx < entrada.in` ejecuta el programa con el mundo
22+
especificado por `entrada.in`.
23+
24+
## Troubleshooting
25+
26+
- Si `npm install` marca error en la librería `node-canvas`, probablemente estés
27+
corriendo desde un OS que necesita instalar ciertas dependencias. Consulta la siguiente
28+
[documentación](https://github.com/Automattic/node-canvas?tab=readme-ov-file#compiling)

js/karel.js

+1-1
Original file line numberDiff line numberDiff line change
@@ -644,7 +644,6 @@ World.prototype.resize = function (w, h) {
644644
var oldW = self.w;
645645
var oldH = self.h;
646646
var oldMap = self.map;
647-
var oldCurrentMap = self.oldCurrentMap;
648647
var oldWallMap = self.wallMap;
649648
var oldDumpCells = self.dumpCells;
650649

@@ -1489,6 +1488,7 @@ World.prototype.errorMap = function (s) {
14891488
World.prototype.move = function (i, j) {
14901489
var self = this;
14911490

1491+
if (0 >= i || i > self.h || 0 >= j || j > self.w) return;
14921492
self.i = self.start_i = i;
14931493
self.j = self.start_j = j;
14941494
self.dirty = true;

js/main.js

+10-4
Original file line numberDiff line numberDiff line change
@@ -1227,8 +1227,10 @@ $(document).ready(function () {
12271227
wRender.moveSouth();
12281228
saveWorld = false;
12291229
} else if (currentCell && event.which >= 96 && event.which <= 105) {
1230+
// numpad 0 - numpad 9
12301231
mundo.setBuzzers(currentCell.row, currentCell.column, event.which - 96);
12311232
} else if (currentCell && event.which >= 48 && event.which <= 57) {
1233+
// 0 - 9
12321234
mundo.setBuzzers(currentCell.row, currentCell.column, event.which - 48);
12331235
} else if (currentCell && event.which == 73) {
12341236
// I
@@ -1256,6 +1258,12 @@ $(document).ready(function () {
12561258
// K
12571259
mundo.move(currentCell.row, currentCell.column);
12581260
mundo.rotate();
1261+
} else if (currentCell && event.which == 79) {
1262+
// O
1263+
mundo.rotate();
1264+
} else if (currentCell && event.which == 80) {
1265+
// P
1266+
mundo.move(currentCell.row, currentCell.column);
12591267
} else {
12601268
repaint = false;
12611269
}
@@ -1509,13 +1517,12 @@ $(document).ready(function () {
15091517
});
15101518
$('#filas').blur(function (event) {
15111519
var valor = parseInt($(this).val());
1512-
if (0 > valor || valor > 10000 || valor == h || Number.isNaN(valor)) {
1520+
if (valor <= 0 || valor > 10000 || valor == h || Number.isNaN(valor)) {
15131521
$(this).val(h);
15141522
return;
15151523
}
15161524
h = valor;
15171525
mundo.resize(w, h);
1518-
addEventListeners(mundo);
15191526
wRender = new WorldRender(context, h, w);
15201527
wRender.paint(mundo, world.width, world.height, {
15211528
editable: true,
@@ -1525,13 +1532,12 @@ $(document).ready(function () {
15251532
});
15261533
$('#columnas').blur(function (event) {
15271534
var valor = parseInt($(this).val());
1528-
if (0 > valor || valor > 10000 || valor == w || Number.isNaN(valor)) {
1535+
if (valor <= 0 || valor > 10000 || valor == w || Number.isNaN(valor)) {
15291536
$(this).val(w);
15301537
return;
15311538
}
15321539
w = valor;
15331540
mundo.resize(w, h);
1534-
addEventListeners(mundo);
15351541
wRender = new WorldRender(context, h, w);
15361542
wRender.paint(mundo, world.width, world.height, {
15371543
editable: true,

0 commit comments

Comments
 (0)