-
Java card game
I have the following problem. I'm making a simple card game for online play. Here's a outline of my code:
class duuzenden
{
GameStatus game; // contains all the hands, the score, etc
CardPanel myhandpanel,hishandpanel;
main{
myhandpanel = new CardPanel (spel.myhand);
hishandpanel = new CardPanel (spel.hishand);
}
void submit ()
// send Main.game
void receive ()
// receive a game and put it into Main.game
}
class GameStatus
{
Hand myhand, hishand, etc..
}
class CardPanel extends JPanel
{
Hand h;
CardPanel(Hand h)
this.h = h;
paintComponent(Graphics g)
g.draw(h);
}
The problem now is that the information about the cards I have is stored in two places (Main.game.myhand and myhandpanel.h). When the cards change, I have to change them in two places: in Main.game.myhand to send Main.game to the other player, and in myhandpanel.h for correct display. How can I remove this redundency?
I'd rather give the CardPanel some kind of reference to the Main.myhand and Main.hishand, so that it'd look like
class CardPanel extends JPanel
{
Hand *h;
CardPanel(*Hand h)
this.h = h;
paintComponent(Graphics g)
g.draw(&h);
}
so that each instance of the CardPanel class still manipulates the objects in Main.game.
Thanks for your help!
Ciro.
Similar Threads
-
By thomastl in forum Java
Replies: 1
Last Post: 03-29-2009, 11:49 AM
-
By thomastl in forum Java
Replies: 4
Last Post: 01-22-2007, 02:45 AM
-
Replies: 1
Last Post: 05-13-2005, 06:46 AM
-
Replies: 2
Last Post: 03-11-2005, 04:34 PM
-
By JJ in forum Enterprise
Replies: 1
Last Post: 07-06-2000, 04:50 AM
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