Example #1
0
 public Player(Player player)
 {
     Name  = player.Name;
     Board = GameBoard.CloneBoard(player.Board);
     Map   = GameBoard.CloneBoard(player.Map);
     Ships = new List <Ship>(player.Ships);
     AI    = player.AI;
 }
Example #2
0
        public static void DrawPlacing(Player player, int shipLen,
                                       bool rotation, int[] coords, ConsoleColor shipcolor, string right)
        {
            Console.Clear();
            GameBoard previewBoard = new GameBoard(player.Board.Board.Count, player.Board.Board[0].Count);

            previewBoard = GameBoard.CloneBoard(player.Board);
            AI.SetPlace(previewBoard, coords, shipLen, rotation);
            var lines           = Regex.Split(GetBoardString(previewBoard), "\r\n|\r|\n");
            var rightlines      = new string[lines.Length];
            var rightlinessplit = Regex.Split(right, "\r\n|\r|\n");

            for (int i = 0; i < lines.Length; i++)
            {
                if (i < rightlinessplit.Length)
                {
                    rightlines[i] = rightlinessplit[i];
                }
                else
                {
                    rightlines[i] = " ";
                }
            }
            Console.WriteLine(GetHeader(player));
            bool drawship = false;

            if (rotation)
            {
                for (int i = 0; i < lines.Length; i++)
                {
                    if (coords[0] * 2 + 2 == i)
                    {
                        drawship = true;
                    }
                    if (coords[0] * 2 + 2 + shipLen * 2 - 1 == i)
                    {
                        drawship = false;
                    }

                    if (drawship)
                    {
                        for (int j = 0; j < lines[i].Length; j++)
                        {
                            if (j == coords[1] * 4 + 3)
                            {
                                Console.ForegroundColor = shipcolor;
                            }
                            if (j == coords[1] * 4 + 2 + 4)
                            {
                                Console.ResetColor();
                            }
                            Console.Write(lines[i][j]);
                        }
                        Console.Write(GetSeparator());
                        Console.Write(rightlines[i]);
                        Console.Write("\n");
                    }
                    else
                    {
                        Console.Write(lines[i]);
                        Console.Write(GetSeparator());
                        Console.Write(rightlines[i]);
                        Console.Write("\n");
                    }
                }
            }
            else
            {
                for (int i = 0; i < lines.Length; i++)
                {
                    if (coords[0] * 2 + 2 == i)
                    {
                        for (int j = 0; j < lines[i].Length; j++)
                        {
                            if (j == coords[1] * 4 + 3)
                            {
                                Console.ForegroundColor = shipcolor;
                            }

                            if (j == coords[1] * 4 + 2 + shipLen * 4 - 1)
                            {
                                Console.ResetColor();
                            }
                            Console.Write(lines[i][j]);
                        }
                        Console.Write(GetSeparator());
                        Console.Write(rightlines[i]);
                        Console.Write("\n");
                    }
                    else
                    {
                        Console.Write(lines[i]);
                        Console.Write(GetSeparator());
                        Console.Write(rightlines[i]);
                        Console.Write("\n");
                    }
                }
            }
            Console.WriteLine(GetFooter(player));
        }