Skip to main content
added 2 characters in body
Source Link
linker
  • 899
  • 1
  • 9
  • 22

Now the drawSillyThings() doesn’t need to perform any if logic while drawing because as the right events gets triggered the silly_runner gets equated to have its run_things() method invoke a different method thus using a variable to store and invoke a method kinda-ish although in the real gaming world(I actually mean inside yourin a console) several threads will work asynchronously to change interface variables to run different piece of code with the same call.

Now the drawSillyThings() doesn’t need to perform any if logic while drawing because as the right events gets triggered the silly_runner gets equated to have its run_things() method invoke a different method thus using a variable to store and invoke a method kinda-ish although in the real gaming world(I actually mean inside your console) several threads will work asynchronously to change interface variables to run different piece of code with the same call.

Now the drawSillyThings() doesn’t need to perform any if logic while drawing because as the right events gets triggered the silly_runner gets equated to have its run_things() method invoke a different method thus using a variable to store and invoke a method kinda-ish although in the real gaming world(I actually mean in a console) several threads will work asynchronously to change interface variables to run different piece of code with the same call.

added 2 characters in body
Source Link
linker
  • 899
  • 1
  • 9
  • 22
public static class InterfaceTest{

    public interface Method{
        public void invoke();
    }
    
    public static void main(String[] args){
        //lets create and store a method in a variable shall we
        Method method_variable=new Method(){
            @Override
            public void invoke(){
                //do something        
            }
        }; 

        //lets call or invoke the method from the variable in order to do something
        method_variable.invoke();
        
        //lets change the method to do something else
        method_variable=new Method(){
            @Override
            public void invoke(){
                //do something else       
            }
        };

        //lets do something else
        method_variable.invoke();            
        
     }

}
public static class InterfaceTest{

    public interface Method{
        public void invoke();
    }
    
    public static void main(String[] args){
        //lets create and store a method in a variable shall we
        Method method_variable=new Method(){
            @Override
            public void invoke(){
                //do something        
            }
        };
        //lets call or invoke the method from the variable in order to do something
        method_variable.invoke();
        
        //lets change the method to do something else
        method_variable=new Method(){
            @Override
            public void invoke(){
                //do something else       
            }
        };
        
        
     }

}
public static class InterfaceTest{

    public interface Method{
        public void invoke();
    }
    
    public static void main(String[] args){
        //lets create and store a method in a variable shall we
        Method method_variable=new Method(){
            @Override
            public void invoke(){
                //do something        
            }
        }; 

        //lets call or invoke the method from the variable in order to do something
        method_variable.invoke();
        
        //lets change the method to do something else
        method_variable=new Method(){
            @Override
            public void invoke(){
                //do something else       
            }
        };

        //lets do something else
        method_variable.invoke();            
        
     }

}
added 2 characters in body
Source Link
linker
  • 899
  • 1
  • 9
  • 22
public static class SoulAvenger{

    private interface SillyRunner{
        public void run_things();
    }

    ...//soul avenging variables
    private SillyRunner silly_runner;

    public SoulAvenger(int game_state){
        //logic check is performed once instead of multiple times in a nested loop
        if(game_state=medium_blows){
            silly_runner=new SillyRunner(){
                @Override
                public void run_things(){
                    drawUpperCut();
                }
            };
        }else if(game_state=heavy_blows){
            silly_runner=new SillyRunner(){
                @Override
                public void run_things(){
                    drawTotalKO();
                }
            };
        }else if(game_state=lost){
            silly_runner=new SillyRunner(){
                @Override
                public void run_things(){
                    drawDefeatAndMockery();
                }
            };
        }else if(game_state=won){
            silly_runner=new SillyRunner(){
                @Override
                public void run_things(){
                    drawVictoryAndGlorifiedRanger();
                }
            };
        }else if(game_state=fight){
            silly_runner=new SillyRunner(){
                @Override
                public void run_things(){
                    drawFightRecap();
                }
            };
            
        }

    }

    private void loadLevel5k(){
        //an event triggered method to change how you run things to load level 5k
        silly_runner=new SillyRunner(){
            @Override
            public void run_things(){
                //level 5k logic
            }
        };
    }

    private void dontAllowUserWinOnTime(){
        //an event triggered method to help user get annoyed and addicted to the game
        silly_runner=new SillyRunner(){
            @Override
            public void run_things(){
                drawDefeatAndMockery();
            }
        };
    }

    private void loadGrimReaperFight(){
        //an event triggered method to send an invitation to the nearest grim-reaper
        silly_runner=new SillyRunner(){
            @Override
            public void run_things(){
                inviteTheGrimReaper();
            }
        };
    }

