Is there a good way ECS for creating variants of a behaviour like in Java interfaces?

In Java, there are interfaces – I’m not clear on the details (I don’t use Java) but from what I’ve learned, they seem to be "classes for classes": a way to effectively make individual classes "instances" of one overarching class. For example, a "Cup" interface could be implemented by a "Mug" class, a "Glass" class, a "Goblet" class etc. As long as they have the same I/O methods such as fill(), empty() or drink(), they can be used interchangeably.

In languages with duck typing, interfaces are not needed – the language allows for classes to be used interchangeably as long as no invalid properties of methods are referenced. This is another valid was of going about things in OOP. This is how I usually go about things.

My question: how can I create varied behaviour in an ECS if components are data-only? I like to think in terms of first-class functions, but that seems to be taboo since components are not supposed to hold behaviour.

Option 1, have a massive switch or if/else chain in my System:

For example, if I have an AI component with several different behaviours, I could use an integer to define which type of AI to use for that particular entity. It seems a bit convoluted and inelegant.

Option 2, have a separate Component and matching System for each behaviour:

This would be neater in each individual System but as a whole, the program would be a mess. This wouldn’t work because of the large amounts of variation such as hundreds of different guns in a shooter game.

Option 3, use a flyweight-like data structure independent of the Component:

This would mean storing all of the different behaviours elsewhere, and storing a key that a System can use to access the behaviour. This is basically a fancy version of the switch option above, but it seems neater as there wouldn’t be a massive dump of code in the System.

Option 4, creating a complex way of encoding a description of the desired behaviour which the System can interpret:

This seems to be the most overkill of the lot. Unless I have to, or there are significant advantages, I’m trying to stay away from this.

If there’s no other way, I’ll just adopt the methodology of first-class functions as I usually do and just ignore any guidelines about ECS I’ve heard, just for this one case. The problem is, it probably won’t just be one case in the future.

Have I missed any other good options? Is there an industry standard or recommendation? If not, what considerations should I make about which option to choose?

When or why would someone use a programming language (Swift, Java, C++, Rust etc…) over an engine like Unity?

Everytime I’ve read about people asking whether they should write their game in C++ or Unity, Unity is usually the default answer, unless they want to go through the hassle of creating an engine by themselves when Unity already does everything for you. If that’s the case is there ever a case where writing a game in C++, Java, Rust etc… is better than using Unity? If so what are these cases?

Most website visitors don’t have Java enabled

So, for the first time ever, I had a look at the "Java Support" dimension in Google Analytics. According to that, most of our visitors don’t seem to have Java enabled (115,844 vs. 7,540 page views). I’ve read stats that approx. 1-3% of people have Java disabled in their browser, so what’s going on on my website? How shall I interpret this data from Google Analytics?!

Our website is based on Javascript and won’t work without it. That’s why I find it odd that visitors without Java support would spend an average of 2:45 minutes on it. Any explanation or advice is greatly appreciated!

enter image description here

Why is PHP still mostly used to make browser games rather than Python or Java? [closed]

I am a Computer Science student and I have been playing to Travian for years.Travian is a browser based MMOG where you have to build your village and compete for resources. There is no animation, there is 3 main views which is the map, your village and your fields.

I was looking at some Travian clones on GitHub and I found 3 clones, all of them using PHP. Travian has itself build using PHP.

I am wondering if PHP is better in some way than Python for example for building this kind of games? And if so, why would be the reason?

Java stored procedure or user-defined function could not call Java method

After I created a Java external stored procedure in DB2 as in my previous question, the call

call user1.send_mail(    P_TO          => ''   ,P_CC          => NULL   ,P_BCC         => NULL   ,P_FROM        => ''   ,P_SUBJECT     => 'db2 java subject'   ,P_TEXT_MSG    => 'db2 java test'   ,P_HTML_MSG    => null   ,P_ATTACH_NAME => null   ,P_ATTACH_MIME => null   ,P_ATTACH_BLOB => null   ,P_SMTP_HOST   => ''   ,P_SMTP_PORT   => 465   ,P_USER_NAME   => ''   ,P_PASSWORD    => 'secret'); 

fails it due to the following error:

Java stored procedure or user-defined function "USER1.SEND_MAIL", specific name "SQL201208113215436" could not call Java method "send_mail", signature "(Ljava/lang/String".. SQLCODE=-4306, SQLSTATE=42724, DRIVER=3.68.61

I made sure that all parameters that have no default values receive non-NULL values. What else is necessary for this to work?

Java simple dusk cleaner game simulator

I am working on a dusk cleaner simulator on Java, in this case the shape of the cleaner is a circular ball.

The program is quite simple, the user puts in the width and length of the "room" and coordinates x and y.

