Singleton (Java): Difference between revisions

From My Limbic Wiki
No edit summary
No edit summary
 
(8 intermediate revisions by the same user not shown)
Line 1: Line 1:
<syntaxhighlight lang="java">
<syntaxhighlight lang="Python" line='line'>
import java.util.*;
/**
import java.io.*;
* Implémentation simple d'un singleton.
import java.math.*;
* L'instance est créée à l'initialisation.  
 
*/
class Player {
public class Singleton
 
    public static void main(String args[]) {
    /** Constructeur privé */
        Scanner in = new Scanner(System.in);
    private Singleton()
        boolean boostIsAvailable=true;
    {}
       
        // game loop
    /** Instance unique pré-initialisée */
        while (true) {
    private static Singleton INSTANCE = new Singleton();
            int x = in.nextInt();
   
            int y = in.nextInt();
    /** Point d'accès pour l'instance unique du singleton */
            int nextCheckpointX = in.nextInt(); // x position of the next check point
    public static Singleton getInstance()
            int nextCheckpointY = in.nextInt(); // y position of the next check point
    {  return INSTANCE;
            int nextCheckpointDist = in.nextInt(); // distance to the next checkpoint
            int nextCheckpointAngle = in.nextInt(); // angle between your pod orientation and the direction of the next checkpoint
            int opponentX = in.nextInt();
            int opponentY = in.nextInt();
            int thurst = 0;
            String power = "";
 
            // Write an action using System.out.println()
            // To debug: System.err.println("Debug messages...");
 
            if(nextCheckpointAngle > 90 || nextCheckpointAngle < -90){
                thurst = 0;
                power = Integer.toString(thurst);
            }else if(nextCheckpointDist > 8500 && boostIsAvailable && nextCheckpointAngle < 3 && nextCheckpointAngle > -2){
                power = "BOOST";
                boostIsAvailable=false;
            }else{
                thurst = 100;
                power = Integer.toString(thurst);
            }
           
            //Logs
            //System.err.println("Dist: "+nextCheckpointDist);
            //System.err.println("Angle: "+nextCheckpointAngle);
            //System.err.println("Boost: "+boostIsAvailable);
 
            // You have to output the target position
            // followed by the power (0 <= thrust <= 100)
            // i.e.: "x y thrust"
            System.out.println(nextCheckpointX + " " + nextCheckpointY +" "+ power);
        }
     }
     }
}
}
</syntaxhighlight>
</syntaxhighlight>

Latest revision as of 04:21, 30 May 2019

<syntaxhighlight lang="Python" line='line'> /**

* Implémentation simple d'un singleton.
* L'instance est créée à l'initialisation. 
*/

public class Singleton {

   /** Constructeur privé */
   private Singleton()
   {}

   /** Instance unique pré-initialisée */
   private static Singleton INSTANCE = new Singleton();
    
   /** Point d'accès pour l'instance unique du singleton */
   public static Singleton getInstance()
   {   return INSTANCE;
   }

} </syntaxhighlight>