コード例 #1
0
        public void StartResetAppGrid()
        {
            StratCell redCell = new StratCell();

            redCell.CellColor = Color.Red;
            redCell.CellUnits = 2;
            StratCell blueCell = new StratCell();

            blueCell.CellColor = Color.Blue;
            blueCell.CellUnits = 2;

            gameCol00.Add(redCell);
            gameCol00.Add(new StratCell());
            gameCol00.Add(new StratCell());
            gameCol00.Add(new StratCell());
            gameCol00.Add(new StratCell());

            gameCol01.Add(new StratCell());
            gameCol01.Add(new StratCell());
            gameCol01.Add(new StratCell());
            gameCol01.Add(new StratCell());
            gameCol01.Add(new StratCell());

            gameCol02.Add(new StratCell());
            gameCol02.Add(new StratCell());
            gameCol02.Add(new StratCell());
            gameCol02.Add(new StratCell());
            gameCol02.Add(new StratCell());

            gameCol03.Add(new StratCell());
            gameCol03.Add(new StratCell());
            gameCol03.Add(new StratCell());
            gameCol03.Add(new StratCell());
            gameCol03.Add(new StratCell());

            gameCol04.Add(new StratCell());
            gameCol04.Add(new StratCell());
            gameCol04.Add(new StratCell());
            gameCol04.Add(new StratCell());
            gameCol04.Add(blueCell);
        }
