private Vector explode String separator String Vector new Vector Strin

 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
private Vector explode(String separator, String s)
{
Vector v = new Vector();
StringTokenizer st = new StringTokenizer(s, separator);
while (st.hasMoreTokens()){
// Получаем слово и заносим в вектор
v.add(st.nextToken()); // Добавляем в конец вектора
}
return v;
}
private void timerTick(String _cmd) {
//System.out.println(_cmd);
int time=0, pid =0, x=0, y=0, bombs=0, strength=0, speed=0;
boolean infected;
String s;
//_cmd = "T2743&P0 dead,P1 dead&+X 0 0,+X 0 10,+X 1 0,+X 1 10,+X 2 0,+X 2 10,+X 3 0,+X 3 10,+X 4 0,+X 4 10,+X 5 0,+X 5 10,+X 6 0,+X 6 10,+X 7 0,+X 7 10,+X 8 0,+X 8 10,+X 9 0,+X 9 10,+X 10 0,+X 10 10,+X 0 1,+X 10 1,+X 0 2,+X 10 2,+X 0 3,+X 10 3,+X 0 4,+X 10 4,+X 0 5,+X 10 5,+X 0 6,+X 10 6,+X 0 7,+X 10 7,+X 0 8,+X 10 8,+X 0 9,+X 10 9&d 2";
Vector v = explode("&",_cmd);
for (int i = 0; i < v.size(); i++) { // Перебираем весь вектор
s = v.get(i).toString();
switch(i) {
case 0:
time = Integer.parseInt(s.substring(1));
System.out.println("Time is: "+ time);
break;
case 1:
{
Vector players = explode(",", s);
if(time == 0)
{
m_BE.m_players = new Player[players.size()];
}
for (int j = 0; j < players.size(); j++)
{
Vector data = explode(" ", players.get(j).toString().substring(1));
if(data.size()>=6)
{
pid = Integer.parseInt(data.get(0).toString());
x = Integer.parseInt(data.get(1).toString());
y = Integer.parseInt(data.get(2).toString());
bombs = Integer.parseInt(data.get(3).toString());
strength = Integer.parseInt(data.get(4).toString());
speed = Integer.parseInt(data.get(5).toString());
if(data.size()==7 && (data.get(6).toString() == "i"))
infected = true;
else
infected = false;
m_BE.m_players[j]=new Player(pid, new Point(x,y), bombs, strength, speed, infected);
System.out.println("Player : "+ m_BE.m_players[j].m_pid);
System.out.println(" X : "+ m_BE.m_players[j].m_pos.x);
System.out.println(" Y : "+ m_BE.m_players[j].m_pos.y);
System.out.println(" Bombs : "+ m_BE.m_players[j].m_bombs);
System.out.println(" strength : "+ m_BE.m_players[j].m_str);
System.out.println(" speed : "+ m_BE.m_players[j].m_speed);
System.out.println(" infected : "+ m_BE.m_players[j].m_infict);
}
}
}
break;
case 2:
System.out.println("Changes : "+v.get(i));
break;
case 3:
System.out.println("Danger : "+v.get(i));
break;
}
}
}