私は一種の「あなたは私の戦艦を沈めた」ゲームを作成しようとしています. これまでのところ、2 つのアレイがあります。 1. ボード (テーブル) -- プレイするサーフェス 2. 船 (Avion) -- この場合は飛行機
私が達成しようとしているのは、表面全体を含み、その中にプレーンを配置する3番目の配列を作成することです。
だから私は飛行機を持っています:
0 0 1 0 0
1 1 1 1 1
0 0 1 0 0
0 0 1 0 0
0 1 1 1 0
および表面:
1 2 3 4 5 6 7 8 8 10
A 0 0 0 0 0 0 0 0 0 0
B 0 0 0 0 0 0 0 0 0 0
C 0 0 0 0 0 0 0 0 0 0
D 0 0 0 0 0 0 0 0 0 0
E 0 0 0 0 0 0 0 0 0 0
F 0 0 0 0 0 0 0 0 0 0
G 0 0 0 0 0 0 0 0 0 0
H 0 0 0 0 0 0 0 0 0 0
I 0 0 0 0 0 0 0 0 0 0
J 0 0 0 0 0 0 0 0 0 0
私が達成しようとしているのは次のとおりです。
1 2 3 4 5 6 7 8 8 10
A 0 0 1 0 0 0 0 0 0 0
B 1 1 1 1 1 0 0 0 0 0
C 0 0 1 0 0 0 0 0 0 0
D 0 0 1 0 0 0 0 0 0 0
E 0 1 1 1 0 0 0 0 0 0
F 0 0 0 0 0 0 0 0 0 0
G 0 0 0 0 0 0 0 0 0 0
H 0 0 0 0 0 0 0 0 0 0
I 0 0 0 0 0 0 0 0 0 0
J 0 0 0 0 0 0 0 0 0 0
int counterAvion = 0;
int counterTable = 0;
int[,] Table = new int[10, 10];
int[,] Avion = new int[5, 5];
int[,] Combined = new int[10, 10];
// Table[][]
//rowA
Table[0, 0] = 0; Table[0, 1] = 0; Table[0, 2] = 0; Table[0, 3] = 0; Table[0, 4] = 0;
Table[0, 5] = 0; Table[0, 6] = 0; Table[0, 7] = 0; Table[0, 8] = 0; Table[0, 9] = 0;
//rowB
Table[1, 0] = 0; Table[1, 1] = 0; Table[1, 2] = 0; Table[1, 3] = 0; Table[1, 4] = 0;
Table[1, 5] = 0; Table[1, 6] = 0; Table[1, 7] = 0; Table[1, 8] = 0; Table[1, 9] = 0;
//rowC
Table[2, 0] = 0; Table[2, 1] = 0; Table[2, 2] = 0; Table[2, 3] = 0; Table[2, 4] = 0;
Table[2, 5] = 0; Table[2, 6] = 0; Table[2, 7] = 0; Table[2, 8] = 0; Table[2, 9] = 0;
//rowD
Table[3, 0] = 0; Table[3, 1] = 0; Table[3, 2] = 0; Table[3, 3] = 0; Table[3, 4] = 0;
Table[3, 5] = 0; Table[3, 6] = 0; Table[3, 7] = 0; Table[3, 8] = 0; Table[3, 9] = 0;
//rowE
Table[4, 0] = 0; Table[4, 1] = 0; Table[4, 2] = 0; Table[4, 3] = 0; Table[4, 4] = 0;
Table[4, 5] = 0; Table[4, 6] = 0; Table[4, 7] = 0; Table[4, 8] = 0; Table[4, 9] = 0;
//rowF
Table[5, 0] = 0; Table[5, 1] = 0; Table[5, 2] = 0; Table[5, 3] = 0; Table[5, 4] = 0;
Table[5, 5] = 0; Table[5, 6] = 0; Table[5, 7] = 0; Table[5, 8] = 0; Table[5, 9] = 0;
//rowG
Table[6, 0] = 0; Table[6, 1] = 0; Table[6, 2] = 0; Table[6, 3] = 0; Table[6, 4] = 0;
Table[6, 5] = 0; Table[6, 6] = 0; Table[6, 7] = 0; Table[6, 8] = 0; Table[6, 9] = 0;
//rowH
Table[7, 0] = 0; Table[7, 1] = 0; Table[7, 2] = 0; Table[7, 3] = 0; Table[7, 4] = 0;
Table[7, 5] = 0; Table[7, 6] = 0; Table[7, 7] = 0; Table[7, 8] = 0; Table[7, 9] = 0;
//rowI
Table[8, 0] = 0; Table[8, 1] = 0; Table[8, 2] = 0; Table[8, 3] = 0; Table[8, 4] = 0;
Table[8, 5] = 0; Table[8, 6] = 0; Table[8, 7] = 0; Table[8, 8] = 0; Table[8, 9] = 0;
//rowJ
Table[9, 0] = 0; Table[9, 1] = 0; Table[9, 2] = 0; Table[9, 3] = 0; Table[9, 4] = 0;
Table[9, 5] = 0; Table[9, 6] = 0; Table[9, 7] = 0; Table[9, 8] = 0; Table[9, 9] = 0;
// Avion[][]
//head
Avion[0, 0] = 0; Avion[0, 1] = 0; Avion[0, 2] = 1; Avion[0, 3] = 0; Avion[0, 4] = 0;
//wings
Avion[1, 0] = 1; Avion[1, 1] = 1; Avion[1, 2] = 1; Avion[1, 3] = 1; Avion[1, 4] = 1;
//mid_1
Avion[2, 0] = 0; Avion[2, 1] = 0; Avion[2, 2] = 1; Avion[2, 3] = 0; Avion[2, 4] = 0;
//mid_2
Avion[3, 0] = 0; Avion[3, 1] = 0; Avion[3, 2] = 1; Avion[3, 3] = 0; Avion[3, 4] = 0;
//tail
Avion[4, 0] = 0; Avion[4, 1] = 1; Avion[4, 2] = 1; Avion[4, 3] = 1; Avion[4, 4] = 0;
// Output Avion[][]
Console.WriteLine("\nAirplane:\n");
foreach (var item in Avion)
{
counterAvion++;
Console.Write(item.ToString() + " ");
if (counterAvion == 5)
{
Console.WriteLine("\n");
counterAvion = 0;
}
}
// Output Table[][]
Console.WriteLine("\nTable:\n");
Console.WriteLine(" 1 2 3 4 5 6 7 8 9 10\n");
int counterColumn = 1;
foreach (var item in Table)
{
counterTable++;
//Console.WriteLine(counterColumn);
switch (counterColumn)
{
case 1:
Console.Write("A ");
break;
case 12:
Console.Write("B ");
break;
case 23:
Console.Write("C ");
break;
case 34:
Console.Write("D ");
break;
case 45:
Console.Write("E ");
break;
case 56:
Console.Write("F ");
break;
case 67:
Console.Write("G ");
break;
case 78:
Console.Write("H ");
break;
case 89:
Console.Write("I ");
break;
case 100:
Console.Write("J ");
break;
default:
break;
}
Console.Write(item.ToString() + " ");
if (counterTable == 10)
{
Console.WriteLine("\n");
counterTable = 0;
counterColumn++;
}
counterColumn++;
}
Console.ReadLine();
私は C# は初めてで、今のところ気に入っていますが、昔遊んでいた BorlandC とは違います。
それで、これを達成する方法についてのアイデアはありますか?
また、これまでの私のコードがちょっと乱雑であるという事実も認識しているので、その点についての意見をお待ちしております。