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

C#

 
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 
Hope all is well

So I am able to pass in all three arguments to the PlaceShip method

And I am copying the Point loc inside of of the method and assigning them values of loc.X, loc.Y,
so I can use them in my loops in my conditional statements (not sure if that's the best way)

I am trying to place and populate the ship with the Enum Ship

Sometimes the values get filled, but other times I am off the board or the logic won't execute. I can see
the values get populated on TheBoard when I step through it while debugging.

This is what it looks like currently:

C#
public Ship PlaceShip(Ship ship, Point loc, Orientation direction)
       {

           loc = new Point(loc.X, loc.Y);
           Console.WriteLine(loc);

           if (direction == Orientation.Up)
           {
               for (int i = loc.Y; i < loc.Y - 5; i--)
               {
                   TheBoard[loc.X, i] = Square.Ship;
               }
           }
           else if (direction == Orientation.Down)
           {
               for (int i = loc.Y; i < loc.Y + 5; i++)
               {
                   TheBoard[loc.X, i] = Square.Ship;
               }
           }
           else if (direction == Orientation.Left)
           {
               for (int i = loc.X; i < loc.X - 5; i--)
               {
                   TheBoard[i, loc.Y] = Square.Ship;
               }
           }
           else
           {
               for (int i = loc.X; i < loc.X + 5; i++)
               {
                   TheBoard[i, loc.Y] = Square.Ship;
               }
           }
           Console.WriteLine(ship.Name);
           Console.WriteLine(direction);
           return ship;
       }
   }

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 
GeneralRe: Changing Windows registry with C# Pin
Ismael_19996-Sep-22 4:47
Ismael_19996-Sep-22 4:47 
GeneralRe: Changing Windows registry with C# Pin
Dave Kreskowiak6-Sep-22 4:48
mveDave Kreskowiak6-Sep-22 4:48 
GeneralRe: Changing Windows registry with C# Pin
Ismael_19996-Sep-22 10:29
Ismael_19996-Sep-22 10:29 

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.