|
-
getting count
Hi:
I've been trying to create a class that would keep track of the
number of players. My thought was to create a game on an applet and
then whenever an instance of the applet was loaded by a client a class
named NumberOfPlayers would keep track of the number of players. I
thought all I would need to do was declare a static variable like:
private static int Players = 0;
but this doesn't seem to work. The entire class looks like this:
public class NumberOfPlayers
{
private static int Players = 0;
public int getNumberOfPlayersAsInt()
{
return Players;
}
public String getNumberOfPlayersAsString()
{
return String.valueOf(Players);
}
public void addNewPlayer(int newPlayer)
{
Players = Players + newPlayer;
}
public void removePayer(int retiredPlayer)
{
Players = Players - retiredPlayer;
}
}
When an instance of the game applet opens I make a call to the
constructor like:
NumberOfPlayers nPlayers = new NumberOfPlayers(); //declaration
public game(){nPlayers.addNewPlayer(1);}//constructor
When I open two instances of the game applet the return value of
nPlayers.getNumberOfPlayersAsString() is always one [1] not two [2] as
expected.
How can I change my approach so as to make this work?
Thanks,
Alan
Posting Permissions
- You may not post new threads
- You may not post replies
- You may not post attachments
- You may not edit your posts
Forum Rules
|
Top DevX Stories
Easy Web Services with SQL Server 2005 HTTP Endpoints
JavaOne 2005: Java Platform Roadmap Focuses on Ease of Development, Sun Focuses on the "Free" in F.O.S.S.
Wed Yourself to UML with the Power of Associations
Microsoft to Add AJAX Capabilities to ASP.NET
IBM's Cloudscape Versus MySQL
|
Bookmarks