コード例 #2
0
        private void SwipeGestureRecognizer_Swiped(object sender, SwipedEventArgs e)
        {
            Debug.WriteLine(e.Direction);
            StratCell swipedCell = e.Parameter as StratCell;

            Tuple <int, int> colAndIndex = new Tuple <int, int>(0, 0);

            #region Find inside cols
            foreach (StratCell compareCell in gameCol00)
            {
                if (compareCell == swipedCell)
                {
                    colAndIndex = new Tuple <int, int>(0, gameCol00.IndexOf(compareCell));
                }
            }

            foreach (StratCell compareCell in gameCol01)
            {
                if (compareCell == swipedCell)
                {
                    colAndIndex = new Tuple <int, int>(1, gameCol01.IndexOf(compareCell));
                }
            }

            foreach (StratCell compareCell in gameCol02)
            {
                if (compareCell == swipedCell)
                {
                    colAndIndex = new Tuple <int, int>(2, gameCol02.IndexOf(compareCell));
                }
            }

            foreach (StratCell compareCell in gameCol03)
            {
                if (compareCell == swipedCell)
                {
                    colAndIndex = new Tuple <int, int>(3, gameCol03.IndexOf(compareCell));
                }
            }

            foreach (StratCell compareCell in gameCol04)
            {
                if (compareCell == swipedCell)
                {
                    colAndIndex = new Tuple <int, int>(4, gameCol04.IndexOf(compareCell));
                }
            }
            #endregion

            Debug.WriteLine("--------------");

            if (!(swipedCell.CellUnits <= 1))
            {
                //UpperLeft
                if (colAndIndex.Item1 == 0 &&
                    colAndIndex.Item2 == 0)
                {
                    switch (e.Direction)
                    {
                    case SwipeDirection.Right:
                        gameCol01[colAndIndex.Item2].BattleOnCell(ref swipedCell);
                        break;

                    case SwipeDirection.Down:
                        gameCol00[colAndIndex.Item2 + 1].BattleOnCell(ref swipedCell);
                        break;
                    }
                }
                //UpperMiddle
                else if ((colAndIndex.Item1 == 1 &&
                          colAndIndex.Item2 == 0) || (colAndIndex.Item1 == 2 &&
                                                      colAndIndex.Item2 == 0) || (colAndIndex.Item1 == 3 &&
                                                                                  colAndIndex.Item2 == 0))
                {
                    switch (e.Direction)
                    {
                    case SwipeDirection.Left:
                        if (colAndIndex.Item1 == 1)
                        {
                            gameCol00[colAndIndex.Item2].BattleOnCell(ref swipedCell);
                            break;
                        }
                        else if (colAndIndex.Item1 == 2)
                        {
                            gameCol01[colAndIndex.Item2].BattleOnCell(ref swipedCell);
                            break;
                        }
                        else if (colAndIndex.Item1 == 3)
                        {
                            gameCol02[colAndIndex.Item2].BattleOnCell(ref swipedCell);
                            break;
                        }
                        else
                        {
                            break;
                        }

                    case SwipeDirection.Right:
                        if (colAndIndex.Item1 == 1)
                        {
                            gameCol02[colAndIndex.Item2].BattleOnCell(ref swipedCell);
                            break;
                        }
                        else if (colAndIndex.Item1 == 2)
                        {
                            gameCol03[colAndIndex.Item2].BattleOnCell(ref swipedCell);
                            break;
                        }
                        else if (colAndIndex.Item1 == 3)
                        {
                            gameCol04[colAndIndex.Item2].BattleOnCell(ref swipedCell);
                            break;
                        }
                        else
                        {
                            break;
                        }

                    case SwipeDirection.Down:
                        if (colAndIndex.Item1 == 1)
                        {
                            gameCol01[colAndIndex.Item2 + 1].BattleOnCell(ref swipedCell);
                            break;
                        }
                        else if (colAndIndex.Item1 == 2)
                        {
                            gameCol02[colAndIndex.Item2 + 1].BattleOnCell(ref swipedCell);
                            break;
                        }
                        else if (colAndIndex.Item1 == 3)
                        {
                            gameCol03[colAndIndex.Item2 + 1].BattleOnCell(ref swipedCell);
                            break;
                        }
                        else
                        {
                            break;
                        }
                    }
                }
                //UpperRight
                else if (colAndIndex.Item1 == 4 &&
                         colAndIndex.Item2 == 0)
                {
                    switch (e.Direction)
                    {
                    case SwipeDirection.Left:
                        gameCol03[colAndIndex.Item2].BattleOnCell(ref swipedCell);
                        break;

                    case SwipeDirection.Down:
                        gameCol04[colAndIndex.Item2 + 1].BattleOnCell(ref swipedCell);
                        break;
                    }
                }
                //MiddleLeft
                else if ((colAndIndex.Item1 == 0 &&
                          colAndIndex.Item2 == 1) || (colAndIndex.Item1 == 0 &&
                                                      colAndIndex.Item2 == 2) || (colAndIndex.Item1 == 0 &&
                                                                                  colAndIndex.Item2 == 3))
                {
                    switch (e.Direction)
                    {
                    case SwipeDirection.Right:
                        if (colAndIndex.Item2 == 1)
                        {
                            gameCol01[colAndIndex.Item2].BattleOnCell(ref swipedCell);
                            break;
                        }
                        else if (colAndIndex.Item2 == 2)
                        {
                            gameCol01[colAndIndex.Item2].BattleOnCell(ref swipedCell);
                            break;
                        }
                        else if (colAndIndex.Item2 == 3)
                        {
                            gameCol01[colAndIndex.Item2].BattleOnCell(ref swipedCell);
                            break;
                        }
                        else
                        {
                            break;
                        }

                    case SwipeDirection.Up:
                        if (colAndIndex.Item2 == 1)
                        {
                            gameCol00[colAndIndex.Item2 - 1].BattleOnCell(ref swipedCell);
                            break;
                        }
                        else if (colAndIndex.Item2 == 2)
                        {
                            gameCol00[colAndIndex.Item2 - 1].BattleOnCell(ref swipedCell);
                            break;
                        }
                        else if (colAndIndex.Item2 == 3)
                        {
                            gameCol00[colAndIndex.Item2 - 1].BattleOnCell(ref swipedCell);
                            break;
                        }
                        else
                        {
                            break;
                        }

                    case SwipeDirection.Down:
                        if (colAndIndex.Item2 == 1)
                        {
                            gameCol00[colAndIndex.Item2 + 1].BattleOnCell(ref swipedCell);
                            break;
                        }
                        else if (colAndIndex.Item2 == 2)
                        {
                            gameCol00[colAndIndex.Item2 + 1].BattleOnCell(ref swipedCell);
                            break;
                        }
                        else if (colAndIndex.Item2 == 3)
                        {
                            gameCol00[colAndIndex.Item2 + 1].BattleOnCell(ref swipedCell);
                            break;
                        }
                        else
                        {
                            break;
                        }
                    }
                }
                //MiddleMiddle
                else if ((colAndIndex.Item1 == 1 &&
                          colAndIndex.Item2 == 1) || (colAndIndex.Item1 == 1 &&
                                                      colAndIndex.Item2 == 2) || (colAndIndex.Item1 == 1 &&
                                                                                  colAndIndex.Item2 == 3) || (colAndIndex.Item1 == 2 &&
                                                                                                              colAndIndex.Item2 == 1) || (colAndIndex.Item1 == 2 &&
                                                                                                                                          colAndIndex.Item2 == 2) || (colAndIndex.Item1 == 2 &&
                                                                                                                                                                      colAndIndex.Item2 == 3) || (colAndIndex.Item1 == 3 &&
                                                                                                                                                                                                  colAndIndex.Item2 == 1) || (colAndIndex.Item1 == 3 &&
                                                                                                                                                                                                                              colAndIndex.Item2 == 2) || (colAndIndex.Item1 == 3 &&
                                                                                                                                                                                                                                                          colAndIndex.Item2 == 3))
                {
                    switch (e.Direction)
                    {
                    case SwipeDirection.Left:
                        if (colAndIndex.Item1 == 1)
                        {
                            gameCol00[colAndIndex.Item2].BattleOnCell(ref swipedCell);
                            break;
                        }
                        else if (colAndIndex.Item1 == 2)
                        {
                            gameCol01[colAndIndex.Item2].BattleOnCell(ref swipedCell);
                            break;
                        }
                        else if (colAndIndex.Item1 == 3)
                        {
                            gameCol02[colAndIndex.Item2].BattleOnCell(ref swipedCell);
                            break;
                        }
                        else
                        {
                            break;
                        }

                    case SwipeDirection.Right:
                        if (colAndIndex.Item1 == 1)
                        {
                            gameCol02[colAndIndex.Item2].BattleOnCell(ref swipedCell);
                            break;
                        }
                        else if (colAndIndex.Item1 == 2)
                        {
                            gameCol03[colAndIndex.Item2].BattleOnCell(ref swipedCell);
                            break;
                        }
                        else if (colAndIndex.Item1 == 3)
                        {
                            gameCol04[colAndIndex.Item2].BattleOnCell(ref swipedCell);
                            break;
                        }
                        else
                        {
                            break;
                        }

                    case SwipeDirection.Up:
                        if (colAndIndex.Item1 == 1)
                        {
                            gameCol01[colAndIndex.Item2 - 1].BattleOnCell(ref swipedCell);
                            break;
                        }
                        else if (colAndIndex.Item1 == 2)
                        {
                            gameCol02[colAndIndex.Item2 - 1].BattleOnCell(ref swipedCell);
                            break;
                        }
                        else if (colAndIndex.Item1 == 3)
                        {
                            gameCol03[colAndIndex.Item2 - 1].BattleOnCell(ref swipedCell);
                            break;
                        }
                        else
                        {
                            break;
                        }

                    case SwipeDirection.Down:
                        if (colAndIndex.Item1 == 1)
                        {
                            gameCol01[colAndIndex.Item2 + 1].BattleOnCell(ref swipedCell);
                            break;
                        }
                        else if (colAndIndex.Item1 == 2)
                        {
                            gameCol02[colAndIndex.Item2 + 1].BattleOnCell(ref swipedCell);
                            break;
                        }
                        else if (colAndIndex.Item1 == 3)
                        {
                            gameCol03[colAndIndex.Item2 + 1].BattleOnCell(ref swipedCell);
                            break;
                        }
                        else
                        {
                            break;
                        }
                    }
                }
                //MiddleRight
                else if ((colAndIndex.Item1 == 4 &&
                          colAndIndex.Item2 == 1) || (colAndIndex.Item1 == 4 &&
                                                      colAndIndex.Item2 == 2) || (colAndIndex.Item1 == 4 &&
                                                                                  colAndIndex.Item2 == 3))
                {
                    switch (e.Direction)
                    {
                    case SwipeDirection.Left:
                        if (colAndIndex.Item2 == 1)
                        {
                            gameCol03[colAndIndex.Item2].BattleOnCell(ref swipedCell);
                            break;
                        }
                        else if (colAndIndex.Item2 == 2)
                        {
                            gameCol03[colAndIndex.Item2].BattleOnCell(ref swipedCell);
                            break;
                        }
                        else if (colAndIndex.Item2 == 3)
                        {
                            gameCol03[colAndIndex.Item2].BattleOnCell(ref swipedCell);
                            break;
                        }
                        else
                        {
                            break;
                        }

                    case SwipeDirection.Up:
                        if (colAndIndex.Item2 == 1)
                        {
                            gameCol04[colAndIndex.Item2 - 1].BattleOnCell(ref swipedCell);
                            break;
                        }
                        else if (colAndIndex.Item2 == 2)
                        {
                            gameCol04[colAndIndex.Item2 - 1].BattleOnCell(ref swipedCell);
                            break;
                        }
                        else if (colAndIndex.Item2 == 3)
                        {
                            gameCol04[colAndIndex.Item2 - 1].BattleOnCell(ref swipedCell);
                            break;
                        }
                        else
                        {
                            break;
                        }

                    case SwipeDirection.Down:
                        if (colAndIndex.Item2 == 1)
                        {
                            gameCol04[colAndIndex.Item2 + 1].BattleOnCell(ref swipedCell);
                            break;
                        }
                        else if (colAndIndex.Item2 == 2)
                        {
                            gameCol04[colAndIndex.Item2 + 1].BattleOnCell(ref swipedCell);
                            break;
                        }
                        else if (colAndIndex.Item2 == 3)
                        {
                            gameCol04[colAndIndex.Item2 + 1].BattleOnCell(ref swipedCell);
                            break;
                        }
                        else
                        {
                            break;
                        }
                    }
                }
                //BottomLeft
                else if ((colAndIndex.Item1 == 0 &&
                          colAndIndex.Item2 == 4))
                {
                    switch (e.Direction)
                    {
                    case SwipeDirection.Right:
                        gameCol01[colAndIndex.Item2].BattleOnCell(ref swipedCell);
                        break;

                    case SwipeDirection.Up:
                        gameCol00[colAndIndex.Item2 - 1].BattleOnCell(ref swipedCell);
                        break;
                    }
                }
                //BottomMiddle
                else if ((colAndIndex.Item1 == 1 &&
                          colAndIndex.Item2 == 4) || (colAndIndex.Item1 == 2 &&
                                                      colAndIndex.Item2 == 4) || (colAndIndex.Item1 == 3 &&
                                                                                  colAndIndex.Item2 == 4))
                {
                    switch (e.Direction)
                    {
                    case SwipeDirection.Left:
                        if (colAndIndex.Item1 == 1)
                        {
                            gameCol00[colAndIndex.Item2].BattleOnCell(ref swipedCell);
                            break;
                        }
                        else if (colAndIndex.Item1 == 2)
                        {
                            gameCol01[colAndIndex.Item2].BattleOnCell(ref swipedCell);
                            break;
                        }
                        else if (colAndIndex.Item1 == 3)
                        {
                            gameCol02[colAndIndex.Item2].BattleOnCell(ref swipedCell);
                            break;
                        }
                        else
                        {
                            break;
                        }

                    case SwipeDirection.Right:
                        if (colAndIndex.Item1 == 1)
                        {
                            gameCol02[colAndIndex.Item2].BattleOnCell(ref swipedCell);
                            break;
                        }
                        else if (colAndIndex.Item1 == 2)
                        {
                            gameCol03[colAndIndex.Item2].BattleOnCell(ref swipedCell);
                            break;
                        }
                        else if (colAndIndex.Item1 == 3)
                        {
                            gameCol04[colAndIndex.Item2].BattleOnCell(ref swipedCell);
                            break;
                        }
                        else
                        {
                            break;
                        }

                    case SwipeDirection.Up:
                        if (colAndIndex.Item1 == 1)
                        {
                            gameCol01[colAndIndex.Item2 - 1].BattleOnCell(ref swipedCell);
                            break;
                        }
                        else if (colAndIndex.Item1 == 2)
                        {
                            gameCol02[colAndIndex.Item2 - 1].BattleOnCell(ref swipedCell);
                            break;
                        }
                        else if (colAndIndex.Item1 == 3)
                        {
                            gameCol03[colAndIndex.Item2 - 1].BattleOnCell(ref swipedCell);
                            break;
                        }
                        else
                        {
                            break;
                        }
                    }
                }
                //BottomRight
                else if ((colAndIndex.Item1 == 4 &&
                          colAndIndex.Item2 == 4))
                {
                    switch (e.Direction)
                    {
                    case SwipeDirection.Left:
                        gameCol03[colAndIndex.Item2].BattleOnCell(ref swipedCell);
                        break;

                    case SwipeDirection.Up:
                        gameCol04[colAndIndex.Item2 - 1].BattleOnCell(ref swipedCell);
                        break;
                    }
                }
            }
        }
