Exemplo n.º 1
0
    // Check if coordinates are in the echiquier=true, outside=false
    private bool GetPositionBoundaries(posInEchiquier_t inPos)
    {
        // Target case
        if ((inPos.x == AllGameParameters.ECHIQUIER_COLUMNS) && (inPos.y == (AllGameParameters.ECHIQUIER_LINES - 1)))
        {
            return(true);
        }

        // check if case is outside
        if ((inPos.x < 0) || (inPos.x >= AllGameParameters.ECHIQUIER_COLUMNS))
        {
            return(false);
        }
        else
        {
            if ((inPos.y < 0) || (inPos.y >= AllGameParameters.ECHIQUIER_LINES))
            {
                return(false);
            }
            else
            {
                return(true);
            }
        }
    }
Exemplo n.º 2
0
    //////////////////////////////////////////////////////////////////////////////////
    // Local functiuns
    //////////////////////////////////////////////////////////////////////////////////

    // Determine destination position according to previous position and cadran where mouse released (MOUSE UP)
    private posInEchiquier_t GetPositionFromCadran(posInEchiquier_t previousPosition, int cadran)
    {
        int deltaX, deltaY;
        posInEchiquier_t result = previousPosition;

        // Compute increments/decrements according to cadran
        switch (cadran)
        {
        case 1:
            deltaX = 1;
            deltaY = 0;
            break;

        case 2:
            deltaX = 1;
            deltaY = -1;
            break;

        case 3:
            deltaX = 0;
            deltaY = -1;
            break;

        case 4:
            deltaX = -1;
            deltaY = -1;
            break;

        case 5:
            deltaX = -1;
            deltaY = 0;
            break;

        case 6:
            deltaX = -1;
            deltaY = 1;
            break;

        case 7:
            deltaX = 0;
            deltaY = 1;
            break;

        case 8:
            deltaX = 1;
            deltaY = 1;
            break;

        default:
            deltaX = 0;
            deltaY = 0;
            break;
        }

        result.x += deltaX;
        result.y += deltaY;

        return(result);
    }
Exemplo n.º 3
0
 //////////////////////////////////////////////////////////////////////////////////
 // Constructor
 //////////////////////////////////////////////////////////////////////////////////
 ///
 public carafeObject(int color, int type, int volume, posInEchiquier_t pos, int graphicalType)
 {
     internalColor         = color;
     internalType          = type;
     internalVolume        = volume;
     internalPos           = pos;
     internalGraphicalType = graphicalType;
 }
Exemplo n.º 4
0
    // Initialization
    void Start()
    {
        GameObject   myLocalCarafeObject;
        carafeObject theCarafe;
        Vector2      vect2;
        bool         bAcidAlready = false;

        // Set the start time according to difficulty level
        myUniqueController.InitializeStarTime();

        // Load the images
        spriteObject = (Sprite[])Resources.LoadAll <Sprite>("carafe-map-final");

        // Create the carafeFinalTarget
        int targetVolume;

        if (myUniqueController.getGameMode() == AllGameParameters.GAME_MODE_UNLIMITED)
        {
            do
            {
                targetVolume = getRandomVolume();
            } while (targetVolume == AllGameParameters.VOLUME_0);

            theFinalCarafeTarget = new carafeFinalObject(getRandomColorRGB(), targetVolume, AllGameParameters.LIQUID_TYPE_WATER);
        }
        else
        {
            theFinalCarafeTarget = myLevelsData.theFinalCarafeLevel[myUniqueController.getCurrenLevel()];
        }
        if (theFinalCarafeTarget == null)
        {
            Debug.LogError("theFinalCarafeTarget=" + theFinalCarafeTarget);
        }

        // Set the correct sprite for Final Carafe Target
        UpdateFinalCarafeTarget();

        // Create all the cases
        theCases = new caseObject[AllGameParameters.ECHIQUIER_COLUMNS, AllGameParameters.ECHIQUIER_LINES];

        // Create all the Carafe objects (one per each case)
        allTheCarafes = new GameObject[AllGameParameters.ECHIQUIER_COLUMNS, AllGameParameters.ECHIQUIER_LINES];

        // If UNLIMITED mode, all is random
        for (int column = 0; column < AllGameParameters.ECHIQUIER_COLUMNS; column++)
        {
            for (int line = 0; line < AllGameParameters.ECHIQUIER_LINES; line++)
            {
                posInEchiquier_t pos;

                pos.x = column;
                pos.y = line;

                if (myUniqueController.getGameMode() == AllGameParameters.GAME_MODE_UNLIMITED)
                {
                    int rndType   = getRandomType();
                    int rndColor  = getRandomColor();
                    int rndVolume = getRandomVolume();

                    // Type cannot be wall if position is next to Target Carafe (otherwise, the game is blocked)
                    if (column == (AllGameParameters.ECHIQUIER_COLUMNS - 1) && (line == (AllGameParameters.ECHIQUIER_LINES - 1)))
                    {
                        rndType = AllGameParameters.LIQUID_TYPE_WATER;
                    }

                    // There can be only 1 acid in the game
                    if (rndType == AllGameParameters.LIQUID_TYPE_ACID)
                    {
                        if (bAcidAlready == true)
                        {
                            rndType = AllGameParameters.LIQUID_TYPE_WATER;
                        }
                        else
                        {
                            bAcidAlready = true;
                            rndColor     = AllGameParameters.CARAFE_WHITE;
                            rndVolume    = AllGameParameters.VOLUME_NEGATIF;
                        }
                    }

                    // determine random carafe
                    theCarafe = new carafeObject(rndColor, rndType, rndVolume, pos, AllGameParameters.GRAPHICAL_TYPE_STANDARD);
                }
                else
                {
                    // Set objects according to level
                    theCarafe = myLevelsData.theLevelCases[myUniqueController.getCurrenLevel(), column, line].getCaseCarafe();
                    if (theCarafe == null)
                    {
                        Debug.LogError("theCarafe=" + theFinalCarafeTarget);
                    }
                }

                theCases[column, line] = new caseObject(true, theCarafe);

                // Instantiate the Liquid objects (according to their volume)
                vect2 = getRealPos(column, line);
                myLocalCarafeObject = (GameObject)Instantiate(getCorrectObjWithVolume(theCarafe.getCarafeVolume(), theCarafe.getCarafeType()), vect2, transform.rotation);
                if (myLocalCarafeObject == null)
                {
                    Debug.LogError("ERROR myLocalCarafeObject");
                }

                // Set the correct color to the object
                sr       = (SpriteRenderer)myLocalCarafeObject.GetComponentsInChildren <SpriteRenderer>()[1];
                sr.color = getSpriteColor(theCarafe.getCarafeColor());

                // Set the carafes
                allTheCarafes[column, line] = myLocalCarafeObject;
            }
        }

        // Check if there is at least one red, one green and one blue, if not start again
        if (checkGameColors() == false)
        {
            //goto setEachCarafeInTheGame;
            SceneManager.LoadScene("Main");
        }

        // Set the FinaleCarafe Object (empty)
        theFinalCarafe = new carafeFinalObject(AllGameParameters.CARAFE_RED, AllGameParameters.VOLUME_0, AllGameParameters.LIQUID_TYPE_WATER);

        // Initialize positions outside the Echiquier
        clickPosDown = resetPosition();
        clickPosUp   = resetPosition();

        // Set the start time
        myUniqueController.InitializeT0();

        // Start the time
        Time.timeScale = 1f;
    }
