// Combat Games
Struct duizhan
{
Public string name;
Public int Xue;
Public int gongji;
Public int fangyu;
Public int mingzhong;
Public int Shengfa;
}
Static void main (string [] ARGs)
{
Duizhan [] A = new duizhan [5]; // defines the struct and creates an array.
Int I = 0;
For (; I <5; I ++) // Input
{
Console. Write ("enter the name of the {0} person:", I + 1 );
A [I]. Name = console. Readline ();
Int M = (INT) convert. tochar (A [I]. Name. substring (0, 1 ));
Random n = new random (m );
A [I]. Xue = 1000 + N. Next (1000 );
A [I]. gongji = 50 + N. Next (100 );
A [I]. mingzhong = 50 + N. Next (100 );
A [I]. fangyu = 30 + N. Next (100 );
A [I]. Shengfa = 30 + N. Next (100 );
Console. write ("vitality:" + A [I]. xue + "\ t attack power:" + A [I]. gongji + "\ t hit rate:" + A [I]. mingzhong + "\ t defensive capabilities" + A [I]. fangyu + "\ t body" + A [I]. shengfa + "\ n ");
}
Console. writeline ("press any key to start! ");
Console. readkey (); // press any key to start
While (true)
{
Random M = new random ();
Int P = M. Next (5 );
Int q = M. Next (5); // randomly generate two contestants
If (P! = Q & A [p]. Xue> 0 & A [Q]. Xue> 0)
{
Console. writeline ("\ n ");
Console. foregroundcolor = lelecolor. Yellow; // modify the font color.
Console. writeline (A [p]. Name + "attack Preparation" + A [Q]. Name );
Thread. Sleep (3000); // delay of 3 seconds
A [p]. gongji = M. Next (150) + 50;
A [p]. mingzhong = M. Next (150) + 50;
Int shashangli = A [p]. gongji + A [p]. mingzhong;
A [Q]. fangyu = M. Next (130) + 50;
A [Q]. Shengfa = M. Next (130) + 50;
Int dikangli = A [Q]. fangyu + A [Q]. Shengfa;
Console. Write ("\ n ");
If (shashangli> dikangli) // identifies attack Conditions
{
Int Shixue = A [p]. gongji-A [Q]. fangyu;
Console. foregroundcolor = consolecolor. Red;
Console. writeline (A [p]. Name + "attacked" + A [Q]. Name + Shixue + "bleeding! ");
Console. foregroundcolor = consolecolor. Green;
A [Q]. Xue = A [Q]. Xue-Shixue;
Console. writeline (A [Q]. Name + "remaining" + A [Q]. Xue + "bleeding! ");
}
Else
{
Console. foregroundcolor = consolecolor. blue;
Console. writeline (A [Q]. Name + "escaped the" + A [p]. Name + "attack! ");
}
}
Else if (a [p]. Xue <= 0)
{
Console. foregroundcolor = consolecolor. Red;
Console. writeline (A [p]. Name + "defeated! ");
}
Else if (a [Q]. Xue <= 0)
{
Console. foregroundcolor = consolecolor. Red;
Console. writeline (A [Q]. Name + "defeated! ");
}
Else
{
Continue;
}
}
// Functions (name input, processing, and output) are highly cohesive, which are called by low coupling and independent division of labor.
// Add static int max (int A, int B) to the class)
//{
// If (A> B) {return a} else {return B}
//}
// You can use it in main.
// Int x = 3, y = 4;
// Console. writeline ("maximum value:" + max (x, y ));
// Int x = 3, y = 4, C = 5;
// Int A = max (x, y), C );
// Console. writeline ("maximum value:" + );
Functions and Combat Games