Created
August 24, 2024 14:05
-
-
Save IvanEnginer/021c3ba3da3face144a704ba6a7a04a4 to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
using System; | |
namespace HW_02 | |
{ | |
internal class Program | |
{ | |
static void Main(string[] args) | |
{ | |
int widhtField = 3; | |
int hightField = 3; | |
int trys = 6; | |
int winCounter = 0; | |
int totalWin = 3; | |
int choiseColum = 0; | |
int choiseRow = 0; | |
int randomColum = 0; | |
int randomRow = 0; | |
bool isCorrect = false; | |
bool isWork = true; | |
char notOpenBoxSimbol = 'o'; | |
char openBoxSimbol = 'x'; | |
string input; | |
char[,] field = new char[widhtField, hightField]; | |
Random random = new Random(); | |
for (int i = 0; i < field.GetLength(0); i++) | |
{ | |
for (int j = 0; j < field.GetLength(1); j++) | |
{ | |
field[i, j] = notOpenBoxSimbol; | |
} | |
} | |
while (isWork) | |
{ | |
for (int i = 0; i <= trys; i++) | |
{ | |
while (!isCorrect) | |
{ | |
randomColum = random.Next(0, hightField); | |
randomRow = random.Next(0, widhtField); | |
if (field[randomColum, randomRow] != openBoxSimbol) | |
{ | |
isCorrect = true; | |
} | |
} | |
isCorrect = false; | |
Console.WriteLine("Введите колонку, число от 1 до 3: "); | |
input = Console.ReadLine(); | |
if(int.TryParse(input, out int resulteColum)) | |
{ | |
choiseColum = resulteColum - 1; | |
} | |
else | |
{ | |
Console.WriteLine("Ошиька ввода"); | |
} | |
Console.WriteLine("Введите столбец, число от 1 до 3: "); | |
input = Console.ReadLine(); | |
if (int.TryParse(input, out int resulteRow)) | |
{ | |
choiseRow = resulteRow - 1; | |
} | |
else | |
{ | |
Console.WriteLine("Ошиька ввода"); | |
} | |
if(randomColum == choiseColum && randomRow == choiseRow) | |
{ | |
field[randomColum, randomRow] = openBoxSimbol; | |
winCounter++; | |
} | |
if(winCounter == totalWin) | |
{ | |
isWork = false; | |
} | |
Console.Clear(); | |
for (int k = 0; k < field.GetLength(0); k++) | |
{ | |
for (int m = 0; m < field.GetLength(1); m++) | |
{ | |
Console.Write(field[k, m] + " "); | |
} | |
Console.WriteLine(); | |
} | |
} | |
} | |
} | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment