Exemplo n.º 1
0
    private (ButtonObj, ButtonObj) GetNextMove(List <ButtonObj> buttons, Find FindNet)
    {
        int       max        = Int32.MinValue;
        ButtonObj currButton = null;
        ButtonObj nextButton = null;

        foreach (ButtonObj button in buttons)
        {
            List <ButtonObj> neighbors = FindAvailableButtons(button);
            foreach (ButtonObj neighbor in neighbors)
            {
                int net = FindNet(button, neighbor, GetEnemyState(currPlayerIndex));
                if (net > max)
                {
                    currButton = button;
                    nextButton = neighbor;
                    max        = net;
                }
                else if (net == max)
                {
                    bool rand = Random.Range(0, 1) > 0.5;
                    currButton = rand ? currButton : button;
                    nextButton = rand ? nextButton : neighbor;
                    max        = rand ? max : net;
                }
            }
        }
        return(currButton, nextButton);
    }
Exemplo n.º 2
0
 public void AddButton(ButtonObj button)
 {
     if (this.Buttons.Contains(button))
     {
         return;
     }
     button.CurrState = PlayerIndex == 0 ? State.cat : State.dog;
     this.Buttons.Add(button);
 }
Exemplo n.º 3
0
    private IEnumerator RunCommon(ButtonObj currButton, ButtonObj nextButton)
    {
        yield return(new WaitForSeconds(0.5f));

        ClickEvent(currButton);
        yield return(new WaitForSeconds(0.5f));

        ClickEvent(nextButton);
    }
Exemplo n.º 4
0
    private void ConsumeButton(ButtonObj clickedButton)
    {
        List <ButtonObj> neighbors = FindNeighbors(clickedButton, 1);

        foreach (ButtonObj neighbor in neighbors)
        {
            if (IsEnemy(neighbor))
            {
                players[currPlayerIndex].AddButton(neighbor);
                players[(currPlayerIndex == 0) ? 1 : 0].RemoveButton(neighbor);
            }
        }
    }
Exemplo n.º 5
0
    private void PlayAudio(ButtonObj button)
    {
        switch (button.CurrState)
        {
        case State.cat:
            button.catClickedSound.Play();
            break;

        case State.dog:
            // button.dogClickedSound.Play();
            break;
        }
    }
Exemplo n.º 6
0
    private int FindLoss(ButtonObj currButton, State enemyState)
    {
        int loss = 0;

        foreach (ButtonObj neighbor in FindNeighbors(currButton, 2))
        {
            if (neighbor.CurrState == enemyState)
            {
                loss--;
            }
        }
        return(loss);
    }
Exemplo n.º 7
0
    private void Attack(ButtonObj clickedButton)
    {
        ClearBorders();

        int dist = GetDistance(selectedButton, clickedButton);

        if (dist <= 2)
        {
            if (dist == 2)
            {
                RemoveCurrentButton();
            }
            MoveButton(clickedButton);
            ConsumeButton(clickedButton);
            EndTurn();
        }
    }
Exemplo n.º 8
0
        private void EnableDisableButton()
        {
            Button[] Buttons = new Button[] { Button1, Button2, Button3 };

            foreach (var ButtonObj in Buttons)
            {
                if (ButtonObj.Enabled == true)
                {
                    ButtonObj.Enabled = false;
                }
                else
                {
                    ButtonObj.Enabled = true;
                }
                ButtonObj.Refresh();
            }
        }
Exemplo n.º 9
0
    private int FindGain(ButtonObj currButton, ButtonObj selectedButton, State enemyState)
    {
        int gain = 0;

        if (GetDistance(currButton, selectedButton) == 1)
        {
            gain++;
        }
        foreach (ButtonObj neighbor in FindNeighbors(selectedButton, 1))
        {
            if (neighbor.CurrState == enemyState)
            {
                gain++;
            }
        }
        return(gain);
    }