Exemplo n.º 5
0
    //////////////////////////////////////////////////////////////////////////////////
    // Update is called once per frame
    //////////////////////////////////////////////////////////////////////////////////
    void Update()
    {
        carafeObject sourceCarafe;
        carafeObject destinationCarafe;
        string       timeStr;

        timeStr = myUniqueController.timeMngt();
        if (timeStr == null)
        {
            // GAME OVER : Timeout !!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!
            SoundManager.gameSoundManager.PlaySound(SoundManager.SOUND_GAME_OVER);

            // Save score in GGPS (and level)
            GGPS_GameEndManagement(myUniqueController.getGameMode(), myUniqueController.getScore(), myUniqueController.getCurrenLevel());

            // Come back to main screen
            SceneManager.LoadScene("StartMenu");
        }
        else
        {
            // Check if bip for last 3 seconds
            BipForLast3Seconds();
        }

        // Update score text
        SetTextValue(timeStr);

        // MOUSE BUTTON DOWN
        if (Input.GetMouseButtonDown(0))
        {
            // Get the position when the mouse button was DOWN
            posDown = getMouseClick();
            // And get echiquier position
            clickPosDown = getEchiquerClick(posDown);
            SoundManager.gameSoundManager.PlaySound(SoundManager.SOUND_CLICK);
        }

        // MOUSE BUTTON UP
        if (Input.GetMouseButtonUp(0))
        {
            // Get the position when the mouse button was UP
            posUp = getMouseClick();
            int n = GetCadran(posDown, posUp);
            clickPosUp = GetPositionFromCadran(clickPosDown, n);

            // We have to load new Recipient and unload current one
            if ((GetPositionBoundaries(clickPosUp) == false) || (GetPositionBoundaries(clickPosDown) == false))
            {
                return;
            }

            sourceCarafe = theCases[clickPosDown.x, clickPosDown.y].getCaseCarafe();
            if (sourceCarafe.getCarafeVolume() == AllGameParameters.VOLUME_0)
            {
                return;
            }

            // Check if loading FinalCarafe
            if (checkFinalCarafeMovement())
            {
                // Yes, we load FinaleCarafe
                SoundManager.gameSoundManager.PlaySound(SoundManager.SOUND_COIN);

                int remainingVolume;
                remainingVolume = theFinalCarafe.loadCarafe(sourceCarafe.getCarafeVolume(), sourceCarafe.getCarafeColor());
                sourceCarafe.unloadCarafe(remainingVolume);

                // Check if carafe is ACID type
                if (sourceCarafe.getCarafeType() == AllGameParameters.LIQUID_TYPE_ACID)
                {
                    sourceCarafe.setCarafeVolume(AllGameParameters.VOLUME_0);
                    sourceCarafe.setCarafeType(AllGameParameters.LIQUID_TYPE_WATER);
                }
                if (theFinalCarafe.getCarafeVolume() >= 0)
                {
                    theFinalCarafe.setCarafeType(AllGameParameters.LIQUID_TYPE_WATER);
                }
                else
                {
                    // If volume is negative, it is an ACID bottle
                    theFinalCarafe.setCarafeType(AllGameParameters.LIQUID_TYPE_ACID);
                }

                // Update the display
                UpdateCarafeInPosition(sourceCarafe, clickPosDown.x, clickPosDown.y);
                UpdateFinalCarafe();

                // CHECK IF PLAYER HAS WIN !
                if ((theFinalCarafe.getCarafeColor() == theFinalCarafeTarget.getCarafeColor()) && (theFinalCarafe.getCarafeVolume() == theFinalCarafeTarget.getCarafeVolume()))
                {
                    // LEVEL FINISHED !!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!
                    SoundManager.gameSoundManager.PlaySound(SoundManager.SOUND_FINISH);

                    // Give score (depends on remaining time)
                    myUniqueController.setTimeValue();
                    myUniqueController.increaseScore(myUniqueController.giveScoreBonus());

                    // Check if an Achievement (trophe) can be done for the time
                    GGPS_Manager.GGPS_GainTimeAchievement(myUniqueController.getPassedTimeInSecondsWithDecimal());

                    // Increment current Level value
                    myUniqueController.incrementCurrenLevel();

                    // Check if an Achievement (trophe) can be done for the level reached
                    GGPS_Manager.GGPS_GainAchievement(myUniqueController.getGameMode(), myUniqueController.getCurrenLevel());

                    // Save last reached level in Campaign mode
                    if (myUniqueController.getGameMode() == AllGameParameters.GAME_MODE_CAMPAIGN)
                    {
                        int curLevel = myUniqueController.getCurrenLevel();

                        // Debug.Log ("FINISHED !! - cureLevel=" + curLevel + " - currentlyReachedLevel=" + SettingsParameters.currentlyReachedLevel);
                        if (curLevel >= SettingsParameters.currentlyReachedLevel)
                        {
                            // Save new game level
                            SettingsParameters.currentlyReachedLevel = curLevel;
                        }

                        // Save parameters in persistant data
                        SettingsParameters.SaveSettings();

                        // Check if we reached last Screen in Campaign mode
                        if (curLevel == SettingsParameters.LEVEL_NUMBER)
                        {
                            // We reached last level ==> Finished
                            SceneManager.LoadScene("FinishScreen");
                            return;
                        }
                    }

                    // Load WaiScreen scene
                    SceneManager.LoadScene("WaitScreen");
                }

                return;
            }

            // Check if movement is possible (just around current position)
            if (checkMovement())
            {
                // Determine the source & destination carafes
                sourceCarafe      = theCases[clickPosDown.x, clickPosDown.y].getCaseCarafe();
                destinationCarafe = theCases[clickPosUp.x, clickPosUp.y].getCaseCarafe();

                // Check if source of destination is a WALL, in this case nothing happens
                if ((sourceCarafe.getCarafeType() == AllGameParameters.LIQUID_TYPE_WALL) || (destinationCarafe.getCarafeType() == AllGameParameters.LIQUID_TYPE_WALL))
                {
                    return;
                }

                // movement is OK
                SoundManager.gameSoundManager.PlaySound(SoundManager.SOUND_COIN);

                // We have to load new Recipient and unload current one
                int remainingVolume;
                remainingVolume = destinationCarafe.loadCarafe(sourceCarafe.getCarafeVolume(), sourceCarafe.getCarafeColor());
                sourceCarafe.unloadCarafe(remainingVolume);

                // Check if carafe is ACID type
                if (sourceCarafe.getCarafeType() == AllGameParameters.LIQUID_TYPE_ACID)
                {
                    sourceCarafe.setCarafeVolume(AllGameParameters.VOLUME_0);
                    sourceCarafe.setCarafeType(AllGameParameters.LIQUID_TYPE_WATER);
                }
                if (destinationCarafe.getCarafeVolume() >= 0)
                {
                    destinationCarafe.setCarafeType(AllGameParameters.LIQUID_TYPE_WATER);
                }
                else
                {
                    // If volume is negative, it is an ACID bottle
                    destinationCarafe.setCarafeType(AllGameParameters.LIQUID_TYPE_ACID);
                }

                // Update the display
                UpdateCarafeInPosition(sourceCarafe, clickPosDown.x, clickPosDown.y);
                UpdateCarafeInPosition(destinationCarafe, clickPosUp.x, clickPosUp.y);

                myUniqueController.increaseScore(1);
            }
            else
            {
                // Debug.LogWarning ("MOV KO"); // TO REMOVE
                clickPosDown = resetPosition();
                clickPosUp   = resetPosition();
            }
        }
    }
Exemplo n.º 6
0
 public void setCarafePos(posInEchiquier_t val)
 {
     internalPos = val;
 }