コード例 #1
0
        private bool CheckMoveLegality(int origin, int destination, bool Color, out int action)
        {
            action = default;
            if (origin < 0 || origin > 25 || destination < 1 || destination > 24)
            {
                return(false);
            }
            bool result = false;

            if (Board[destination].Color == Color)
            {
                result = true;
            }

            if (Board[destination].SoldiersQuantity < 2)
            {
                result = true;
            }

            if (result)
            {
                if (Color)
                {
                    result = DieActions.Contains(destination - origin);
                    action = destination - origin;
                }
                else
                {
                    result = DieActions.Contains(origin - destination);
                    action = origin - destination;
                }
            }
            return(result);
        }
コード例 #2
0
        public void MakeMove(int origin, int destination, string madeBy)
        {
            bool Color;

            if (madeBy != CurrentPlayer)
            {
                return;
            }
            if (origin < 0 || destination > 24)
            {
                return;
            }

            Color = WhoseTurn();

            if (CheckMoveLegality(origin, destination, Color, out int action))
            {
                DieActions.Remove(action);
                Board[origin].SoldiersQuantity--;
                switch (Board[destination].SoldiersQuantity)
                {
                case 0:
                    Board[destination].Color = Color;
                    Board[destination].SoldiersQuantity++;
                    break;

                case 1:
                    if (Board[destination].Color != Color)
                    {
                        if (Color)
                        {
                            Board[25].SoldiersQuantity++;
                        }
                        else
                        {
                            Board[0].SoldiersQuantity++;
                        }

                        Board[destination].Color = Color;
                    }
                    else
                    {
                        Board[destination].SoldiersQuantity++;
                    }
                    break;

                default:
                    Board[destination].SoldiersQuantity++;
                    break;
                }
            }

            if (DieActions.Count == 0 || !CanMakeMoves(WhoseTurn()))
            {
                StartNewTurn();
            }
        }
コード例 #3
0
 private void removeFromOrigion(int origin, int action, bool color)
 {
     if (color)
     {
         BlackOut++;
     }
     else
     {
         WhiteOut++;
     }
     Board[origin].SoldiersQuantity--;
     DieActions.Remove(action);
 }
コード例 #4
0
        private List <int> RollDice()
        {
            DieActions.Clear();
            List <int> results = new List <int>();
            int        die1    = _rnd.Next(1, 7);
            int        die2    = _rnd.Next(1, 7);

            results.Add(die1);
            results.Add(die2);

            DieActions.Add(die1);
            DieActions.Add(die2);

            if (die1 == die2)
            {
                DieActions.Add(die1);
                DieActions.Add(die2);
            }

            return(results);
        }