Exemplo n.º 1
0
 //clears a peg in between the previous one and the new one
 void removePeg(GameObject startPeg, GameObject endPeg)
 {
     pegToRemove = getPegInbetween(startPeg, endPeg);
     //remove peg
     removeScript = pegToRemove.GetComponent <PegScript>();
     removeScript.setHasPeg(false);
     removeScript.setEmpty();
 }
Exemplo n.º 2
0
    //checks all of the game objects to search for isSelected = true
    //restricts selection to one peg only
    GameObject checkSelectedPeg()
    {
        for (int i = 0; i < board.Count; i++)
        {
            for (int j = 0; j < board [i].Length; j++)
            {
                currentPeg       = board [i] [j];
                currentPegScript = board [i] [j].GetComponent <PegScript> ();
                //checks if the selection is a peg
                if (currentPegScript.getIsSelected() == true && currentPegScript.getHasPeg() == true)
                {
                    if (currentPeg.Equals(previousPeg))
                    {
                        //continues the loop to check for a new peg
                        continue;
                    }
                    else
                    {
                        //set previous peg to not selected
                        if (previousPeg != null)
                        {
                            previousPegScript = previousPeg.GetComponent <PegScript>();
                            previousPegScript.setIsSelected(false);
                            previousPegScript.setPeg();
                        }
                        currentPegScript.setPegSelected();
                        previousPeg = currentPeg;
                        return(currentPeg);
                    }
                }

                //checks if the selection is an empty space
                else if (currentPegScript.getIsSelected() == true && currentPegScript.getHasPeg() == false)
                {
                    //if its a valid move
                    if (validMoves != null)
                    {
                        if (validMoves.Contains(currentPeg))
                        {
                            //set the previous peg to empty
                            if (previousPeg != null)
                            {
                                previousPegScript = previousPeg.GetComponent <PegScript> ();
                                previousPegScript.setIsSelected(false);
                                previousPegScript.setHasPeg(false);
                                previousPegScript.setEmpty();
                            }
                            currentPegScript.setPeg();
                            previousPeg = currentPeg;
                            return(currentPeg);
                        }
                        //if its not a valid move, remove the isSelected return the seleted peg
                        else
                        {
                            currentPegScript.setIsSelected(false);
                            return(selectedPeg);
                        }
                    }
                }
            }
        }
        //always return the current peg in case of errant clicks
        return(selectedPeg);
    }