Advertisement
nuggetin

fasdfas

Oct 17th, 2021 (edited)
1,201
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C# 2.68 KB | None | 0 0
  1. using System;
  2. using System.Text;
  3. using System.Collections;
  4. using System.Collections.Generic;
  5.  
  6. namespace ConsoleApp3
  7. {
  8.     class GuessingGame
  9.     {
  10.         static Random RandomWords = new Random();
  11.         static int t = RandomWords.Next(0, 5), pts = 0, wrongguess = 0;
  12.         char input;
  13.         bool correct = false;
  14.         static ArrayList words = new ArrayList(new[] { "ICECREAM", "CHOCOLATE", "BURGER", "PIZZA", "SPAGHETTI" });
  15.         static StringBuilder sb = new StringBuilder((String)words[t]);
  16.         static String[] placeholder = new String[sb.Length];
  17.  
  18.  
  19.  
  20.     public void Play()
  21.         {
  22.             for (int x = 0; x < sb.Length; x++)
  23.             {
  24.                 placeholder[x] = "_";
  25.             }
  26.            
  27.  
  28.             Console.WriteLine("\nGuess the random word!\n");
  29.             printWord();
  30.  
  31.             while (pts != sb.Length)
  32.             {
  33.                 try
  34.                 {
  35.                     Console.Write("\nEnter a letter: \n");
  36.                     input = Convert.ToChar(Console.ReadLine().ToUpper());
  37.                 }
  38.                 catch(Exception e){
  39.                     Console.WriteLine("LETTER ONLY");
  40.                 }
  41.                
  42.  
  43.                 for (int x = 0; x < sb.Length; x++)
  44.                 {
  45.                     if (input == sb[x])
  46.                     {
  47.                         placeholder[x] = Convert.ToString(sb[x]);
  48.                         pts++;
  49.                         correct = true;
  50.                     }
  51.                    
  52.                 }
  53.                 if (correct)
  54.                 {
  55.                     Console.WriteLine("\nYour guess is right!\n");
  56.                 }
  57.                 else
  58.                 {
  59.                     wrongguess++;
  60.                     if (wrongguess == 5)
  61.                     {
  62.                         Console.WriteLine("\nYou got 5 more tries\n");
  63.                     }
  64.                     else if (wrongguess == 10)
  65.                     {
  66.                         Console.WriteLine("\nGAME OVER!\n");
  67.                         Environment.Exit(0);
  68.                     }
  69.                 }
  70.                 printWord();
  71.             }
  72.             Console.WriteLine("\nYOU WIN, The word is"+words[t]+ "\n");
  73.  
  74.             void printWord()
  75.             {
  76.                 Console.WriteLine(" ");
  77.                 for (int x = 0; x < sb.Length; x++)
  78.                 {
  79.                     Console.Write(placeholder[x] + " ");
  80.                 }
  81.                 Console.WriteLine(" ");
  82.             }
  83.         }
  84.     }
  85.     class Program
  86.     {
  87.         static void Main()
  88.         {
  89.             GuessingGame g = new GuessingGame();
  90.             g.Play();
  91.         }
  92.     }
  93. }
  94.  
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement