Subversion Repositories AndroidProjects

Rev

Rev 130 | Blame | Compare with Previous | Last modification | View Log | RSS feed

package com.gebauz.pingK.common.game;

import java.util.Random;

import android.util.Log;

/** This class uses the Service Locator pattern to provide required globally accessible objects.
 */

public class GameServices
{
        public static abstract class AdListener
        {
                public abstract void showAd(boolean show);
        }
       
        private static Font mFont = null;
//      private static Context mContext = null;
        private static Random mRandomizer = new Random();
       
        private static boolean mAdsEnabled = false;
       
        private static Sounds mSounds = null;
       
        private static AdListener mAdListener = null;
       
        public static void initServices()
        {
//              mContext = context;
                if (mFont == null)
                {
                        mFont = new Font();
                }
               
                if (mSounds == null)
                {
                        mSounds = new Sounds();
                }
        }
       
/*      static public Context getContext()
        {
                return mContext;
        }*/

       
        public static Font getFont()
        {
                return mFont;
        }
       
        public static Random getRandomizer()
        {
                return mRandomizer;
        }
       
        public static float getRandomFloat(float min, float max)
        {
                return min + mRandomizer.nextFloat() * (max-min);
        }
       
        public static int getRandomInt(int min, int max)
        {
                return min + mRandomizer.nextInt(max-min);
        }
       
        public static boolean areAdsEnabled()
        {
                return mAdsEnabled;
        }
       
        public static void setAdsEnabled(boolean adsEnabled)
        {
                mAdsEnabled = adsEnabled;
        }
       
        public static Sounds getAudio()
        {
                return mSounds;        
        }
       
        public static void playSound(int sound)
        {
                getAudio().playSound(sound);
        }
       
        public static void setAdListener(AdListener listener)
        {
                mAdListener = listener;
        }
       
        public static void showAd(boolean show)
        {
                if (mAdListener != null)
                        mAdListener.showAd(show);
        }

}