コード例 #3
0
        public void BattleOnCell(ref StratCell invadingCell)
        {
            int homeUnits = invadingCell.CellUnits;

            //Only battle if the invadingCell has more than one.
            if (!(homeUnits <= 1))
            {
                //First swipe
                if (!invadingCell.CellSecondSwipe)
                {
                    int invadingUnits = invadingCell.CellUnits / 2;
                    //Attacking Gray
                    if (this.CellColor == Color.Gray)
                    {
                        this.CellColor         = invadingCell.CellColor;
                        this.CellUnits         = invadingUnits;
                        invadingCell.CellUnits = homeUnits - invadingUnits;
                    }
                    //Attacking same color
                    else if (this.CellColor == invadingCell.CellColor)
                    {
                        this.CellUnits         = this.CellUnits + invadingUnits;
                        invadingCell.CellUnits = homeUnits - invadingUnits;
                    }
                    //Attacking opposing color
                    else
                    {
                        //Invading is larger
                        if (invadingUnits > this.CellUnits)
                        {
                            this.CellColor         = invadingCell.CellColor;
                            this.CellUnits         = invadingUnits - this.CellUnits;
                            invadingCell.CellUnits = homeUnits - invadingUnits;
                        }
                        //Invading is smaller
                        else if (invadingUnits < this.CellUnits)
                        {
                            this.CellUnits         = this.CellUnits - invadingUnits;
                            invadingCell.CellUnits = homeUnits - invadingUnits;
                        }
                        //Invading is equal
                        else
                        {
                            Random rand = new Random();
                            //Invading wins
                            if (rand.Next() % 2 == 0)
                            {
                                this.CellColor         = invadingCell.CellColor;
                                this.CellUnits         = 1;
                                invadingCell.CellUnits = homeUnits - invadingUnits;
                            }
                            //Invading loses
                            else
                            {
                                this.CellUnits         = 1;
                                invadingCell.CellUnits = homeUnits - invadingUnits;
                            }
                        }
                    }

                    invadingCell.CellSecondSwipe = true;
                }
                //Second swipe
                else
                {
                    int invadingUnits = homeUnits - 1;

                    //Attacking Gray
                    if (this.CellColor == Color.Gray)
                    {
                        this.CellColor         = invadingCell.CellColor;
                        this.CellUnits         = invadingUnits;
                        invadingCell.CellUnits = 1;
                    }
                    //Attacking same color
                    else if (this.CellColor == invadingCell.CellColor)
                    {
                        this.CellUnits         = this.CellUnits + invadingUnits;
                        invadingCell.CellUnits = 1;
                    }
                    //Attacking opposing color
                    else
                    {
                        //Invading is larger
                        if (invadingUnits > this.CellUnits)
                        {
                            this.CellColor         = invadingCell.CellColor;
                            this.CellUnits         = invadingUnits - this.CellUnits;
                            invadingCell.CellUnits = 1;
                        }
                        //Invading is smaller
                        else if (invadingUnits < this.CellUnits)
                        {
                            this.CellUnits         = this.CellUnits - invadingUnits;
                            invadingCell.CellUnits = 1;
                        }
                        //Invading is equal
                        else
                        {
                            Random rand = new Random();
                            //Invading wins
                            if (rand.Next() % 2 == 0)
                            {
                                this.CellColor         = invadingCell.CellColor;
                                this.CellUnits         = 1;
                                invadingCell.CellUnits = 1;
                            }
                            //Invading loses
                            else
                            {
                                this.CellUnits         = 1;
                                invadingCell.CellUnits = 1;
                            }
                        }
                    }
                }
            }
            else
            {
                Debug.WriteLine("Too few units to invade");
            }
        }