Exemplo n.º 10
0
    private List <ButtonObj> VisitNeighbors(ButtonObj button, int gap, Function f)
    {
        List <ButtonObj> retList = new List <ButtonObj>();
        Pair             coord   = button.coord;

        for (int x = coord.X - gap; x <= coord.X + gap; x++)
        {
            for (int y = coord.Y - gap; y <= coord.Y + gap; y++)
            {
                if (f(x, y, coord.X, coord.Y))
                {
                    retList.Add(buttonList[GetPosition(x, y)]);
                }
            }
        }
        return(retList);
    }
Exemplo n.º 11
0
    float cutoutPos;                                                                                                                                                                                                          //the position of the cutout object.
    #endregion

    // Use this for initialization
    void Start()
    {
        Cursor.visible            = true;                                                    //show the users mouse.
        gameController            = GameObject.Find("GameController");                       //find the game controller object so we can access its script.
        script                    = gameController.GetComponent <GameController>();          //holds the script attached to the game controller object.
        cutoutPos                 = script.cutoutX;                                          //get the position of the cutout from the save file.
        cutout.transform.position = new Vector3(cutoutPos, cutout.transform.position.y, -1); //set the position of the cutout game object.

        #region initialize buttons
        // navigation buttons
        playButton      = new ButtonObj(play, "Play");
        gameModesButton = new ButtonObj(gameMode, "Game Modes");
        optionsButton   = new ButtonObj(options, "Options");
        creditsButton   = new ButtonObj(credits, "Credits");
        quitButton      = new ButtonObj(quit, "Quit");
        resetButton     = new ButtonObj(reset, "Reset");
        backButton      = new ButtonObj(back, "Back");

        // color buttons
        orangeButton = new ButtonObj(orange, "Orange");
        blueButton   = new ButtonObj(blue, "Blue");
        greenButton  = new ButtonObj(green, "Green");
        purpleButton = new ButtonObj(purple, "Purple");
        pinkButton   = new ButtonObj(pink, "Pink");

        // sound buttons
        onButton  = new ButtonObj(on, "On");
        offButton = new ButtonObj(off, "Off");

        //credits buttons
        tacoButton   = new ButtonObj(taco, "BrokenTaco");
        cksnedButton = new ButtonObj(cksned, "CkSned");

        // initialize button sets
        navButtonSet = new HashSet <ButtonObj>()
        {
            playButton, gameModesButton, optionsButton, creditsButton, quitButton, resetButton, backButton, tacoButton, cksnedButton
        };                                                                                                                                                                           // adds all nav buttons to this set
        colorButtonSet = new HashSet <ButtonObj> ()
        {
            orangeButton, pinkButton, greenButton, purpleButton, blueButton
        };                                                                                                                     // /adds all color buttons to this set
        #endregion
    }
Exemplo n.º 12
0
 /// コンストラクタ
 public Gui()
 {
     // Wave数
     _txtWave = MyCanvas.Find <TextObj>("TextWave");
     // 所持金テキスト
     _txtMoney = MyCanvas.Find <TextObj>("TextMoney");
     // コストテキスト
     _txtCost       = MyCanvas.Find <TextObj>("TextCost");
     _txtCost.Label = "";
     // 購入ボタン
     _btnBuy = MyCanvas.Find <ButtonObj>("ButtonBuy");
     // タワー情報を取得する
     _txtTowerInfo = MyCanvas.Find <TextObj>("TextTowerInfo");
     // 射程範囲ボタン
     _btnRange = MyCanvas.Find <ButtonObj>("ButtonRange");
     // 連射速度ボタン
     _btnFirerate = MyCanvas.Find <ButtonObj>("ButtonFirerate");
     // 攻撃威力ボタン
     _btnPower = MyCanvas.Find <ButtonObj>("ButtonPower");
 }
