elleryq
3/19/2015 - 9:36 AM

猜數字遊戲

猜數字遊戲

using System;
using System.Linq;
public class Guess
{
  public static void Main(string[] args)
  {
    int scoreCount = 0, score = 100;
    string answer = "test", user_input, out_put = string.Empty;
    Console.WriteLine("Enter a length {0} word start with {1}:", answer.Length.ToString(), answer.Substring(0, 1));
    do
    {
      user_input = Console.ReadLine();
      out_put = String.Join(" ", user_input.Zip(answer, (x1, x2) => x1==x2?x1:'*' ));
      scoreCount++;
      Console.WriteLine(out_put);
      out_put = string.Empty;
    } while (answer != user_input);
    Console.WriteLine("Congratulations! The answer is {0}!", answer);
    Console.WriteLine("Score:{0}", (score - (scoreCount - 1) * 10).ToString());
    Console.WriteLine("bye!");
  }
}