source: proiecte/ptvs/src/vnsim/vehicular/simulator/intersections/TrafficLightInfo.java @ 31

Last change on this file since 31 was 31, checked in by (none), 14 years ago
File size: 1.4 KB
Line 
1/************************************************************************************
2 * Copyright (C) 2008 by Politehnica University of Bucharest and Rutgers University
3 * All rights reserved.
4 * Refer to LICENSE for terms and conditions of use.
5 ***********************************************************************************/
6package vnsim.vehicular.simulator.intersections;
7
8
9import java.io.Serializable;
10
11import vnsim.map.object.Globals;
12
13
14
15public class TrafficLightInfo implements Serializable {
16       
17        /** <code>serialVersionUID</code> */
18        private static final long serialVersionUID = -5883719321862303634L;
19
20        //[secs]
21        public int greenStart;
22        public int greenEnd;
23        public int yellowStart;
24        public int yellowEnd;
25
26        public static int TIMEYELLOW=3;
27        //any other time is red
28
29        public TrafficLightInfo(int greenStart, int greenEnd) {
30                this.greenStart=greenStart;
31                this.greenEnd=greenEnd;
32                yellowStart=greenEnd;
33                yellowEnd=yellowStart+TIMEYELLOW;
34        }
35
36        public TrafficLightInfo(int greenStart, int greenEnd, int yellowTime) {
37                this.greenStart=greenStart;
38                this.greenEnd=greenEnd;
39                yellowStart=greenEnd;
40                yellowEnd=yellowStart + yellowTime;
41        }
42
43        public int getColor(double timeSec) {
44                //1=RED, 2=YELLOW, 3=GREEN
45                if(timeSec>=greenStart && timeSec<greenEnd)
46                        return Globals.GREEN;
47                if(timeSec>=yellowStart && timeSec<yellowEnd)
48                        return Globals.YELLOW;
49                return Globals.RED;
50        }
51}
Note: See TracBrowser for help on using the repository browser.