Exemplo n.º 13
0
 /// コンストラクタ
 public Gui2()
 {
     // Wave数
     _txtWave = MyCanvas.Find <TextObj>("TextWave2");
     // 所持金テキスト
     _txtMoney2 = MyCanvas.Find <TextObj>("TextMoney2");
     // コストテキスト
     _txtCost2       = MyCanvas.Find <TextObj>("TextCost2");
     _txtCost2.Label = "";
     // 購入ボタン
     _btnBuy2 = MyCanvas.Find <ButtonObj>("ButtonBuy2");
     // タワー情報を取得する
     _txtTowerInfo2 = MyCanvas.Find <TextObj>("TextTowerInfo2");
     // 射程範囲ボタン
     _btnRange2 = MyCanvas.Find <ButtonObj>("ButtonRange2");
     // 連射速度ボタン
     _btnFirerate2 = MyCanvas.Find <ButtonObj>("ButtonFirerate2");
     // 攻撃威力ボタン
     _btnPower2 = MyCanvas.Find <ButtonObj>("ButtonPower2");
 }
Exemplo n.º 14
0
    public void ClickEvent(ButtonObj clickedButton)
    {
        Player currPlayer = players[currPlayerIndex];

        switch (status)
        {
        case Status.notSelected:
            if (IsCurrPlayerButton(clickedButton, currPlayer))
            {
                this.selectedButton = clickedButton;
                this.status         = Status.clicked;
                UpdateBorders();
                PlayAudio(clickedButton);
            }
            break;

        case Status.clicked:
            if (IsCurrPlayerButton(clickedButton, currPlayer))
            {
                this.selectedButton = clickedButton;

                PlayAudio(clickedButton);
                ClearBorders();
                UpdateBorders();
            }
            else if (IsBorder(clickedButton.CurrState))
            {
                this.status = Status.notSelected;
                Attack(clickedButton);
            }
            else
            {
                ClearBorders();
            }
            break;

        default:
            throw new ArgumentException(String.Format("{0} is not a valid game status!", status));
        }
        // UpdateBoard();
    }
Exemplo n.º 15
0
 private int GetPosition(ButtonObj button)
 {
     return(GetPosition(button.GetCoord()));
 }
Exemplo n.º 16
0
 public void RemoveButton(ButtonObj button)
 {
     this.Buttons.Remove(button);
 }
Exemplo n.º 17
0
 private int FindRandom(ButtonObj currButton, ButtonObj selectedButton, State enemyState)
 {
     return(Random.Range(0, 5));
 }
Exemplo n.º 18
0
 private int FindMinimax(ButtonObj currButton, ButtonObj selectedButton, State enemyState)
 {
     return(FindGain(currButton, selectedButton, enemyState) + FindLoss(currButton, enemyState));
 }
Exemplo n.º 19
0
 private bool IsEnemy(ButtonObj button)
 {
     return(IsEnemy(button.CurrState));
 }
Exemplo n.º 20
0
 private State GetEnemyState(ButtonObj button)
 {
     return(GetEnemyState(button.CurrState));
 }
Exemplo n.º 21
0
 private void MoveButton(ButtonObj clickedButton)
 {
     players[currPlayerIndex].AddButton(clickedButton);
 }
Exemplo n.º 22
0
 private bool IsCurrPlayerButton(ButtonObj clickedButton, Player currPlayer)
 {
     return(currPlayer.GetButtonObjs().Contains(clickedButton));
 }
Exemplo n.º 23
0
 private List <ButtonObj> FindAvailableButtons(ButtonObj button)
 {
     return(VisitNeighbors(button, NEARBY, IsAvailable));
 }
Exemplo n.º 24
0
 private int GetDistance(ButtonObj from, ButtonObj to)
 {
     return(GetDistance(from.GetCoord(), to.GetCoord()));
 }
Exemplo n.º 25
0
 private List <ButtonObj> FindNeighbors(ButtonObj button, int gap)
 {
     return(VisitNeighbors(button, gap, IsNeighbor));
 }