Exemple #1
0
        private void SetupPlayer(Player player)
        {
            Console.WriteLine("\n\n");

            Console.WriteLine("{0}'s turn to set up the board.", player.playerName);

            Console.WriteLine("\n");

            PlaceShips placeShips = new PlaceShips();
            placeShips.PlaceTheShips(player);
        }
Exemple #2
0
        public static void DrawShotHistoryBoard(Player player)
        {
            char[] columnGrid = "\0ABCDEFGHIJ".ToCharArray();

            Console.Write("   ");
            for (int i = 1; i < 11; i++)
            {
                Console.Write(" {0} ", columnGrid[i]);
            }
            Console.WriteLine();

            for (int i = 1; i < 11; i++)
            {
                if (i == 10)
                {
                    Console.Write("{0} ", i);
                }
                else
                {
                    Console.Write("{0}  ", i);
                }

                for (int j = 1; j < 11; j++)
                {
                    Coordinate checkCoordinate = new Coordinate(j, i);
                    if (!player.PlayerBoard.ShotHistory.ContainsKey(checkCoordinate) ||
                        player.PlayerBoard.ShotHistory[checkCoordinate] == ShotHistory.Unknown)
                    {
                        Console.Write(" - ");
                    }
                    else if (player.PlayerBoard.ShotHistory[checkCoordinate] == ShotHistory.Hit)
                    {
                        Console.ForegroundColor = ConsoleColor.Red;
                        Console.Write(" {0} ", "H");
                        Console.ForegroundColor = ConsoleColor.Gray;
                    }
                    else if (player.PlayerBoard.ShotHistory[checkCoordinate] == ShotHistory.Miss)
                    {
                        Console.ForegroundColor = ConsoleColor.Yellow;
                        Console.Write(" {0} ", "M");
                        Console.ForegroundColor = ConsoleColor.Gray;
                    }
                }
                Console.WriteLine();
            }
        }
Exemple #3
0
 private void SetUpPlayerAutomatically(Player player)
 {
     PlaceShips placeShips = new PlaceShips();
     placeShips.PlaceTheShipsAuto(player);
 }
        public static void ShowBoard1(Player p)
        {
            Console.WriteLine("\n");
            Console.WriteLine("  A    B    C    D    E    F    G    H    I    J");
            for (int y = 1; y < 11; y++)
            {
                if (y != 1)
                {
                    Console.WriteLine("\n");
                }

                for (int x = 1; x < 11; x++)
                {
                    Coordinate coordinateToCheck = new Coordinate(x, y);

                    if (p.playerBoard.ShotHistory.ContainsKey(coordinateToCheck))
                    {
                        if (coordinateToCheck.XCoordinate == 1)
                        {
                            var value = p.playerBoard.ShotHistory[coordinateToCheck];
                            if (value.Equals(ShotHistory.Hit))
                            {
                                Console.ForegroundColor = ConsoleColor.Red;
                                Console.Write(y + " H  ");
                                Console.ResetColor();
                            }
                            else if (value.Equals(ShotHistory.Miss))
                            {
                                Console.ForegroundColor = ConsoleColor.Yellow;
                                Console.Write(y + " M  ");
                                Console.ResetColor();
                            }
                            else
                            {
                                Console.Write(y + " U  ");
                            }
                        }
                        else
                        {
                            var value = p.playerBoard.ShotHistory[coordinateToCheck];
                            if (value.Equals(ShotHistory.Hit))
                            {
                                Console.ForegroundColor = ConsoleColor.Red;
                                Console.Write("  H  ");
                                Console.ResetColor();
                            }
                            else if (value.Equals(ShotHistory.Miss))
                            {
                                Console.ForegroundColor = ConsoleColor.Yellow;
                                Console.Write("  M  ");
                                Console.ResetColor();
                            }
                            else
                            {
                                Console.Write("  U  ");
                            }
                        }

                    }
                    else
                    {
                        if (coordinateToCheck.XCoordinate == 1)
                        {
                            Console.Write(y + " -  ");
                        }
                        else
                        {
                            Console.Write("  -  ");
                        }
                    }
                }
            }
        }
