Click here to Skip to main content
15,561,948 members
Home / Discussions / C#
   

C#

 
GeneralRe: C# Battleship gameboard & random assignment Pin
OriginalGriff24-Sep-22 4:16
mvaOriginalGriff24-Sep-22 4:16 
GeneralRe: C# Battleship gameboard & random assignment Pin
Otto_W25-Sep-22 22:20
Otto_W25-Sep-22 22:20 
GeneralRe: C# Battleship gameboard & random assignment Pin
OriginalGriff25-Sep-22 23:01
mvaOriginalGriff25-Sep-22 23:01 
GeneralRe: C# Battleship gameboard & random assignment Pin
Otto_W29-Sep-22 17:23
Otto_W29-Sep-22 17:23 
GeneralRe: C# Battleship gameboard & random assignment Pin
OriginalGriff29-Sep-22 20:10
mvaOriginalGriff29-Sep-22 20:10 
GeneralRe: C# Battleship gameboard & random assignment Pin
Otto_W4-Oct-22 1:29
Otto_W4-Oct-22 1:29 
GeneralRe: C# Battleship gameboard & random assignment Pin
OriginalGriff4-Oct-22 2:09
mvaOriginalGriff4-Oct-22 2:09 
GeneralRe: C# Battleship gameboard & random assignment Pin
Otto_W13-Oct-22 18:45
Otto_W13-Oct-22 18:45 
I understand the creation and passing of the Enum for the orientation

From what I have searched and found for the Point struct/class:

I was not able to instantiate/access this from the foundational .NET suite

So I looked up how to create my own Point struct(Struct in C#[^]),
and tried to access it like that

Maybe there is a better way to access the Point struct/class?

Also I am having a difficult time accessing classes, properties,
and methods across my two files GameBoard.cs and Program.cs

Program.cs
C#
namespace ConsoleBattle
{
    public class Program
    {       
        public static void Main(string[] args)
        {
            GameBoard playerA = new GameBoard();
            GameBoard playerAGuesses = new GameBoard();
            bool sunk = false;
            string message;

            Welcome();
            Console.WriteLine("X: 0 - 9");
            Console.WriteLine("Y: 0 - 9");

            while (true)
            {
                playerA.PlaceShip(new Submarine(),new Point(x,y), Orientation.Down);

                while (!sunk)
                {

                try
                {
                    Console.WriteLine("Enter your guess: X, Y");
                    string guess = Console.ReadLine();
                    int xPos = Convert.ToInt32(guess.Split(',')[0]) - 1;
                    int yPos = Convert.ToInt32(guess.Split(',')[1]) - 1;

                    if (xPos > 9 || yPos > 9)
                    {
                        Console.WriteLine(message = "You are off the board, try again!");
                    }
                    playerA.CheckGuess(xPos, yPos);                   
                }
                catch
                {
                    Console.WriteLine(message = "Unable to process coordinates");
                }
                Console.ReadLine();
                //finished = true;
                }

                Console.WriteLine(message = "You sunk the ship!");
                Console.WriteLine("Play Again? [Y or N]");
                string answer = Console.ReadLine().ToUpper();

                if (answer == "Y")
                {
                    continue;
                }
                else if (answer == "N")
                {
                    return;
                }
                else
                {
                    return;
                }
            }   
        }
        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();
        }     
    }
}

GeneralRe: C# Battleship gameboard & random assignment Pin
Otto_W13-Oct-22 18:46
Otto_W13-Oct-22 18:46 
GeneralRe: C# Battleship gameboard & random assignment Pin
Otto_W25-Oct-22 18:16
Otto_W25-Oct-22 18:16 
GeneralRe: C# Battleship gameboard & random assignment Pin
OriginalGriff25-Oct-22 20:34
mvaOriginalGriff25-Oct-22 20:34 
GeneralRe: C# Battleship gameboard & random assignment Pin
Otto_W30-Oct-22 20:30
Otto_W30-Oct-22 20:30 
GeneralRe: C# Battleship gameboard & random assignment Pin
Otto_W15-Nov-22 15:46
Otto_W15-Nov-22 15:46 
AnswerRe: C# Battleship gameboard & random assignment Pin
Gerry Schmitz6-Sep-22 6:06
mveGerry Schmitz6-Sep-22 6:06 
QuestionChanging Windows registry with C# Pin
Ismael_199931-Aug-22 13:50
Ismael_199931-Aug-22 13:50 
AnswerRe: Changing Windows registry with C# Pin
Dave Kreskowiak31-Aug-22 15:37
mveDave Kreskowiak31-Aug-22 15:37 
GeneralRe: Changing Windows registry with C# Pin
Ismael_19993-Sep-22 5:18
Ismael_19993-Sep-22 5:18 
GeneralRe: Changing Windows registry with C# Pin
Dave Kreskowiak3-Sep-22 10:51
mveDave Kreskowiak3-Sep-22 10:51 
AnswerRe: Changing Windows registry with C# Pin
OriginalGriff31-Aug-22 19:51
mvaOriginalGriff31-Aug-22 19:51 
GeneralRe: Changing Windows registry with C# Pin
Ismael_19993-Sep-22 5:20
Ismael_19993-Sep-22 5:20 
GeneralRe: Changing Windows registry with C# Pin
OriginalGriff3-Sep-22 5:43
mvaOriginalGriff3-Sep-22 5:43 
GeneralRe: Changing Windows registry with C# Pin
Ismael_19994-Sep-22 12:41
Ismael_19994-Sep-22 12:41 
GeneralRe: Changing Windows registry with C# Pin
Dave Kreskowiak4-Sep-22 14:12
mveDave Kreskowiak4-Sep-22 14:12 
GeneralRe: Changing Windows registry with C# Pin
OriginalGriff4-Sep-22 20:19
mvaOriginalGriff4-Sep-22 20:19 
GeneralRe: Changing Windows registry with C# Pin
Dave Kreskowiak5-Sep-22 4:43
mveDave Kreskowiak5-Sep-22 4:43 

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.