Tell me more ×
Stack Overflow is a question and answer site for professional and enthusiast programmers. It's 100% free, no registration required.

I'm trying to insert five java patterns like (Command pattern, Decorator, Factory, Facade, Iterator) in my java game. Now i have modified an existing TETRIS game to a better one. Notice that i worked about 3 weeks to modify this game but now i need to insert into the code these patterns. If there is anyone that can help me with my problem I will be glad to discuss with.

A scrap from my first pattern

public class Decorator  extends JComponent {
        public Decorator(JComponent c) {
                setLayout(new BorderLayout());
                add("Center", c);
  }
}
        public class CoolDecorator  extends Decorator {

        JComponent thisComp;

        public CoolDecorator(JComponent c) {
        super(c);
        c.setBackground(Color.white);  }
    }

If anyone can help me in private I will be glad to pay it.

share|improve this question
2  
Why do you want to insert patterns into your game? Do you even need them? – Adam Arold May 28 at 21:50
I don't need them but this task is for a university project. They need now patterns:(( – Stanley Tips May 28 at 21:51
1  
this is a really good exercise for you, just study the patterns I am sure you will be able to do it... and post a question for specific situations you might face a problem – fmodos May 28 at 22:02
@fmodos thank you for the response but I need to finish this this night. I have studied thee patters for few weeks, I know what they are doing but I manage them in my project. – Stanley Tips May 28 at 22:07
1  
@StanleyTips it's not easy to suggest you how to implement as we dont know the actual architecture of this game, so far as I know stackoverflow is not a place where people get paid to help... so I suggest you to try to find some help in a freelancer website. – fmodos May 28 at 22:29
show 2 more comments

closed as not a real question by matt b, Ryan Cavanaugh, Adam Arold, Raedwald, Brian Roach May 28 at 23:32

It's difficult to tell what is being asked here. This question is ambiguous, vague, incomplete, overly broad, or rhetorical and cannot be reasonably answered in its current form. For help clarifying this question so that it can be reopened, see the FAQ.

1 Answer

Here is a brief example on how you could apply for your system each of the patterns you requested. I hope this can help you for a better understanding on how to apply design patterns for your scenarios.

Your Decorator pattern looks ok.

Command pattern: You can use it in the actions of your game for example the actions to rotate the object. Create one command for each action

RotateRightCommand implements ICommand{
@override
public void execute(){
 //copy here the code to rotate
}

Create one instance of this command, and invoke command.execute() in the actionlistener of the button or keylistener

Factory pattern: Think as you have different type of objects in the game that need to be drawn, so have an abstract class for the basic and the other objects will extend it:

abstract class GenericObject{

abstract void drawObject();

}

class ObjectSquare extends GenericObject{

   public void drawObject(){
      //invoke the code to draw the square object
   } 

}

Facade pattern: This a basic pattern, create one class that group other class and functions for ie: one class to save the current points and show the points in the screen

FacadePoints {
   SavePoint savePoint;
   ShowPoint showPoint;

   public void update(){
      savePoint.save();
      showPoint.show()
   }
}

Iterator pattern: Create one class that store an internal array and implement the class java.util.Iterator interface.

share|improve this answer
Thank you for you reply. I will try them right now and let you know what i will make – Stanley Tips May 28 at 23:12

Not the answer you're looking for? Browse other questions tagged or ask your own question.