-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathSeries3Ex1.java
73 lines (52 loc) · 1.48 KB
/
Series3Ex1.java
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
import ch.aplu.robotsim.Gear;
import ch.aplu.robotsim.LightSensor;
import ch.aplu.robotsim.NxtContext;
import ch.aplu.robotsim.NxtRobot;
import ch.aplu.robotsim.SensorPort;
import ch.aplu.robotsim.TouchSensor;
public class Series3Ex1 {
Series3Ex1(){
NxtRobot robot = new NxtRobot();
Gear gear = new Gear();
robot.addPart(gear);
TouchSensor ts = new TouchSensor(SensorPort.S3); //creates TouchSensor
robot.addPart(ts); //fixes the TouchSensor to the Robot
gear.setSpeed(30);
gear.forward();
while(true){
while (true)
{
if (ts.isPressed()) //if the TouchSensor is pressed do
{
gear.backward(1000);
gear.left(1250);
gear.forward(2000);
gear.left(1250);
gear.forward();
break;
}
}
while (true){
if (ts.isPressed()) //if the TouchSensor is pressed do
{
gear.backward(1000);
gear.right(1250);
gear.forward(2000);
gear.right(1250);
gear.forward();
break;
}
}
}
}
public static void main(String[] args) {
new Series3Ex1();
}
//Environment-----------------------------------------------------------------
static {
//430,60 initial
NxtContext.setStartPosition(100, 60);
NxtContext.setStartDirection(180);
NxtContext.useObstacle("sprites/rectangle.gif", 250, 250);
}
}