void TestMove() { string opponentColor = playerTeam == "Red" ? "Blue" : "Red"; int pieceSingleRowMove1 = playerTeam == "Red" ? 1 : -1; int pieceSingleRowMove2 = playerTeam == "Red" ? 2 : -2; if (fromChecker.Type == Piece.Single) { if (fromChecker.Position.Row - toPosition.Row == pieceSingleRowMove1) //-1 if blue 1 if red { if (fromChecker.Position.Col - toPosition.Col == 1 || fromChecker.Position.Col - toPosition.Col == -1) //check move left of right by 1 { error = string.Empty; MakeMove(); } else // did not move left or right by 1 { error = $"You cant Move to cell {boardGrid[toPosition.Row][toPosition.Col][0]}"; } } else if (fromChecker.Position.Row - toPosition.Row == pieceSingleRowMove2) // jump move { int col; int row = fromChecker.Position.Row - pieceSingleRowMove1; // get jumped row if (fromChecker.Position.Col - toPosition.Col < pieceSingleRowMove1) // find the out if the move was left or right { col = toPosition.Col - 1; // move was right } else { col = toPosition.Col + 1; //move was left } Position opponentPos = new Position(row, col); // position jumpChecker = board.GetChecker(opponentPos); //get checker player is jumping if (jumpChecker != null) //see if player jumped empty cell { if ((fromChecker.Position.Col - toPosition.Col == 2 || fromChecker.Position.Col - toPosition.Col == -2) && Enum.GetName(typeof(Color), jumpChecker.Team) == opponentColor) { error = string.Empty; board.RemoveChecker(jumpChecker); MakeMove(); } else //trying to jump their own piece { error = $"You cant Move to cell {boardGrid[toPosition.Row][toPosition.Col][0]} you can't jump your own piece"; } } else //player tried to jump empty cell { error = $"You cant Move to cell {boardGrid[toPosition.Row][toPosition.Col][0]} there was no Opponent to Jump!"; } } else //player did not move 1 or 2 rows { error = $"You cant Move to cell {boardGrid[toPosition.Row][toPosition.Col][0]}"; } } else if (fromChecker.Type == Piece.Double) { if (fromChecker.Position.Row - toPosition.Row == 1 || fromChecker.Position.Row - toPosition.Row == -1) //-1 if blue 1 if red { if (fromChecker.Position.Col - toPosition.Col == 1 || fromChecker.Position.Col - toPosition.Col == -1) //check move left of right by 1 { error = string.Empty; MakeMove(); } else // did not move left or right by 1 { error = $"You cant Move to cell {boardGrid[toPosition.Row][toPosition.Col][0]}"; } } else if (fromChecker.Position.Row - toPosition.Row == 2 || fromChecker.Position.Row - toPosition.Row == -2) // jump move { int row, col; if (fromChecker.Position.Row - toPosition.Row < pieceSingleRowMove1) // find if move is up or down { row = fromChecker.Position.Row + 1; } else { row = fromChecker.Position.Row - 1; } if (fromChecker.Position.Col - toPosition.Col < pieceSingleRowMove1) // find the out if the move was left or right { col = toPosition.Col - 1; // move was right } else { col = toPosition.Col + 1; //move was left } Position opponentPos = new Position(row, col); // position jumpChecker = board.GetChecker(opponentPos); //get checker player is jumping if (jumpChecker != null) //see if player jumped empty cell { if ((fromChecker.Position.Col - toPosition.Col == 2 || fromChecker.Position.Col - toPosition.Col == -2) && Enum.GetName(typeof(Color), jumpChecker.Team) == opponentColor) { error = string.Empty; board.RemoveChecker(jumpChecker); MakeMove(); } else //trying to jump their own piece { error = $"You cant Move to cell {boardGrid[toPosition.Row][toPosition.Col][0]} you can't jump your own piece"; } } else //player tried to jump empty cell { error = $"You cant Move to cell {boardGrid[toPosition.Row][toPosition.Col][0]} there was no Opponent to Jump!"; } } else //player did not move 1 or 2 rows { error = $"You cant Move to cell {boardGrid[toPosition.Row][toPosition.Col][0]}"; } } }
public void MoveChecker(Checker fromChecker, Position toPosition) //change checker position { fromChecker.Position = toPosition; }
void TestInputFrom() { bool movePass = false; do { Console.Write("Please select the Checker you want to move. Use the number in "); Change(Color.Green); Console.WriteLine("GREEN"); Change(Color.White); string userFrom = Console.ReadLine().Trim(); int moveNum; if (int.TryParse(userFrom, out moveNum)) { if (moveNum >= 1 && moveNum <= 64) { string[] test = new string[3]; for (int row = 0; row < 8; row++) { for (int col = 0; col < 8; col++) { if (Convert.ToInt32(boardGrid[row][col][0]) == moveNum) { fromPosition = new Position(row, col); fromChecker = board.GetChecker(fromPosition); col = 8; break; } } } if (fromChecker != null) { if (Enum.GetName(typeof(Colors.Color), fromChecker.Team) == playerTeam) { movePass = true; } else { Change(Color.Red); Console.WriteLine("You can not select the opponent's checkers"); Change(Color.White); } } else { Change(Color.Red); Console.WriteLine("You did not select a Checker! Try again"); Change(Color.White); } } else { Change(Color.Red); Console.WriteLine("You must select a number between 1 and 64"); Change(Color.White); } } else { Change(Color.Red); Console.WriteLine("You did not enter a number"); Change(Color.White); } } while (!movePass); }
public void RemoveChecker(Checker checker) //remove checker from list { checkers.Remove(checker); }