Question : Java Client Applet - Painting

OK so I will be leaving my server on until I say it's offline in this topic.

What the problem? Let's say a player A logs in, and takes the sword... then player B logs in, th e server sends what to draw for the items. So what happens is EVERY ITEM is draw on the board for a SPLIT SECOND then the Sword is taken away.

I want that split second gone and if the drawSword is false... then to NOT draw AT ALL...

That function is this at the very end of tileGen in the GamePanel class:
1:
2:
3:
                  if (drawFlail == true && currentMap == 1) g.drawImage(weapon[1], 32 * 4, 32 * 4, this);
				  if (drawBattleaxe == true && currentMap == 1) g.drawImage(weapon[0], 32 * 3, 32 * 2, this);
                  if (drawSword == true && currentMap == 1) g.drawImage(weapon[2], 32 * 13, 32 * 7, this);


It is inside the public void paintComponent(Graphics g) method. I was wondering if I could do the paintComponent BEFORE the run() is made that way.. but then I thought.. paintComponent is drawn first before run() then the server tells the client which items should be drawn.. so I don't know what to do.

Connect to the game: http://mystikrpg.com/new/play.php
Please do not take any items for this question purpose. Just observe. My character will be on the bottom right sitting idle... I will take the Sword so you will notice it flash before it disappears...

thanks.

Here is my run() method
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:
103:
104:
105:
106:
107:
108:
109:
110:
111:
112:
113:
114:
115:
116:
117:
118:
119:
120:
121:
122:
123:
124:
125:
126:
127:
128:
129:
130:
131:
132:
133:
134:
135:
136:
137:
138:
139:
140:
141:
142:
143:
144:
145:
146:
147:
148:
149:
150:
151:
152:
153:
154:
155:
156:
157:
158:
159:
160:
161:
162:
163:
164:
165:
166:
      public void run() {

            Socket s = null;

            try {



                 String host = "69.133.110.152";
                 s = new Socket(host,Integer.valueOf(getParameter("port")));



                  in = new BufferedReader(new InputStreamReader(s.getInputStream()));

                  os = new PrintStream(s.getOutputStream());
                  System.out.println("\n******** Connecting to " + host + " on port " + getParameter("port"));

                  playerLogin();


                  int buf = -1;
                  String responseLine;

                  // rawr
                  while ((responseLine = in.readLine()) != null) {
                        isResp = true;

                        chatOne = true;

                         repaint();
                        // c.append("\nxxx\n");
                        // System.out.println("responseLine (|): " + responseLine);

                        String str = responseLine;

                        String delimiter = "\\|";

                        String[] temp = str.split(delimiter);

                        // c.append("\noutput: " + str);

                        // pid
                        Player player = players.get(temp[0]);
System.out.println("drawFlail: " + drawFlail + " | drawSword: " + drawSword + " | drawBattleaxe: " + drawBattleaxe);
if (drawFlail || drawSword || drawBattleaxe) {
 if ("pickup".equalsIgnoreCase(temp[4]))
{
	//c.append("\n"+temp[0] + "|" + temp[1] + "|" + temp[2] + "|" + temp[3] + "|" + temp[4]);
	//int changeX = Integer.parseInt(temp[1]);
	//int changeY = Integer.parseInt(temp[2]);
	//board[changeY][changeX] = 4;

	if("drawFlail".equals(temp[2])) drawFlail = false;
	if("drawBattleaxe".equals(temp[2])) drawBattleaxe = false;
    if("drawSword".equals(temp[2])) drawSword = false;

	int theItem = Integer.parseInt(temp[1]);
	pickedUp(theItem, temp[0]);
	if("yes".equalsIgnoreCase(temp[3])) {
		c.append("\n"+ temp[0] + " picked up a " + getItem(theItem)[0]+".");
	}
	System.out.println("~~~~~~~~~~~~~~~~~~~\nITEM REMOVED " + temp[2] + "\n~~~~~~~~~~~~~~~~~~~~~~");
	System.out.println("drawFlail - " + drawFlail + " | drawSword - " + drawSword + " | drawBattleaxe - " + drawBattleaxe);

}
}
                        if ("chat".equalsIgnoreCase(temp[4])) {
							if (temp[2].indexOf( "has left" ) > -1 ) {
								c.append("\n"+temp[0] + " has logged out.");
							  		      players.remove(temp[0]);


							}else{
								String theirMap = Integer.toString(currentMap);
                              if(theirMap.equals(temp[1])) {
                              c.append("\n" + temp[0] + ": " + temp[2]);
						  }else if(temp[0].equals(me.getUsername())){
							   c.append("\n" + temp[0] + ": " + temp[2]);
						  }

                              System.out.println("CurrentMap:" + currentMap + " | temp1 " + temp[1]);
						  }
                              c.setCaretPosition(c.getDocument().getLength());
                              //c.append("\n player = " + player.getUsername() + " | me. " + me.getUsername());

                              // sendMsg(temp[0], temp[2], me.getUsername());


							 if (temp[2].indexOf( "/kick" ) > -1) {
								 String[] whoKick = str.split(" ");
								 String[] kicked = whoKick[1].split("\\|");
								 players.remove(kicked[0]);
								 c.append("\n"+kicked[0] + " has been kicked by " + temp[0]);
								 c.setCaretPosition(c.getDocument().getLength());

							 }

							int realx = 0;
							for (Player playert : players.values()) realx++;
usersOn.setText("Players online: " + realx);


                        }
if(isInteger(temp[2]) == true) {
                        if (player == null) {


                              player = new Player();
                              player.setUsername(temp[0]);
                              player.setX(Integer.parseInt(temp[1]));
                              player.setY(Integer.parseInt(temp[2]));
                              player.setCommand(temp[4]);
                              player.setPlayerImage(ImageIO.read(getClass().getResource(
                                          "me.gif")));
                              player.setMap(1);
                              players.put(temp[0], player);

                              int realy = 0;
							  for (Player playert : players.values()) realy++;
usersOn.setText("Players online: " + realy);

                        }
                        if ("move".equalsIgnoreCase(temp[4])) {
                              // c.append("\n"+temp[2] + " and temp 4: " + temp[4]);
                              player.setX(Integer.parseInt(temp[1]));
                              player.setY(Integer.parseInt(temp[2]));
                              player.setMap(Integer.parseInt(temp[3]));
                        }
                        System.out.println("TEMP 4 " + temp[4]);
                        player.setCommand(temp[4]);
                        player.setUsername(temp[0]);
                        System.out.println("X set: " + player.getX() + " | Y set: "
                                    + player.getY() + " | CurrMap set: " + player.getMap()
                                    + " | Username set: " + player.getUsername()
                                    + " | Command set: " + temp[4]);

                        repaint();
					}

                  }
                  repaint();

            } catch (Exception rwe) {
                  // System.exit(0);
                  System.out.println("Server went down -- crap!");
                  c.append("\nServer crashed!");
                  rwe.printStackTrace();
            } finally {
                  try {
                        s.close();
                  } catch (IOException ere) {
                        ere.printStackTrace();
                  }
            }

            c.setCaretPosition(c.getDocument().getLength());

			count = 0;
			for (Player player : players.values()) {
				System.out.println(player.getUsername() + " is still on. new count: " + count);
			count++;
			}

			usersOn.setText("Players online: " + count);
      }


