Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix Karel positioning and max rows columns #193

Merged
merged 2 commits into from
Oct 7, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
29 changes: 17 additions & 12 deletions README.md
Original file line number Diff line number Diff line change
@@ -1,23 +1,28 @@
Karel.js
========
# Karel.js

Compilador y evaluador de Karel en Javascript

## Cómo descargar Karel.js

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

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

* `npm install && npm start`
- `npm install && npm start`

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

* `sudo npm install -g`
* `kareljs compile archivo.karel` compila el programa y genera un
archivo `.kx`.
* `kareljs run archivo.kx < entrada.in` ejecuta el programa con el mundo
especificado por `entrada.in`.
- `sudo npm install -g`
- `kareljs compile archivo.karel` compila el programa y genera un
archivo `.kx`.
- `kareljs run archivo.kx < entrada.in` ejecuta el programa con el mundo
especificado por `entrada.in`.

## Troubleshooting

- Si `npm install` marca error en la librería `node-canvas`, probablemente estés
corriendo desde un OS que necesita instalar ciertas dependencias. Consulta la siguiente
[documentación](https://github.com/Automattic/node-canvas?tab=readme-ov-file#compiling)
2 changes: 1 addition & 1 deletion js/karel.js
Original file line number Diff line number Diff line change
Expand Up @@ -644,7 +644,6 @@ World.prototype.resize = function (w, h) {
var oldW = self.w;
var oldH = self.h;
var oldMap = self.map;
var oldCurrentMap = self.oldCurrentMap;
var oldWallMap = self.wallMap;
var oldDumpCells = self.dumpCells;

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

if (0 >= i || i > self.h || 0 >= j || j > self.w) return;
self.i = self.start_i = i;
self.j = self.start_j = j;
self.dirty = true;
Expand Down
14 changes: 10 additions & 4 deletions js/main.js
Original file line number Diff line number Diff line change
Expand Up @@ -1227,8 +1227,10 @@ $(document).ready(function () {
wRender.moveSouth();
saveWorld = false;
} else if (currentCell && event.which >= 96 && event.which <= 105) {
// numpad 0 - numpad 9
mundo.setBuzzers(currentCell.row, currentCell.column, event.which - 96);
} else if (currentCell && event.which >= 48 && event.which <= 57) {
// 0 - 9
mundo.setBuzzers(currentCell.row, currentCell.column, event.which - 48);
} else if (currentCell && event.which == 73) {
// I
Expand Down Expand Up @@ -1256,6 +1258,12 @@ $(document).ready(function () {
// K
mundo.move(currentCell.row, currentCell.column);
mundo.rotate();
} else if (currentCell && event.which == 79) {
// O
mundo.rotate();
} else if (currentCell && event.which == 80) {
// P
mundo.move(currentCell.row, currentCell.column);
} else {
repaint = false;
}
Expand Down Expand Up @@ -1509,13 +1517,12 @@ $(document).ready(function () {
});
$('#filas').blur(function (event) {
var valor = parseInt($(this).val());
if (0 > valor || valor > 10000 || valor == h || Number.isNaN(valor)) {
if (valor <= 0 || valor > 10000 || valor == h || Number.isNaN(valor)) {
$(this).val(h);
return;
}
h = valor;
mundo.resize(w, h);
addEventListeners(mundo);
wRender = new WorldRender(context, h, w);
wRender.paint(mundo, world.width, world.height, {
editable: true,
Expand All @@ -1525,13 +1532,12 @@ $(document).ready(function () {
});
$('#columnas').blur(function (event) {
var valor = parseInt($(this).val());
if (0 > valor || valor > 10000 || valor == w || Number.isNaN(valor)) {
if (valor <= 0 || valor > 10000 || valor == w || Number.isNaN(valor)) {
$(this).val(w);
return;
}
w = valor;
mundo.resize(w, h);
addEventListeners(mundo);
wRender = new WorldRender(context, h, w);
wRender.paint(mundo, world.width, world.height, {
editable: true,
Expand Down
Loading