Игра "Виселица" с условиями - C#
Формулировка задачи:
нужно сделать тоже самое но без использования классов, потоков и структуры
using System;
using System.Threading;
namespace ConsoleApplication1
{
struct Game
{
public string word;
public char[] stars;
public int count;
}
internal class Program
{
private static Game game;
private static void Main(string[] args)
{
const int maxCount = 15;
Console.Write("Введите слово:");
string str = Console.ReadLine().ToLower();
game.word = str;
game.stars=new string('*',str.Length).ToCharArray();
char symbol = ' ';
Thread th=new Thread(() =>
{
while (true)
{
Console.WriteLine(new string('-',30));
NewWord(symbol);
Console.WriteLine("Загаданное слово "+string.Join("",game.stars));
Console.WriteLine(new string('-', 30));
Console.WriteLine("Количество попыток {0},У Вас еще осталось {1}",game.count,maxCount-game.count);
if (game.word.Equals(string.Join("", game.stars)))
{
Console.WriteLine("You are win!");
return;
}
if (game.count == maxCount)
{
Console.WriteLine("You are lose!");
return;
}
Thread.Sleep(200);
Console.Clear();
}
});
th.Start();
Thread th2=new Thread(() =>
{
while (true)
{
symbol = (Char.ToLower(Console.ReadKey().KeyChar));
game.count++;
Thread.Sleep(300);
}
});
th2.IsBackground = true;
th2.Start();
Console.ReadKey(true);
}
static void NewWord(char s)
{
for (int i = 0; i < game.word.Length; i++)
{
if (game.word[i] == s)
{
game.stars[i] = s;
}
}
}
}
}Решение задачи: «Игра "Виселица" с условиями»
textual
Листинг программы
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using bookss;
namespace _123
{
class Program
{
static void Main(string[] args)
{
Console.OutputEncoding = Encoding.GetEncoding(1251);
Console.Write("Введите слово которое нужно будет отгадивать: ");
string zagSL = Console.ReadLine().ToLower();
int lg = zagSL.Length, kilm = 0;
List<string> zs = new List<string>();
int pop = 0;
Console.Clear();
while (true)
{
if (pop == 5)
{
Console.WriteLine("Ви програли!");
Console.ReadKey();
break;
}
if (kilm == lg)
{
Console.WriteLine("Ви вииграли!");
Console.ReadKey();
break;
}
Console.Write("Введите букву: ");
string ch = Console.ReadLine().ToLower();
if (zagSL.Contains(ch[0]) && !zs.Contains(ch[0].ToString()))
{
for (int i = 0; i < zagSL.Length; i++)
if (zagSL[i] == ch[0])
++kilm;
Console.WriteLine("Буква " + ch[0] + " есть в етом слове.");
zs.Add(ch[0].ToString());
}
else ++pop;
}
}
}
}