Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- using System;
- using System.Text;
- using System.Collections;
- using System.Collections.Generic;
- namespace ConsoleApp3
- {
- class GuessingGame
- {
- static Random RandomWords = new Random();
- static int t = RandomWords.Next(0, 5), pts = 0, wrongguess = 0;
- char input;
- bool correct = false;
- static ArrayList words = new ArrayList(new[] { "ICECREAM", "CHOCOLATE", "BURGER", "PIZZA", "SPAGHETTI" });
- static StringBuilder sb = new StringBuilder((String)words[t]);
- static String[] placeholder = new String[sb.Length];
- public void Play()
- {
- for (int x = 0; x < sb.Length; x++)
- {
- placeholder[x] = "_";
- }
- Console.WriteLine("\nGuess the random word!\n");
- printWord();
- while (pts != sb.Length)
- {
- try
- {
- Console.Write("\nEnter a letter: \n");
- input = Convert.ToChar(Console.ReadLine().ToUpper());
- }
- catch(Exception e){
- Console.WriteLine("LETTER ONLY");
- }
- for (int x = 0; x < sb.Length; x++)
- {
- if (input == sb[x])
- {
- placeholder[x] = Convert.ToString(sb[x]);
- pts++;
- correct = true;
- }
- }
- if (correct)
- {
- Console.WriteLine("\nYour guess is right!\n");
- }
- else
- {
- wrongguess++;
- if (wrongguess == 5)
- {
- Console.WriteLine("\nYou got 5 more tries\n");
- }
- else if (wrongguess == 10)
- {
- Console.WriteLine("\nGAME OVER!\n");
- Environment.Exit(0);
- }
- }
- printWord();
- }
- Console.WriteLine("\nYOU WIN, The word is"+words[t]+ "\n");
- void printWord()
- {
- Console.WriteLine(" ");
- for (int x = 0; x < sb.Length; x++)
- {
- Console.Write(placeholder[x] + " ");
- }
- Console.WriteLine(" ");
- }
- }
- }
- class Program
- {
- static void Main()
- {
- GuessingGame g = new GuessingGame();
- g.Play();
- }
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement