Click here to Skip to main content
15,881,898 members
Home / Discussions / C#
   

C#

 
AnswerRe: C# Service: Error 1053: The service did not respond to the start or control request in a timely fashion Pin
Richard Deeming8-Sep-22 21:49
mveRichard Deeming8-Sep-22 21:49 
GeneralRe: C# Service: Error 1053: The service did not respond to the start or control request in a timely fashion Pin
temuco8-Sep-22 22:34
professionaltemuco8-Sep-22 22:34 
General[Solved] Re: C# Service: Error 1053: The service did not respond to the start or control request in a timely fashion Pin
temuco9-Sep-22 1:38
professionaltemuco9-Sep-22 1:38 
QuestionC# Battleship gameboard & random assignment Pin
Otto_W5-Sep-22 17:50
Otto_W5-Sep-22 17:50 
AnswerRe: C# Battleship gameboard & random assignment Pin
OriginalGriff5-Sep-22 19:11
mveOriginalGriff5-Sep-22 19:11 
GeneralRe: C# Battleship gameboard & random assignment Pin
Otto_W6-Sep-22 15:51
Otto_W6-Sep-22 15:51 
GeneralRe: C# Battleship gameboard & random assignment Pin
OriginalGriff6-Sep-22 19:19
mveOriginalGriff6-Sep-22 19:19 
GeneralRe: C# Battleship gameboard & random assignment Pin
Otto_W16-Sep-22 21:54
Otto_W16-Sep-22 21:54 
I am a little bit further along in my Battleship app although
not as far as I'd hoped to be.

So I setup the 10x10 representations with the enum
Square class and values on the board

It feels like I am running into issues with the CheckGuess
Method in the location where I am calling it from, and also
with the values it's returning after the player enters their guess.

I know that I can change TheBoard values because I have done
so in the current code and wrote it out at the bottom with the
changed values displayed. I can't quite understand why those
same values don't show up when the players guess gets passed
into the CheckGuess Method.

{explained as best as possible to my knowledge}

Please help if you have free time

GitHub - Charles-CarM/Battleship[^]

C#
namespace ConsoleBattle
{
    public class Program
    {
        public enum Square
        {
            Water,
            Miss,
            Ship,
            Hit,
        }
        public static void Main(string[] args)
        {
        bool finished = false;
        string message;

            Square[,] TheBoard = new Square[10, 10];
            Welcome();
            Console.WriteLine("X: 0 - 9");
            Console.WriteLine("Y: 0 - 9");
            Console.WriteLine("Enter your guess: X, Y");

            while (!finished)
            {
                TheBoard[7, 7] = Square.Ship;
                TheBoard[7, 5] = Square.Ship;
                string guess = Console.ReadLine();

                void CheckGuess(int x, int y)
                {
                    if (TheBoard[x, y] == Square.Ship)
                    {
                        Console.WriteLine(TheBoard[x, y] = Square.Hit);
                    }
                    else if (TheBoard[x, y] == Square.Water)
                    {
                        Console.WriteLine(TheBoard[x, y] = Square.Miss);
                    }
                    else if (TheBoard[x, y] == Square.Miss)
                    {
                        Console.WriteLine(message = "you already missed here");
                    }
                    else
                    {
                        Console.WriteLine(message = "this spot was hit already");
                    }
                    Console.ReadLine();
                }

                try
                {
                    int xPos = Convert.ToInt32(guess.Split(',')[0]) - 1;
                    int yPos = Convert.ToInt32(guess.Split(',')[1]) - 1;

                    if (xPos > 9 || yPos > 9)
                    {
                        message = "You are off the board, try again!";
                    }
                    CheckGuess(xPos, yPos);
                }
                catch
                {
                    message = "Unable to process coordinates";
                }
                finished = true;
            }
            Console.WriteLine(TheBoard[7, 7]);
            Console.WriteLine(TheBoard[7, 5]);
        }
        private static void Welcome()
        {
            Console.WriteLine("Welcome to Console Battle!");
            //Console.ReadLine();
            Console.WriteLine("Enter username: ");
            string username = Console.ReadLine();
            Console.WriteLine($"\nLet's begin {username} press Enter!");
            Console.ReadLine();
        }
        //static void AssignShip(board)
        //{
        //    Clear();
        //}
    }
}

GeneralRe: C# Battleship gameboard & random assignment Pin
OriginalGriff16-Sep-22 22:13
mveOriginalGriff16-Sep-22 22:13 
GeneralRe: C# Battleship gameboard & random assignment Pin
Otto_W24-Sep-22 1:09
Otto_W24-Sep-22 1:09 
GeneralRe: C# Battleship gameboard & random assignment Pin
OriginalGriff24-Sep-22 1:34
mveOriginalGriff24-Sep-22 1:34 
GeneralRe: C# Battleship gameboard & random assignment Pin
Otto_W24-Sep-22 2:45
Otto_W24-Sep-22 2:45 
GeneralRe: C# Battleship gameboard & random assignment Pin
OriginalGriff24-Sep-22 3:16
mveOriginalGriff24-Sep-22 3:16 
GeneralRe: C# Battleship gameboard & random assignment Pin
Otto_W25-Sep-22 21:20
Otto_W25-Sep-22 21:20 
GeneralRe: C# Battleship gameboard & random assignment Pin
OriginalGriff25-Sep-22 22:01
mveOriginalGriff25-Sep-22 22:01 
GeneralRe: C# Battleship gameboard & random assignment Pin
Otto_W29-Sep-22 16:23
Otto_W29-Sep-22 16:23 
GeneralRe: C# Battleship gameboard & random assignment Pin
OriginalGriff29-Sep-22 19:10
mveOriginalGriff29-Sep-22 19:10 
GeneralRe: C# Battleship gameboard & random assignment Pin
Otto_W4-Oct-22 0:29
Otto_W4-Oct-22 0:29 
GeneralRe: C# Battleship gameboard & random assignment Pin
OriginalGriff4-Oct-22 1:09
mveOriginalGriff4-Oct-22 1:09 
GeneralRe: C# Battleship gameboard & random assignment Pin
Otto_W13-Oct-22 17:45
Otto_W13-Oct-22 17:45 
GeneralRe: C# Battleship gameboard & random assignment Pin
Otto_W13-Oct-22 17:46
Otto_W13-Oct-22 17:46 
GeneralRe: C# Battleship gameboard & random assignment Pin
Otto_W25-Oct-22 17:16
Otto_W25-Oct-22 17:16 
GeneralRe: C# Battleship gameboard & random assignment Pin
OriginalGriff25-Oct-22 19:34
mveOriginalGriff25-Oct-22 19:34 
GeneralRe: C# Battleship gameboard & random assignment Pin
Otto_W30-Oct-22 19:30
Otto_W30-Oct-22 19:30 
GeneralRe: C# Battleship gameboard & random assignment Pin
Otto_W15-Nov-22 14:46
Otto_W15-Nov-22 14:46 

General General    News News    Suggestion Suggestion    Question Question    Bug Bug    Answer Answer    Joke Joke    Praise Praise    Rant Rant    Admin Admin   

Use Ctrl+Left/Right to switch messages, Ctrl+Up/Down to switch threads, Ctrl+Shift+Left/Right to switch pages.