Esempio n. 1
0
 public static void ReadAndPrint()
 {
     Records.Read();
     for (int i = 0; i < names.Count; i++)
     {
         Console.Write(names[i] + " ");
         Console.WriteLine(points[i]);
     }
 }
Esempio n. 2
0
        public static void NewGame()
        {
            Console.Clear();

            if (!gameContinue)
            {
                Console.WriteLine("Введите ваш никнейм");
                playerName = Console.ReadLine().Trim(' ');
                Console.Clear();

                Console.WriteLine("Введите уровень от 5 до 28");

                Field.lvl = ReadLvl();
                Console.Clear();

                Console.Write("Идёт создание карты филвордов...");

                field = Field.FillField();
                Console.Clear();

                quessedWords      = new char[Field.xLenght, Field.yLenght];
                numOfQuessedWords = 0;

                for (int i = 0; i < Field.xLenght; i++)
                {
                    for (int j = 0; j < Field.yLenght; j++)
                    {
                        Console.SetCursorPosition(i, j);
                        Console.Write(field[i, j]);
                    }
                }
            }
            else
            {
                for (int i = 0; i < Field.xLenght; i++)
                {
                    for (int j = 0; j < Field.yLenght; j++)
                    {
                        if (quessedWords[i, j] == '*')
                        {
                            PrintingColoredChar(i, j, "green");
                        }
                        else
                        {
                            PrintingColoredChar(i, j, "black");
                        }
                    }
                }
                gameContinue = false;
            }



            for (int i = 0; i < 1; i++)
            {
                Console.SetCursorPosition(0, i + Field.yLenght + 1);
                Console.Write(Field.fieldWords1[i]);
            }


            Console.SetCursorPosition(0, 0);

            ConsoleKeyInfo key;
            int            x           = 0;
            int            y           = 0;
            string         currentWord = null;


            bool stopFor = false;

            bool wordIsQuessed = true;
            int  firstLetter   = 0;


            char[,] thisTry = new char[Field.xLenght, Field.yLenght];
            bool enter = false;


            for (; ;)
            {
                if (stopFor)
                {
                    Console.SetCursorPosition(Field.xLenght + 1, 0);
                    Console.Write("Правильно!");
                    Continue.DeleteFile();
                    Records.Read();
                    if (Records.names.Contains(playerName))
                    {
                        for (int i = 0; i < Records.names.Count; i++)
                        {
                            if (Records.names[i] == playerName)
                            {
                                Records.points[i] += Field.xLenght * Field.yLenght;
                                break;
                            }
                        }
                    }
                    else
                    {
                        Records.names.Add(playerName);
                        Records.points.Add(Field.xLenght * Field.yLenght);
                    }
                    Records.WriteInFile();
                    break;
                }

                Console.SetCursorPosition(x, y);
                key = Console.ReadKey();

                if (quessedWords[x, y] != '*' && !enter)
                {
                    PrintingColoredChar(x, y, "black");
                }
                else if (enter)
                {
                    PrintingColoredChar(x, y, "red");
                }
                else if (quessedWords[x, y] == '*')
                {
                    PrintingColoredChar(x, y, "green");
                }


                switch (key.Key)
                {
                case ConsoleKey.UpArrow:
                    if (IsEnterInFieldArea(x, y - 1) && thisTry[x, y - 1] != '*')
                    {
                        if (!enter)
                        {
                            PrintingColoredChar(x, y - 1, "blue");
                            y--;
                        }

                        if (enter && quessedWords[x, y - 1] != '*')
                        {
                            y            -= 1;
                            currentWord  += field[x, y];
                            thisTry[x, y] = '*';
                            PrintingColoredChar(x, y, "red");
                            if (firstLetter != Field.numField1[x, y])
                            {
                                wordIsQuessed = false;
                            }
                        }
                    }
                    else
                    {
                        PrintingColoredChar(x, y, "blue");
                    }
                    break;

                case ConsoleKey.DownArrow:
                    if (IsEnterInFieldArea(x, y + 1) && thisTry[x, y + 1] != '*')
                    {
                        if (!enter)
                        {
                            PrintingColoredChar(x, y + 1, "blue");
                            y++;
                        }

                        if (enter && quessedWords[x, y + 1] != '*')
                        {
                            y            += 1;
                            currentWord  += field[x, y];
                            thisTry[x, y] = '*';
                            PrintingColoredChar(x, y, "red");
                            if (firstLetter != Field.numField1[x, y])
                            {
                                wordIsQuessed = false;
                            }
                        }
                    }
                    else
                    {
                        PrintingColoredChar(x, y, "blue");
                    }
                    break;

                case ConsoleKey.LeftArrow:
                    if (IsEnterInFieldArea(x - 1, y) && thisTry[x - 1, y] != '*')
                    {
                        if (!enter)
                        {
                            PrintingColoredChar(x - 1, y, "blue");
                            x--;
                        }

                        if (enter && quessedWords[x - 1, y] != '*')
                        {
                            x            -= 1;
                            currentWord  += field[x, y];
                            thisTry[x, y] = '*';
                            PrintingColoredChar(x, y, "red");
                            if (firstLetter != Field.numField1[x, y])
                            {
                                wordIsQuessed = false;
                            }
                        }
                    }
                    else
                    {
                        PrintingColoredChar(x, y, "blue");
                    }
                    break;

                case ConsoleKey.RightArrow:
                    if (IsEnterInFieldArea(x + 1, y) && thisTry[x + 1, y] != '*')
                    {
                        if (!enter)
                        {
                            PrintingColoredChar(x + 1, y, "blue");
                            x++;
                        }

                        if (enter && quessedWords[x + 1, y] != '*')
                        {
                            x            += 1;
                            currentWord  += field[x, y];
                            thisTry[x, y] = '*';
                            PrintingColoredChar(x, y, "red");

                            if (firstLetter != Field.numField1[x, y])
                            {
                                wordIsQuessed = false;
                            }
                        }
                    }
                    else
                    {
                        PrintingColoredChar(x, y, "blue");
                    }
                    break;

                case ConsoleKey.Enter:
                    if (!enter)
                    {
                        thisTry     = ClearArray();
                        currentWord = null;
                        PrintingColoredChar(x, y, "red");
                        currentWord  += field[x, y];
                        thisTry[x, y] = '*';
                        wordIsQuessed = true;
                        firstLetter   = Field.numField1[x, y];
                    }
                    else
                    {
                        if (Field.fieldWords1.Contains(currentWord) && wordIsQuessed)
                        {
                            numOfQuessedWords++;
                            if (numOfQuessedWords >= Field.fieldWords1.Count)
                            {
                                stopFor = true;
                            }

                            for (int i = 0; i < Field.xLenght; i++)
                            {
                                for (int j = 0; j < Field.yLenght; j++)
                                {
                                    if (thisTry[i, j] == '*')
                                    {
                                        quessedWords[i, j] = '*';
                                    }
                                }
                            }
                        }


                        for (int i = 0; i < Field.xLenght; i++)
                        {
                            for (int j = 0; j < Field.yLenght; j++)
                            {
                                if (quessedWords[i, j] == '*')
                                {
                                    PrintingColoredChar(i, j, "green");
                                }
                                else
                                {
                                    PrintingColoredChar(i, j, "black");
                                }
                            }
                        }

                        currentWord = "";
                        thisTry     = ClearArray();
                    }
                    enter = !enter;
                    break;

                case ConsoleKey.S:
                    Continue.SaveGame();
                    Console.Clear();
                    Program.Main();
                    break;

                default:
                    PrintingColoredChar(x, y, "black");
                    break;
                }
            }



            Console.ReadKey();
            Console.Clear();
            Program.Main();
        }