Exemple #1
0
        private void MouseClicker(object sender, MouseEventArgs e)
        {
            Girdcoord coord = getCoordsFromPixel(e.X, e.Y);

            // Evitar hacer lineas diagonales pq sino esto peta

            if (karelMovementActions.Count > 0)
            {
                int i = karelMovementActions.Count - 1;
                if (!nextInvalid)
                {
                    if (coord.x != karelMovementActions[i].coord.x && coord.y != karelMovementActions[i].coord.y)
                    {
                        return;
                    }
                }
            }

            KarelClick nextKarelClick = new KarelClick(coord);

            if (nextInvalid)
            {
                nextKarelClick.valid = false;
                nextInvalid          = false;
            }
            karelMovementActions.Add(nextKarelClick);

            RefreshMainPanel();
        }
Exemple #2
0
        private string generateCode()
        {
            string res = "function left(){while(notFacingEast())turnRight();mov();}function right(){while(notFacingWest())turnRight();mov();}function up(){while(notFacingNorth())turnRight();mov();}function down(){while(notFacingSouth())turnRight();mov();}function mov(){if(frontIsBlocked()) removeWall();if(beepersPresent()) pickBeeper();move();if(trayPresent()){if(trayIsMine()){while(beepersInBag()) putBeeperInTray();}}}";

            res += "\nfunction main(){\n   ";

            for (int i = 0; i < karelMovementActions.Count - 1; i++)
            {
                int r = i + 1;

                if (!karelMovementActions[r].valid)
                {
                    continue;
                }

                Girdcoord difference = new Girdcoord(karelMovementActions[i].coord.x - karelMovementActions[r].coord.x,
                                                     karelMovementActions[i].coord.y - karelMovementActions[r].coord.y);

                int dist = Math.Abs(difference.x) + Math.Abs(difference.y);

                res += "repeat(" + dist + "){\n   ";

                if (difference.x > 0)
                {
                    // Izquierda
                    res += "right();";
                }
                else if (difference.x < 0)
                {
                    // derecha
                    res += "left();";
                }
                else if (difference.y > 0)
                {
                    // abajo
                    res += "up();";
                }
                else if (difference.y < 0)
                {
                    // arriba
                    res += "down();";
                }

                res += "\n}";

                if (karelMovementActions[r].keyBinding == Keys.E)
                {
                    res += "if(exitPresent())exit();";
                }
                if (karelMovementActions[r].keyBinding == Keys.T)
                {
                    res += "teleport();";
                }
            }

            res += "\n}";

            return(res);
        }
Exemple #3
0
 public KarelClick(Girdcoord coord, Keys key, Color lineColor)
 {
     this.coord      = coord;
     this.keyBinding = key;
     this.lineColor  = lineColor;
 }
Exemple #4
0
 public KarelClick(Girdcoord coord)
 {
     this.coord      = coord;
     this.keyBinding = Keys.None;
     this.lineColor  = Color.Green;
 }