-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathParcours.java
102 lines (80 loc) · 1.53 KB
/
Parcours.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
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
//
import ch.aplu.robotsim.*;
class Parcours
{
//TouchForward
public TouchSensor leftsensor=new TouchSensor(SensorPort.S2);
//TouchBackward
public TouchSensor rightsensor=new TouchSensor(SensorPort.S1);
//front,back,left,right
public boolean flagl,flagr,out=false;
//gear
public Gear gear = new Gear();
void check()
{
flagl=false;
flagr=false;
flagl=leftsensor.isPressed();
flagr=rightsensor.isPressed();
}
void frontmove()
{
gear.forward();
}
void rightmove()
{
gear.backward(1000);
gear.left(200);
gear.forward();
}
void leftmove()
{
gear.backward(800);
gear.right(300);
gear.forward();
}
void backmove()
{
gear.backward(900);
gear.left(200);
}
Parcours()
{
//Instance a Robot
NxtRobot robot = new NxtRobot();
//Instance a Gear
//Add parts to Robot
robot.addPart(gear);
robot.addPart(leftsensor);
robot.addPart(rightsensor);
gear.setSpeed(70);
gear.forward();
while (true)
{
check();
if(flagl&&flagr)
backmove();
if(flagr&&!flagl)
rightmove();
if(flagl&&!flagr)
leftmove();
if(!flagr&&!flagl)
frontmove();
}
//gear.stop();
//Quitting the instance
//robot.exit();
}
public static void main(String[] args)
{
new Parcours();
}
//Environment
static
{
Obstacle obs=new Obstacle("sprites/parcours.gif");
NxtContext.useObstacle(obs);
NxtContext.setStartDirection(-90);
NxtContext.setStartPosition(280, 430);
}
}