Exemple #1
0
        //Funkcja odpowiadająca za grę.
        public static void start()
        {
            IAI           AI    = new AI();
            CheckersBoard board = new CheckersBoard();

            board.PlaceChecker();
            string lineChecker, lineDestination;
            int    checkX, checkY, destX, destY;
            Move   moveChecker;
            bool   rightMove = false;
            int    endGame   = 15;

            while (IfGameContinues(board.Board, CheckerColor.Blue, AI.AIColor) || endGame != 0)
            {
                board.DrawBoard();
                checkX = 0;
                checkY = 0;

                do
                {
                    do
                    {
                        rightMove = false;
                        Console.WriteLine("Jesteś graczem niebieskim. Podaj pionka którego chcesz ruszyć w formacie x,y");
                        try
                        {
                            lineChecker = Console.ReadLine();
                            checkX      = Int32.Parse(lineChecker[0].ToString());
                            checkY      = Int32.Parse(lineChecker[2].ToString());
                        }
                        catch (Exception ex)
                        {
                            Console.WriteLine("Zły format.");
                        }
                    } while (!Utils.IsValidPosition(checkX, checkY) || board.Board[checkX, checkY].Color != CheckerColor.Blue);

                    destX = 0;
                    destY = 0;
                    do
                    {
                        Console.WriteLine("Podaj na jakie miejsce chcesz ruszyć pionka o współrzędnych " +
                                          String.Format("{0},{1} formacie x,y", checkX, checkY));
                        try
                        {
                            lineDestination = Console.ReadLine();
                            destX           = Int32.Parse(lineDestination[0].ToString());
                            destY           = Int32.Parse(lineDestination[2].ToString());
                        }
                        catch (Exception ex)
                        {
                            Console.WriteLine("Zły format");
                        }
                    } while (!Utils.IsValidPosition(destX, destY) && destX != 0 && destY != 0);

                    /*   Console.WriteLine("Possible Moves");
                     * foreach (var mv in Utils.PossibleMoves(board.Board, new Position(checkX, checkY)))
                     * {
                     *     Console.WriteLine(mv);
                     * }*/

                    moveChecker = Utils.PossibleMoves(board.Board, new Position(checkX, checkY)).
                                  FirstOrDefault(move => move.Destination.X == destX && move.Destination.Y == destY);

                    if (moveChecker == null)
                    {
                        Console.WriteLine("Niepoprawny ruch!");
                    }
                    else if (IfCapture(board.Board, CheckerColor.Blue) && moveChecker.Captures.Count == 0)
                    {
                        Console.WriteLine("Masz bicie, wykonaj je!");
                    }
                    else
                    {
                        rightMove = true;
                    }
                    if (moveChecker.Captures.Count == 0)
                    {
                        --endGame;
                    }
                    else
                    {
                        endGame = 15;
                    }
                } while (!rightMove);

                Console.WriteLine("Wykonałeś ruch!");
                board.Move(moveChecker);

                //Utils.PossibleMoves(board.Board,new Position(2,3)).ToList()[0].Captures.ForEach(mv => Console.WriteLine(mv));
                Console.WriteLine("AI Wykonuje ruch!");
                Console.WriteLine(AI.Game(board.Board));
                board.Move(AI.Game(board.Board));
                board.DrawBoard();
                Console.WriteLine("Po wcisnieciu klawisza \"ENTER\" przejdziesz do następnej tury.");
                Console.ReadLine();
                Console.Clear();
            }

            Console.WriteLine("Gra zakonczona");
            Console.ReadLine();
            Console.Clear();
        }
Exemple #2
0
 public void RunGame(ref CheckersBoard io_CheckersBoard)
 {
     m_Controller.StartGame(ref io_CheckersBoard); // start function that controls game flow
 }