    private void drawSillyThings(){
        ...//unaccounted game logic
        while(fighting_in_level_5k){
            while(soul_ranger_has_enough_lives){
                silly_runner.run_things();
            }
        }
    }
 
    private interface SillyRunner{
        public void run_things();
    }
}
public static class SoulAvenger{

    ...//soul avenging variables
    private SillyRunner silly_runner;

    public SoulAvenger(int game_state){
        //logic check is performed once instead of multiple times in a nested loop
        if(game_state=medium_blows){
            silly_runner=new SillyRunner(){
                @Override
                public void run_things(){
                    drawUpperCut();
                }
            };
        }else if(game_state=heavy_blows){
            silly_runner=new SillyRunner(){
                @Override
                public void run_things(){
                    drawTotalKO();
                }
            };
        }else if(game_state=lost){
            silly_runner=new SillyRunner(){
                @Override
                public void run_things(){
                    drawDefeatAndMockery();
                }
            };
        }else if(game_state=won){
            silly_runner=new SillyRunner(){
                @Override
                public void run_things(){
                    drawVictoryAndGlorifiedRanger();
                }
            };
        }else if(game_state=fight){
            silly_runner=new SillyRunner(){
                @Override
                public void run_things(){
                    drawFightRecap();
                }
            };
            
        }

    }

    private void loadLevel5k(){
        //an event triggered method to change how you run things to load level 5k
        silly_runner=new SillyRunner(){
            @Override
            public void run_things(){
                //level 5k logic
            }
        };
    }

    private void dontAllowUserWinOnTime(){
        //an event triggered method to help user get annoyed and addicted to the game
        silly_runner=new SillyRunner(){
            @Override
            public void run_things(){
                drawDefeatAndMockery();
            }
        };
    }

    private void loadGrimReaperFight(){
        //an event triggered method to send an invitation to the nearest grim-reaper
        silly_runner=new SillyRunner(){
            @Override
            public void run_things(){
                inviteTheGrimReaper();
            }
        };
    }

    private void drawSillyThings(){
        ...//unaccounted game logic
        while(fighting_in_level_5k){
            while(soul_ranger_has_enough_lives){
                silly_runner.run_things();
            }
        }
    }
 
    private interface SillyRunner{
        public void run_things();
    }
}
public static class SoulAvenger{

    private interface SillyRunner{
        public void run_things();
    }

    ...//soul avenging variables
    private SillyRunner silly_runner;

    public SoulAvenger(int game_state){
        //logic check is performed once instead of multiple times in a nested loop
        if(game_state=medium_blows){
            silly_runner=new SillyRunner(){
                @Override
                public void run_things(){
                    drawUpperCut();
                }
            };
        }else if(game_state=heavy_blows){
            silly_runner=new SillyRunner(){
                @Override
                public void run_things(){
                    drawTotalKO();
                }
            };
        }else if(game_state=lost){
            silly_runner=new SillyRunner(){
                @Override
                public void run_things(){
                    drawDefeatAndMockery();
                }
            };
        }else if(game_state=won){
            silly_runner=new SillyRunner(){
                @Override
                public void run_things(){
                    drawVictoryAndGlorifiedRanger();
                }
            };
        }else if(game_state=fight){
            silly_runner=new SillyRunner(){
                @Override
                public void run_things(){
                    drawFightRecap();
                }
            };
            
        }

    }

    private void loadLevel5k(){
        //an event triggered method to change how you run things to load level 5k
        silly_runner=new SillyRunner(){
            @Override
            public void run_things(){
                //level 5k logic
            }
        };
    }

    private void dontAllowUserWinOnTime(){
        //an event triggered method to help user get annoyed and addicted to the game
        silly_runner=new SillyRunner(){
            @Override
            public void run_things(){
                drawDefeatAndMockery();
            }
        };
    }

    private void loadGrimReaperFight(){
        //an event triggered method to send an invitation to the nearest grim-reaper
        silly_runner=new SillyRunner(){
            @Override
            public void run_things(){
                inviteTheGrimReaper();
            }
        };
    }

    private void drawSillyThings(){
        ...//unaccounted game logic
        while(fighting_in_level_5k){
            while(soul_ranger_has_enough_lives){
                silly_runner.run_things();
            }
        }
    }

}
added 3 characters in body
Source Link
linker
  • 899
  • 1
  • 9
  • 22
Loading
Source Link
linker
  • 899
  • 1
  • 9
  • 22
Loading
Post Made Community Wiki by linker