Click here to Skip to main content
15,904,288 members
Home / Discussions / C#
   

C#

 
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 
Hi Griff,

Hope you are doing well

I am up to speed with everything you mentioned on this post

I figured out I needed the using directive System.Drawing in order
to access the built in .NET Point struct

With that said I successfully implemented the randomization of
Point loc, and the Orienation orient (represented as Enums)

I am able to call the PlaceShip method on the object playerA
and create the 1 ship, 2 location, and 3 orientation as follows:
C#
playerA.PlaceShip(new Submarine(), loc, orient);
...

 public Ship PlaceShip(Ship ship, Point loc, Orientation wayUp)
        {
            loc = (x, y);

            string direction;

            int x;
            int y;

            if (wayUp == Orientation.Right)
            {
                direction = "right";
            }
            else if (wayUp == Orientation.Left)
            {
                direction = "left";
            }
            else
            {
                direction = "left,right";
            }

            if (wayUp == Orientation.Down)
            {
                direction += "down";
            }
            else if (wayUp == Orientation.Up)
            {
                direction += "up";
            }
            else
            {
                direction += "up,down";
            }

            if (direction == "up")
            {
                for (int i = y; i < y - 4; i--)
                {
                    TheBoard[i, y] = Square.Ship;
                }
            }
            else if (direction == "down")
            {
                for (int i = y; i < y + 4; i++)
                {
                    TheBoard[i, y] = Square.Ship;
                }
            }
            else if (direction == "left")
            {
                for (int i = x; i < x - 4; i--)
                {
                    TheBoard[x, i] = Square.Ship;
                }
            }
            else
            {
                for (int i = x; i < x + 4; i++)
                {
                    TheBoard[x, i] = Square.Ship;
                }
            }

            Console.WriteLine(ship.Name);
            //loop over the ship.Length to
            //populate the gameboard with Ship Enum

            Console.WriteLine(wayUp);
            //foreach (int point in loc)
            //{
            //    TheBoard[i, ship[i]] = Square.Ship;

            //}
            Console.WriteLine(loc);

            return ship;
        }  

In the console when I run the program with PlaceShip() above I get back the following:
C#
Submarine
Left   //random each time called
{X=7, Y=1} //random each time called

What I am working on now is placement of the Ship(s)
inside the PlaceShip Method:

I am trying to acces the x, y coordinates that come from Point loc
within the PlaceShip Method, and them use them in the assignment
logic with the looping and if/else statements in order to populate
the board with the Enum Ship

I know that I need to take the location and orientation and loop
over them to populate TheBoard with the Enum Ship, but having
a hard implementing that functionality.
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 
AnswerRe: C# Battleship gameboard & random assignment Pin
Gerry Schmitz6-Sep-22 5:06
mveGerry Schmitz6-Sep-22 5:06 
QuestionChanging Windows registry with C# Pin
Ismael_199931-Aug-22 12:50
Ismael_199931-Aug-22 12:50 
AnswerRe: Changing Windows registry with C# Pin
Dave Kreskowiak31-Aug-22 14:37
mveDave Kreskowiak31-Aug-22 14:37 
GeneralRe: Changing Windows registry with C# Pin
Ismael_19993-Sep-22 4:18
Ismael_19993-Sep-22 4:18 
GeneralRe: Changing Windows registry with C# Pin
Dave Kreskowiak3-Sep-22 9:51
mveDave Kreskowiak3-Sep-22 9:51 
AnswerRe: Changing Windows registry with C# Pin
OriginalGriff31-Aug-22 18:51
mveOriginalGriff31-Aug-22 18:51 
GeneralRe: Changing Windows registry with C# Pin
Ismael_19993-Sep-22 4:20
Ismael_19993-Sep-22 4:20 
GeneralRe: Changing Windows registry with C# Pin
OriginalGriff3-Sep-22 4:43
mveOriginalGriff3-Sep-22 4:43 
GeneralRe: Changing Windows registry with C# Pin
Ismael_19994-Sep-22 11:41
Ismael_19994-Sep-22 11:41 
GeneralRe: Changing Windows registry with C# Pin
Dave Kreskowiak4-Sep-22 13:12
mveDave Kreskowiak4-Sep-22 13:12 
GeneralRe: Changing Windows registry with C# Pin
OriginalGriff4-Sep-22 19:19
mveOriginalGriff4-Sep-22 19:19 
GeneralRe: Changing Windows registry with C# Pin
Dave Kreskowiak5-Sep-22 3:43
mveDave Kreskowiak5-Sep-22 3:43 
GeneralRe: Changing Windows registry with C# Pin
Ismael_19996-Sep-22 4:10
Ismael_19996-Sep-22 4:10 
GeneralRe: Changing Windows registry with C# Pin
Dave Kreskowiak6-Sep-22 4:30
mveDave Kreskowiak6-Sep-22 4:30 

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.