// Decompiled by DJ v3.0.0.63 Copyright 2002 Atanas Neshkov  Date: 11/09/2002 17:30:32
// Home Page : http://members.fortunecity.com/neshkov/dj.html  - Check often for new version!
// Decompiler options: packimports(3) 
// Source File Name:   SnakeConfig.java

import java.awt.Color;
import java.io.*;
import java.net.MalformedURLException;
import java.net.URL;
import java.util.Properties;

public class SnakeConfig
{

    public SnakeConfig(String s)
    {
        levelText = "Level";
        selectLevelText = "Select level, click to play";
        scoreText = "Your score:";
        gameOverText = "Game Over!";
        clickToPlayText = "Click to play again";
        textMaxLength = 164;
        backgroundColor = new Color(Integer.parseInt("94BD7B", 16));
        readProperties(readConfigFile(s));
    }

    public SnakeConfig()
    {
        levelText = "Level";
        selectLevelText = "Select level, click to play";
        scoreText = "Your score:";
        gameOverText = "Game Over!";
        clickToPlayText = "Click to play again";
        textMaxLength = 164;
        backgroundColor = new Color(Integer.parseInt("94BD7B", 16));
    }

    public String getLevelText()
    {
        return levelText;
    }

    public String getSelectLevelText()
    {
        return selectLevelText;
    }

    public String getScoreText()
    {
        return scoreText;
    }

    public String getGameOverText()
    {
        return gameOverText;
    }

    public String getClickToPlayText()
    {
        return clickToPlayText;
    }

    public int getTextMaxLength()
    {
        return textMaxLength;
    }

    public Color getBackgroundColor()
    {
        return backgroundColor;
    }

    public URL getServerUrl()
    {
        return serverUrl;
    }

    public void setServerUrl(String s)
    {
        serverUrl = extractUrl(s);
    }

    private URL extractUrl(String s)
    {
        URL url = null;
        try
        {
            if(s.startsWith("file://"))
                url = new URL("file", "", s.substring(7));
            else
                url = new URL(s);
        }
        catch(MalformedURLException _ex)
        {
            System.err.println("Not a proper url: " + s);
        }
        return url;
    }

    private Properties readConfigFile(String s)
    {
        Properties properties = new Properties();
        InputStream inputstream = null;
        URL url = extractUrl(s);
        try
        {
            if(url != null)
            {
                inputstream = url.openStream();
                if(inputstream != null)
                    properties.load(inputstream);
            }
        }
        catch(FileNotFoundException _ex)
        {
            System.err.println("File not found: " + s);
        }
        catch(IOException _ex)
        {
            System.err.println("IOException while trying to read config file in SnakeConfig.readConfigFile(): " + s);
        }
        finally
        {
            try
            {
                if(inputstream != null)
                    inputstream.close();
            }
            catch(IOException _ex) { }
        }
        return properties;
    }

    private String getProperty(Properties properties, String s, String s1)
    {
        String s2 = properties.getProperty(s);
        if(s2 == null || s2.length() <= 0)
            System.err.println(s + " not specified, using default value.");
        return properties.getProperty(s, s1);
    }

    private void readProperties(Properties properties)
    {
        backgroundColor = new Color(Integer.parseInt(getProperty(properties, "BCOLOR", "94BD7B"), 16));
        levelText = getProperty(properties, "MSG_LEVEL", "Level");
        selectLevelText = getProperty(properties, "MSG_SELECT_LEVEL", "Select level, click to play");
        scoreText = getProperty(properties, "MSG_SCORE", "Your score:");
        gameOverText = getProperty(properties, "MSG_GAME_OVER", "Game Over!");
        clickToPlayText = getProperty(properties, "MSG_CLICK_TO_PLAY", "Click to play again");
        String s = properties.getProperty("SRV_URL");
        if(s != null && s.length() > 0)
        {
            serverUrl = extractUrl(s);
            return;
        } else
        {
            System.err.println("SRV_URL not specified in the config file, possibly no communication with the high score server possible");
            return;
        }
    }

    private String levelText;
    private String selectLevelText;
    private String scoreText;
    private String gameOverText;
    private String clickToPlayText;
    private int textMaxLength;
    private Color backgroundColor;
    private URL serverUrl;
}