コード例 #1
0
        // if during checkers game any chosen position == an existing checker position throw exception otherwise valid
        //throw and exception if not diagonal
        public Checker CheckerPreCheck(int sourceRow, int sourceColumn, int destRow, int destColumn, Checker check)
        {
            check = Checkers.Find(cx => cx.Position.SequenceEqual(new List <int> {
                sourceRow, sourceColumn
            }));
            // if dest row and dest col have a checker piece using select checker method passing dest
            if (SelectCheckerDestination(destRow, destColumn) != null)
            {
                throw new Exception("That space is full.");
            }
            else if (SelectCheckerDestination(destRow, destColumn) == null)
            {
                //if moving 2 diagonal spaces jump checker must be opposing (X)
                //1. check if moving two spots (X)
                //2. check if destination removal is not null (&& SelectCheckerDestination(destRow+1,destColumn -1) != null)
                //3. checker symbol being jumped is opposing
                if (Math.Abs(destRow - check.Position[0]) == 2 && Math.Abs(destColumn - check.Position[1]) == 2)
                {
                    if (destRow - check.Position[0] == -2 && destColumn - check.Position[1] == 2)
                    {
                        RemoveChecker(destRow + 1, destColumn - 1);
                        Console.WriteLine("Nice move");
                    }
                    //remove the checker row up to column left
                    else if (destRow - check.Position[0] == -2 && destColumn - check.Position[1] == -2)
                    {
                        RemoveChecker(destRow + 1, destColumn + 1);

                        Console.WriteLine("Nice move");
                    }

                    //remove the checker row behind me to column right
                    else if (destRow - check.Position[0] == 2 && destColumn - check.Position[1] == 2)
                    {
                        RemoveChecker(destRow - 1, destColumn - 1);
                        Console.WriteLine("Nice move");
                    }
                    //remove the checker down to left
                    else if (destRow - check.Position[0] == 2 && destColumn - check.Position[1] == -2)
                    {
                        RemoveChecker(destRow - 1, destColumn + 1);

                        Console.WriteLine("Nice move");
                    }

                    //check for a diagonal move - regular
                }
                else if (Math.Abs(destRow - check.Position[0]) == 1 &&
                         Math.Abs(destColumn - check.Position[1]) == 1)
                {
                    Console.WriteLine("Nice diagonal move!");
                    return(Checkers.Find(cx => cx.Position.SequenceEqual(new List <int> {
                        destRow, destColumn
                    })));
                }
                else
                {
                    Console.WriteLine(" ");

                    throw new Exception("You cannot move here. Does not meet requirements to move.");
                }
            }
            return(Checkers.Find(cx => cx.Position.SequenceEqual(new List <int> {
                destRow, destColumn
            })));
        }
コード例 #2
0
        //allows a checker to be removed
        public void RemoveChecker(int destRow, int destColumn)
        {
            Checker cx2 = SelectCheckerDestination(destRow, destColumn);

            Checkers.Remove(cx2);
        }
コード例 #3
0
 public void RemoveChecker(Checker checker)
 {
     Checkers.Remove(checker);
     return;
 }