Exemple #5
0
        public void PlaceTheShips(Player player)
        {
            PlaceShipRequest ShipToPlace = new PlaceShipRequest();

            int howManyShipsPlaced = 0;

            for (int i = 0; i < 5; i++)
            {
                ShipPlacement response;

                do
                {
                    Console.WriteLine("Place your {0} on the x axis with a letter: ", ShipToPlace.ShipType);
                    string userinputXCoord = Console.ReadLine();
                    int Xcoord = 0;

                    switch (userinputXCoord.ToUpper())
                    {
                        case "A":
                            Xcoord = 1;
                            break;
                        case "B":
                            Xcoord = 2;
                            break;
                        case "C":
                            Xcoord = 3;
                            break;
                        case "D":
                            Xcoord = 4;
                            break;
                        case "E":
                            Xcoord = 5;
                            break;
                        case "F":
                            Xcoord = 6;
                            break;
                        case "G":
                            Xcoord = 7;
                            break;
                        case "H":
                            Xcoord = 8;
                            break;
                        case "I":
                            Xcoord = 9;
                            break;
                        case "J":
                            Xcoord = 10;
                            break;
                    }

                    Console.WriteLine("\nPlace your {0} on the y axis with a number: ", ShipToPlace.ShipType);
                    string inputYCoord = Console.ReadLine();
                    var new_string = 0;
                    if (int.TryParse(inputYCoord, out new_string))
                    {
                        new_string = new_string;
                    }
                    else
                    {
                        new_string = 0;
                    }
                    //int Ycoord = int.Parse(inputYCoord);
                    int Ycoord = new_string;
                    Console.WriteLine("\nWhat direction should your carrier point? (Up, Down, Right, Left): ");
                    string inputCarrierDirection = Console.ReadLine();
                    ShipDirection myDirection = 0;
                    switch (inputCarrierDirection.ToUpper())
                    {
                        case "UP":
                        case "U":
                            myDirection = ShipDirection.Up;
                            break;
                        case "DOWN":
                        case "D":
                            myDirection = ShipDirection.Down;
                            break;
                        case "RIGHT":
                        case "R":
                            myDirection = ShipDirection.Right;
                            break;
                        case "LEFT":
                        case "L":
                            myDirection = ShipDirection.Left;
                            break;
                    }

                    ShipToPlace.Direction = myDirection;

                    ShipToPlace.Coordinate = new Coordinate(Xcoord, Ycoord);

                    response = player.playerBoard.PlaceShip(ShipToPlace);

                    if (ShipToPlace.Coordinate.Equals(new Coordinate(0, 0)))
                    {
                        Console.WriteLine("\nInvalid input...Make sure x is a letter, and y is a number. " +
                                          "Press enter to try again.\n");
                        Console.ReadLine();
                    }
                    else
                    {
                        if (response == ShipPlacement.NotEnoughSpace)
                        {

                            Console.WriteLine("\nThere isn't enough room.  Try again.\n");
                            Console.ReadLine();
                        }
                        else if (response == ShipPlacement.Overlap)
                        {
                            Console.WriteLine("\nThat ship overlaps another.  Please try again.\n");
                            Console.ReadLine();
                        }
                    }

                    Console.Clear();

                    //wf.ShowBoard(wf.p1);
                   WorkFlowObject.ShowBoard1(player);
                   Console.WriteLine("\n");

                } while (response != ShipPlacement.Ok);

                ShipToPlace.ShipType++;

                Console.WriteLine("\n");

                howManyShipsPlaced++;

                Console.ForegroundColor = ConsoleColor.Cyan;
                Console.WriteLine("You've placed {0} of 5 ships so far. \n", howManyShipsPlaced);
                Console.ResetColor();

            }
        }
Exemple #6
0
        public void PlaceTheShipsAuto(Player player)
        {
            var request = new PlaceShipRequest()
            {
                Coordinate = new Coordinate(4, 4),
                Direction = ShipDirection.Right,
                ShipType = ShipType.Carrier
            };

            player.playerBoard.PlaceShip(request);
            var request1 = new PlaceShipRequest()
            {
                Coordinate = new Coordinate(10, 6),
                Direction = ShipDirection.Down,
                ShipType = ShipType.Battleship
            };

            player.playerBoard.PlaceShip(request1);

            var request2 = new PlaceShipRequest()
            {
                Coordinate = new Coordinate(3, 5),
                Direction = ShipDirection.Left,
                ShipType = ShipType.Submarine
            };

            player.playerBoard.PlaceShip(request2);

            var request3 = new PlaceShipRequest()
            {
                Coordinate = new Coordinate(3, 3),
                Direction = ShipDirection.Up,
                ShipType = ShipType.Cruiser
            };

            player.playerBoard.PlaceShip(request3);

            var request4 = new PlaceShipRequest()
            {
                Coordinate = new Coordinate(1, 8),
                Direction = ShipDirection.Right,
                ShipType = ShipType.Destroyer
            };

            player.playerBoard.PlaceShip(request4);
        }