Skip to content

Commit fbfbdc1

Browse files
committed
resolved confict for merge
2 parents 48bb65d + d55e042 commit fbfbdc1

File tree

5 files changed

+111
-43
lines changed

5 files changed

+111
-43
lines changed

README.md

Lines changed: 15 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,15 @@
1-
# FFX_LightningAvoider
2-
This is a simple project that makes Tidus to avoid thunder in the game Final Fantasy X for ps4
3-
4-
INSTRUCTIONS
5-
6-
1 - Start remote play for ps4 on PC in order to play the game on the PC
7-
2 - Position Tidus in the south area near the kyactus stone on the right side of the map in order to block him when avoiding
8-
3 - Run the program
9-
4 - Now you have 5 seconds to position the mouse pointer on a dark pixel of the game screen
10-
5 - wait until the program ends, you can see on the standard output how many thunder have been avoided
1+
2+
# FFX_LightningAvoider
3+
This is a simple project that makes Tidus to avoid thunder in the game Final Fantasy X for ps4
4+
5+
INSTRUCTIONS
6+
7+
1. Start remote play for ps4 on PC in order to play the game on the PC
8+
2. Position Tidus in the south area near the kyactus stone on the right side of the map in order to block him when avoiding
9+
3. Run the program
10+
4. Now you have 5 seconds to position the mouse pointer in on a dark pixel of the game screen
11+
5. wait until the program ends, you can see on the standard output how many thunder have been avoided
12+
13+
## Command line option
14+
15+
``[-wp <number of waiting time>] [-ml <number of max lightning avoied>]``

src/LightningSensor.java

Lines changed: 44 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,44 @@
1+
import java.awt.AWTException;
2+
import java.awt.MouseInfo;
3+
import java.awt.Point;
4+
import java.awt.Robot;
5+
import java.awt.event.KeyEvent;
6+
7+
public class LightningSensor {
8+
9+
final public int WAITING_PIXEL;
10+
final public int MAXLIGHTNING_AVOIED;
11+
12+
public LightningSensor(int waitinPixel, int maxLightningAvoied){
13+
this.WAITING_PIXEL = waitinPixel;
14+
this.MAXLIGHTNING_AVOIED = maxLightningAvoied;
15+
}
16+
17+
public LightningSensor(){
18+
this(5000, 210);
19+
}
20+
21+
public void run() throws AWTException{
22+
Point coord;
23+
Robot robot = new Robot();
24+
int lightningCounter = 0;
25+
26+
// wait for this.WAITINGPIXEL seconds to permit the user to point the mouse on the desire pixel
27+
robot.delay(this.WAITING_PIXEL);
28+
coord = MouseInfo.getPointerInfo().getLocation();
29+
30+
while (lightningCounter <= this.MAXLIGHTNING_AVOIED) {
31+
// green >= 70 means screen flash
32+
if (robot.getPixelColor((int) coord.getX(), (int) coord.getY()).getGreen() >= 70) {
33+
// press ENTER = X
34+
robot.keyPress(KeyEvent.VK_ENTER);
35+
robot.delay(100);
36+
robot.keyRelease(KeyEvent.VK_ENTER);
37+
lightningCounter++;
38+
System.out.println(lightningCounter);
39+
// wait to prevent X spamming
40+
robot.delay(500);
41+
}
42+
}
43+
}
44+
}

src/Main.java

Lines changed: 14 additions & 33 deletions
Original file line numberDiff line numberDiff line change
@@ -1,40 +1,21 @@
11
import java.awt.AWTException;
2-
import java.awt.Robot;
3-
import java.awt.event.KeyEvent;
4-
import java.awt.Point;
5-
import java.awt.MouseInfo;
62

73
public class Main {
84

5+
final static public int DEFAULT_WAITING_PIXEL = 5000;
6+
final static public int DEFAULT_MAXLIGHTNING_AVOIED = 210;
7+
98
public static void main(String[] args) throws AWTException {
10-
11-
Point coord;
12-
Robot robot = new Robot();
13-
int count = 0;
14-
boolean whileCondition = true;
15-
16-
// wait for 5 seconds to permit the user to point the mouse on the desire pixel
17-
robot.delay(5000);
18-
// take coordinate of the pointed pixel
19-
coord = MouseInfo.getPointerInfo().getLocation();
20-
21-
while (whileCondition) {
22-
// green >= 70 means screen flash
23-
if (robot.getPixelColor((int) coord.getX(), (int) coord.getY()).getGreen() >= 70) {
24-
// press ENTER = X
25-
robot.keyPress(KeyEvent.VK_ENTER);
26-
robot.delay(100);
27-
robot.keyRelease(KeyEvent.VK_ENTER);
28-
// how many lightning avoided since now
29-
count++;
30-
System.out.println(count);
31-
// wait to prevent X spamming
32-
robot.delay(500);
33-
// exit the while after 210 lightning avoided
34-
if (count == 210) {
35-
whileCondition = false;
36-
}
37-
}
38-
}
9+
try{
10+
String commandValue;
11+
int waitingPizel = ((commandValue = ParserInput.getCommand("-wp", args)) != null) ? ParserInput.parseIntForCommand("-wp", commandValue) : DEFAULT_WAITING_PIXEL;
12+
int maxLightningAvoied = ((commandValue = ParserInput.getCommand("-ml", args)) != null) ? ParserInput.parseIntForCommand("-ml", commandValue) : DEFAULT_WAITING_PIXEL;
13+
14+
new LightningSensor(waitingPizel, maxLightningAvoied).run();
15+
}
16+
catch(ParserInputException e){
17+
System.out.println(e.getMessage());
18+
}
3919
}
20+
4021
}

src/ParserInput.java

Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,17 @@
1+
2+
public class ParserInput {
3+
public static String getCommand(String command, String[] arguments){
4+
for(int i = 0; i<arguments.length;i++)
5+
if(arguments[i].compareTo(command) == 0)
6+
return (i<arguments.length) ? arguments[i+1] : null;
7+
return null;
8+
}
9+
public static int parseIntForCommand(String command, String num){
10+
try{
11+
return Integer.parseInt(num);
12+
}
13+
catch(NumberFormatException e){
14+
throw new ParserInputException(command, num);
15+
}
16+
}
17+
}

src/ParserInputException.java

Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,21 @@
1+
2+
public class ParserInputException extends RuntimeException {
3+
private static final long serialVersionUID = 1L;
4+
protected String command;
5+
protected String string;
6+
7+
public ParserInputException(String command, String string) {
8+
this.command = command;
9+
this.string = string;
10+
}
11+
12+
@Override
13+
public String toString() {
14+
return "Error to perform command.\n"+this.command+" it's not a number but: " + this.string;
15+
}
16+
17+
@Override
18+
public String getMessage() {
19+
return this.toString();
20+
}
21+
}

0 commit comments

Comments
 (0)