C # mini games ------- guess numbers

Source: Internet
Author: User

My friends, I just wrote this little game. It's over 11 o'clock. take a break and enjoy it. learning any language is constantly being compiled. do not use simplicity rather than simplicity. using System;
Public class Game
{
Private string number;
Private static int x, y;
Private int count = 0;

Public void init ()
{
Do {
Console. WriteLine ("Please input number :");
Number = (string) Console. ReadLine ();
} While (number. Length! = 4 );
}
Public void play ()
{
String READ = "1234 ";
// Here, the value of ready must be randomly changed. Otherwise, no one will play your game.
// Char [] r = new char [] {0,... 9 };
// Use loops and random functions to disrupt the order. Get the first four elements and give them to ready.
Do {
X = 0;
Y = 0;
Init ();
For (int I = 0; I <= 3; I ++)
{
For (int j = 0; j <= 3; j ++)
{
If (number [I] = ready [j])
{
If (I = j)
++ X;
Else
++ Y;
}
}
}
++ Count;
Console. WriteLine ("{0} A {1} B", x. ToString (), y. ToString ());
If (count> = 8)
{
Console. WriteLine ("-------------------");
Console. WriteLine ("You already lossed ");
Console. WriteLine ("-------------------");
Return;
}
} While (number! = Ready );
Console. WriteLine ("----------------------------");
Console. WriteLine ("OK! You are very cleverness! ");
Console. WriteLine ("----------------------------");

}
}
Public class MyGame
{
Public static void Main ()
{
Game g = new Game ();
G. play ();
}
}
It has been compiled.

Related Article

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.