and here is the GamePanel which draws it...
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:
class GamePanel extends JPanel {

            public void paintComponent(Graphics g) {
                  for (row = 0; row < board.length; row++) {
                        for (col = 0; col < board[row].length; col++) {
                              int index = board[row][col];
                              g.drawImage(tiles[index], 32 * col, 32 * row, this);

                        }
                  }

                  try {


                        for (Player player : players.values()) {
                              System.out.println("++++++++++++++++++++++++++");
                              System.out.println("current map: " + player.getMap());
                              if (player.getUsername() == me.getUsername())
                                    player.setMap(currentMap);
                              if (player.getUsername() == me.getUsername())
                                    player.setCommand(myCommand);
                              if (player.getMap() == currentMap) {
                                    g.drawImage(player.getPlayerImage(), player.getX(), player
                                                .getY(), this);

                              }
                              System.out.println("Command-- " + player.getCommand() + " > "
                                          + player.getUsername() + " moved to X:" + player.getX()
                                          + " and Y: " + player.getY());

                              System.out.println("++++++++++++++++++++++++++");
                        }
                  } catch (Exception dan) {
                        System.out.println("No one is on.");
                  }

                  // qq
                  /**
                   * for(int runx = 0;runx < 10;runx++) { g.drawImage(userImg[runx],
                   * userPX[runx], userPY[runx], this); }
                   **/

                  if (drawFlail == true && currentMap == 1) g.drawImage(weapon[1], 32 * 4, 32 * 4, this);
				  if (drawBattleaxe == true && currentMap == 1) g.drawImage(weapon[0], 32 * 3, 32 * 2, this);
                  if (drawSword == true && currentMap == 1) g.drawImage(weapon[2], 32 * 13, 32 * 7, this);

            }

      }

Answer : Java Client Applet - Painting

Thats doing what I suggested in your earlier q, ie. have the server track the location of all items on the maps
Random Solutions  
 
programming4us programming4us