Executing user typed code
I am creating a learning aid in the scenario of a game which allows the users to type their own code into a JTextArea for it to be compiled and executed to traverse the player through the level.
Within the learning aid currently, I want to allow the user to use conditional statements and loops so that they can detect if the player has hit a wall while it was moving. An example code of this would look like this:
However, when I test this code out, the while() loop and the if statement returns true, but the player.moveRight(3); within the if statement does not get executed.
//The numbers passed into the methods are the number of tiles to move in that direction.
Within the player class what I am currently doing is storing the player's movements into an array and assigning target x and y coordinates for the player to move towards. The player will move in the direction specified for the amount passed in within the parameter. Once the player has reached the target distance, it will then move in the second direction that the user might have specified, until it has emptied the array containing the move directions.
I tried emptying the move direction array when the player has hit the wall, but that did not work either.
Here is the player class: player class
Re: Executing user typed code
For better help sooner, it's a good idea to create an SSCCE that demonstrates the problem in a way that we can copy and paste without going to external sites.