-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathCourse2.java
More file actions
63 lines (58 loc) · 1.21 KB
/
Course2.java
File metadata and controls
63 lines (58 loc) · 1.21 KB
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
import ch.aplu.robotsim.*;
class Course2
{
Course2()
{
TurtleRobot robot = new TurtleRobot();
Gear gear = new Gear();
robot.addPart(gear);
TouchSensor tsl = new TouchSensor(SensorPort.S1);
TouchSensor tsr = new TouchSensor(SensorPort.S2);
robot.addPart(tsl);
robot.addPart(tsr);
gear.setSpeed(100);
gear.forward();
while (true)
{
boolean t1 = tsl.isPressed();
boolean t2 = tsr.isPressed();
if (t1 && t2)
{
gear.backward(500);
gear.left(400);
gear.forward();
}
else
{
if (t1)
{
gear.backward(500);
gear.left(400);
gear.forward();
}
else
{
if (t2)
{
gear.backward(500);
gear.right(100);
gear.forward();
}
}
}
Tools.delay(20);
}
}
static public void main(String[] args)
{
new Course2();
}
// ------------------ Environment --------------------------
static
{
NxtContext.setLocation(10, 10);
NxtContext.setStartDirection(270);
NxtContext.setStartPosition(410, 430);
NxtContext.useObstacle("sprites/bg2.gif", 250, 250);
}
}