示例#1
0
 public static void NoDelete()
 {
     // kollar så att listan har mer än 1 ord innan man deletar och om den har 1 eller mindre så tillåter den dig inte att deleta ord
     if (File.Exists("words.json"))
     {
         string      fileContent = File.ReadAllText("words.json");
         CustomWords newWords    = JsonConvert.DeserializeObject <CustomWords>(fileContent);
         if (newWords.words.Count <= 1)
         {
             Exists = false;
         }
     }
 }
示例#2
0
 public static void CheckFileV2()
 {
     // kollar om listan existerar så att man kan edita den när man vill deleta.
     if (File.Exists("words.json"))
     {
         string      fileContent = File.ReadAllText("words.json");
         CustomWords newWords    = JsonConvert.DeserializeObject <CustomWords>(fileContent);
         if (newWords.words.Count > 0)
         {
             Exists = true;
         }
     }
 }
示例#3
0
 public static void CheckFile()
 {
     // kollar så att det finns mer än 0 ord i listan och gör placeholder listan till den listan om det är mer än 0 i listan
     if (File.Exists("words.json"))
     {
         string      fileContent = File.ReadAllText("words.json");
         CustomWords newWords    = JsonConvert.DeserializeObject <CustomWords>(fileContent);
         if (newWords.words.Count > 0)
         {
             Words = newWords.words;
         }
     }
 }
示例#4
0
        public static void Add()
        {
AddAgain:
            CustomWords oldWords = null;   // Sätter owlWords till ingenting

            if (File.Exists("words.json")) // gör så att oldWords innehåller allt i word.json filen
            {
                string fileContent = File.ReadAllText("words.json");
                oldWords = JsonConvert.DeserializeObject <CustomWords>(fileContent);
            }

            Console.WriteLine("Write what word you want to add:");
            string existing = File.ReadAllText("words.json"); // låser in words.json och gör så att existing printar ut hela listan

FaultyWord:
            Console.WriteLine(existing);
            string newWord = Console.ReadLine();

            Console.Clear();
            if (newWord == "") // båda dessa if kollar så att man inte lägger till något som kommer vara nästan omöjligt att gissa
            {
                Console.Clear();
                Console.WriteLine("Must be a word!");
                goto FaultyWord;
            }
            else // kollar igenom hela ordet så att det inte är några mellanrum mitt i ordet.
            {
                for (int i = 0; i < newWord.Length; i++)
                {
                    if (newWord[i] == ' ')
                    {
                        Console.Clear();
                        Console.WriteLine("Please don't use spaces!");
                        goto FaultyWord;
                    }
                }
            }
            for (int i = 0; i < Words.Count; i++)// kollar genom alla ord som finns i listan och kollar så att man inte lägger till samma ord två gånger
            {
                if (Words[i] == newWord)
                {
                    Console.Clear();
                    Console.WriteLine("Already existing word!");
                    goto FaultyWord;
                }
            }
            #region addingword
            Console.Clear();
            Words.Add(newWord.ToLower()); // gör så att ordet man vill lägga in är i små bokstäver så man inte behöver gissa med stora bokstäver
            // från 1 till 1 så lägger den till det nya ordet i den redan existerande listan av ord
            // 1
            oldWords.words.Add(newWord);
            String insertedword = JsonConvert.SerializeObject(oldWords);
            File.WriteAllText("words.json", insertedword);
            // 1
            Console.WriteLine("Do you want to add another word?");
FaultyAnswer:
            Console.WriteLine("yes or no");
            YoN = Console.ReadLine();
            Console.Clear();
            #endregion
            if (YoN.ToLower() == "yes")
            {
                goto AddAgain;
            }
            else if (YoN.ToLower() == "no")
            {
                Console.WriteLine("Do you want to play?");
incorrectAnswer:
                Console.WriteLine("Yes or no");
                YoN = Console.ReadLine();
                Console.Clear();
                if (YoN.ToLower() == "yes")
                {
                    Play = true;
                }
                else if (YoN.ToLower() == "no")
                {
                    Play = false;
                    Console.Clear();
                }
                else
                {
                    goto incorrectAnswer;
                }
            }
            else
            {
                Console.WriteLine("Try Again!");
                goto FaultyAnswer;
            }
            // kollar om man vill lägga till mera ord och om man inte vill så kollar den om man vill spela igen där den sätter play boolean till true om man vill annars till false
        }
示例#5
0
        public static void Delete()
        {
DelAgain:
            NoDelete();// går in i metoden som kollar om listan i .json filen har ett ord eller mindre annars och då kan man inte ta bort ord innan man lagt till mer
            if (!Exists)
            {
                Console.WriteLine("You can't delete your only word please add more before you delete");
                return;
            }
            #region Remove
            Console.WriteLine("Write what word you want to delete:");
            // 1
            string existing = File.ReadAllText("words.json");
            Console.WriteLine(existing);
            string newWord = Console.ReadLine();
            Console.Clear();
            // 1
            // från 1 till 1 så printar den hela listan av ord och tar in en variabel
            // 2
            Words.Remove(newWord.ToLower());
            CustomWords newWords = new CustomWords();
            newWords.words = Words;
            String insertedword = JsonConvert.SerializeObject(newWords);
            File.WriteAllText("words.json", insertedword);
            // 2
            // från 2 till 2 så tar den variabeln den fått av spelaren och om det är ett ord som inte existerar i listan ändras inget.
            Console.WriteLine("Do you want to delete another word?");
FaultyAnswer:
            Console.WriteLine("yes or no");
            YoN = Console.ReadLine(); //läser in variabel
            Console.Clear();
            #endregion
            if (YoN.ToLower() == "yes")
            {
                goto DelAgain;              // om man vill ta bort ett till ord så går den till toppen av metoden där den kollar om man kan ta bort ett ord eller inte i metoden DelAgain
            }
            else if (YoN.ToLower() == "no") // om man inte vill ta bort igen så kollar den om man vill spela igen
            {
                Console.WriteLine("Do you want to play?");
incorrectAnswer:
                Console.WriteLine("Yes or no");
                YoN = Console.ReadLine();   //läser in variabel
                Console.Clear();
                if (YoN.ToLower() == "yes") // om YoN är yes så sätts Play variabeln till true. Detta är för att när den kommer ut metoden så finns en if som skickar dig till starten av programmet igen
                {
                    Play = true;
                }
                else if (YoN.ToLower() == "no") // om YoN är no så stoppar den hela programmet genom att sätta Play till false
                {
                    Play = false;
                    Console.Clear();
                }
                else// om YoN inte är yes/no så frågar den igen
                {
                    goto incorrectAnswer;
                }
            }
            else// om YoN inte är yes/no så frågar den igen
            {
                Console.WriteLine("Try Again!");
                goto FaultyAnswer;
            }
        }