-
Notifications
You must be signed in to change notification settings - Fork 0
/
Ship.cs
95 lines (74 loc) · 2.26 KB
/
Ship.cs
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
namespace CSharpBattleShip
{
public class Ship
{
public string name;
protected int size;
public int health;
// private int[] location = new int[] { };
public int[,] newBoard = new int[21,21];
public Ship(string name)
{
this.name = name;
//this.size = size;
//this.health = health;
}
public int[,] PlaceShipsX()
{
Random rnd = new();
int starting_position_x = rnd.Next(1, 22 - (size));
int starting_position_y = rnd.Next(1, 22);
int x_span_until = starting_position_x + size;
for (int y = 0; y < 21; y++)
{
for (int x = 0; x < 21; x++)
{
if (starting_position_x < x_span_until)
{
if (y == starting_position_y & x == starting_position_x)
{
newBoard[y, x] = 2;
starting_position_x += 1;
}
}
}
}
return newBoard;
}
public int[,] PlaceShipsY()
{
Random rnd = new();
int starting_position_y = rnd.Next(1, (22 - size));
int starting_position_x = rnd.Next(1, 22);
int y_span_until = starting_position_y + size;
for (int y = 0; y < 21; y++)
{
for (int x = 0; x < 21; x++)
{
if (starting_position_y < y_span_until)
{
if (y == starting_position_y & x == starting_position_x)
{
newBoard[y, x] = 2;
starting_position_y += 1;
}
}
}
}
return newBoard;
}
public void PlaceShips()
{
Random rnd = new();
int decidingInt = rnd.Next(0,2);
if (decidingInt == 0)
{
PlaceShipsX();
}
else
{
PlaceShipsY();
}
}
}
}