What I want to do and cannot is create a series of commands, each represented by a character. There are three commands that I want to imnplement:

  1. char ‘A’ = Move forward 1 meter

  2. char ‘L’ = Turn left 90 degrees

  3. char ‘R’ = Turn right 90 degrees

Example of user input AALA, in this case the expected output is that the machine moves 2 meters and then turns left 90 degrees and then moves 1 meter again. Hope I am clear.

As you can see in the code, I have tried to create an array of chars but I dont know what the next step should be…

The code:

public class Cleaner extends JPanel { /* int lx = 1, ly = 1; int x = 200, y = 250;  */ int x, y; int width = 52, height = 50; // width and height of the "dust sucker" int lx , ly;   // an array of chars char[] charArray ={ 'A', 'L', 'R'};       java.util.Timer move; // making the instance of Timer class from the util package static JFrame frame;   Cleaner() {          frame = new JFrame ("Cleaner started!"); // passing attributes to our fame     frame.setSize (400, 400); // setting size of the starting window     frame.setVisible (true);          setForeground(; // setting color          move = new java.util.Timer();          move.scheduleAtFixedRate(new TimerTask()     {                       public void run()          {             if(x<0)                 lx = 1;             if(x>=getWidth()-45)                 lx = -1; // -1 sets boundry for the dusk sucker             if(y<0)                 ly = 1;             if(y>=getHeight()-45)                 ly = -1; // -1 sets boundry for the dusk sucker                          x+=lx; // to make the machine move             y+=ly;                          repaint();         }              }, 0, 5// speed of the machine             );          frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);      }  public void paint (Graphics g)  {     super.paint(g);     Graphics2D g2d = (Graphics2D) g;     g2d.setRenderingHint(RenderingHints.KEY_ANTIALIASING, RenderingHints.VALUE_ANTIALIAS_ON);     g2d.fillOval(x, y, width, height); }  public static void main (String[] args)  {     // lx value          String lxValue =               JOptionPane.showInputDialog( "Enter lx" );     // ly value     String lyValue =               JOptionPane.showInputDialog( "Enter ly" );          String xValue =               JOptionPane.showInputDialog( "Enter x value" );     // ly value     String yValue =               JOptionPane.showInputDialog( "Enter y value" );        // convert String inputs to int values        int firstInput = Integer.parseInt( lxValue );        int secondInput = Integer.parseInt( lyValue );       int thirdInput = Integer.parseInt( xValue );        int forthInput = Integer.parseInt( yValue );               Cleaner cleaner = new Cleaner();                       frame.add(cleaner);       cleaner.lx = firstInput; = secondInput;       cleaner.x = thirdInput;       cleaner.y = forthInput;             }      } 

All help is appreciated!

How to draw the heap for an array in Java?

I have an assignment to draw the heap after an ArrayList and a LinkedList is created.

public static void main(String[] args) {      List list = new ArrayList();      list.add(0);      list.add(1);      list.add(1);      list.add(2); } 


public static void main(String[] args) {      List list = new LinkedList();     list.add(0);      list.add(1);      list.add(1);      list.add(2); } 

So far I have a tree set up for [0, 1, 1, 2] so that it just goes down like a tree from 0, 1 and 1, then 2. But I don’t know if that’s correct and if it’d be different for the ArrayList and LinkedList.

How do I approach towards an abstract production rule interpreter with this situation of converting XML to python or java class?

If I am asking in the wrong place, please forgive and direct me to a more suitable one

So I have a XML like this

<range>    unconstrained    <span>       <rttype>          String </range>  <range>    x type    <span>       <rttype>          int       <assert>          $   > 0 </range>  <range>    Simple class reference    <span>       <rttype>          SimpleClass </range>  <range>    Simple class set    <span>       <rttype>          ArrayList<SimpleClass> </range>  <class>   Simple class     <attribute>      x         <range>            x type   </attribute>    <attribute>      state   </attribute>    <action>      initializer      <guarantees>         x has been set to zero      </guarantees>      <pimaction>         .@a x @ = 0      </pimaction>   </action>    <action>      update x      <parameter>         new x         x type      <guarantees>         x has been set to new x      </guarantees>      <pimaction>         .@a x @ = @i new x @      </pimaction>   </action>    <state>      Exists   </state>    <state>      Doesn't exist   </state>    <event>      <<new>>   </event>    <event>      <<destroy>>   </event>    <event>      update   </event>    <transition>      Doesn't exist      <<new>>      Exists      <transitionaction>         initializer   </transition>    <transition>      Exists      <<destroy>>      Doesn't exist   </transition>    <transition>      Exists      update      Exists      <transitionaction>         update x   </transition> 

I have a Java compiler (let’s call this ToJavaCompiler) that will compile this into a Java class

And another Java compiler (let’s call this ToPythonCompiler) that will also compile this into a Python class.

class SimpleClass:      # State Enum Declaration     # see MMClass.ruleStateEnumDeclaration for implementation      SimpleClass_states = Enum("SimpleClass_states", "EXISTS DOESNTEXIST")      # Attribute instance variables     # see MMClass.ruleAttributeInstVarList for implementation      _x: int     _state: SimpleClass_states      # Class level attribute     # All class members accessor      SimpleClassSet: ClassVar[List[SimpleClass]] = []       # Constructor     # See MMClass.ruleConstructorOperation      # See constructEvent.ruleConstructorOperation     def __init__(self):         # requires         #    none         # guarantees         #    --> x has been set to zero and state == Exists         self._initializer()         self._state = SimpleClass.SimpleClass_states.EXISTS         SimpleClass.SimpleClassSet.append(self)      # Attribute getters      @property     def x(self) -> int:         # requires         #   none         # guarantees         #   returns the x         return self._x      @property     def state(self) -> SimpleClass_states:         # requires         #   none         # guarantees         #   returns the state         return self._state       # Pushed events      def destroy(self) -> None:         # requires         #    none         # guarantees         #   state was Exists --> state == Doesn't exist         if self._state == SimpleClass.SimpleClass_states.EXISTS:             self._state = SimpleClass.SimpleClass_states.DOESNTEXIST             SimpleClass.SimpleClassSet.remove(self)      def update(self, new_x: int) -> None:         # requires         #    none         # guarantees         #   state was Exists --> x has been set to new x         if self._state == SimpleClass.SimpleClass_states.EXISTS:             self._update_x(new_x)      # Private transition actions      def _initializer(self):         # requires         #   none         # guarantees         #   x has been set to zero         self._x = 0      def _update_x(self, new_x: int):         # requires         #   none         # guarantees         #   x has been set to new x         self._x = new_x 

THe thing is my production rule need access to instance variable data from the model object they are compiling.

For example to generate the instance variables declarations i need a production rule that’s written in Java code like this which require access to the underlying model itself at Context.model()

public void ruleAttributeInstVarList() {     // description     // this rule emits the set of (private) instance variable declarations, if any     //     // Class.#ATTRIBUTE_INST_VAR_LIST -->     // foreach anAttribute in class     // anAttribute.#DEFINE_INST_VAR     //     // requires     // none     // guarantees     // all attributes of this class have been declared as instance variable of the     // PIM Overlay run-time type     if (Context.model().isVerbose()) {         Context.codeOutput().indent();         Context.codeOutput().println("# Attribute instance variables");         Context.codeOutput().println("# see MMClass.ruleAttributeInstVarList for implementation");                  Context.codeOutput().println("");         if (!attributeSet.isEmpty()) {             for (Attribute anAttribute : attributeSet) {                 anAttribute.ruleDefineInstVarAsPrivate();             }         } else {             if (Context.model().isVerbose()) {                 Context.codeOutput().indent();                 Context.codeOutput().println("# none");             }         }         Context.codeOutput().indentLess();     } else {         for (Attribute anAttribute : attributeSet) {             anAttribute.ruleDefineInstVarAsPrivate();         }     }     Context.codeOutput().println("");     Context.codeOutput().println(""); } 

I wonder if there’s an easier way to add target languages or frameworks without creating separate codebases per target language.

For e.g. I now have a ToJavaCompiler and a ToPythonCompiler two separate codebases

So I am here asking if there’s a way I can create an abstract production rule interpreter that suits my needs. My aim is to ultimately produce model classes in the target language or framework (such as Django or Rails) with a single codebase that allows extensions for different target languages/frameworks

I am okay to move away from Java if there’s a better language that suits what I am trying to do.

Canvas VS JPanel (Java)

Everyone says all the time – "Be careful to combine Canvas with Swing components, because it is a heavyweight component and Swing is lightweight". How exactly will this harm me? Maybe in very specific cases that do not even come to my mind, but currently Canvas is the best way to develop games in Java if you use Swing in my opinion. And the fact is, Minecraft is also painted on AWT’s Canvas. Correct me if I’m wrong. But right now what gives me more control is Canvas and not JPanel.

Java Programming

Assume that you have been assigned a task to develop an application which will be handling teaching activities as the University. The application has four main entities namely administrator, lecturer, student and course. The application should be able to allow: a) Registration of classes b) Registration of modules c) Registration of lecturers d) Registration of students e) Assignment of modules into class f) Assignment of module to lecturer g) Assignment of student into class h) View all registered students, modules, classes i) View all students and their modules j) View lecturers and their modules The application should be developed by using Object Oriented programming in which encapsulation, inheritance, abstraction and polymorphism concepts MUST be observed and implemented by using Java