Namespace Duzhanxiaoyouxi
{
struct Renwu //define struct type
{
public string Name;
public int Blood; This is the struct: the structure is a complex type that we define ourselves to solve the complex problems of life.
public int Attack;
public int defence;
public int speed;
Public Wugong WG; //Structs can also be referenced within the structure body
}
struct Wugong//struct can define multiple
{
public string Name;
Publicint Attack; Public common variable type variable name;
public int defence;
public int speed;
}
Class Program
{
static void Main (string[] args)
{
Create
Renwu r1 = new Renwu (); The constructed type can be used like int, string, and so on
Renwu r2 = new Renwu ();
Console.Write ("Please enter the name of the first Warrior:");
R1. Name = Console.ReadLine ();
Console.Write ("Please enter the name of the second Warrior:");
R2. Name = Console.ReadLine ();
Generate Blood Volume
Random rand = new Random ();
R1. Blood = Rand. Next (1000) + 1000;
R2. Blood = Rand. Next (1000) + 1000;
Generate attack and defense
R1. Attack = Rand. Next (100) + 50;
R1. Defence = rand. Next (100) + 50;
R2. Attack = Rand. Next (100) + 50;
R2. Defence = rand. Next (100) + 50;
Generate SHENFA
R1. Speed = Rand. Next (100);
R2. Speed = Rand. Next (100);
Console.WriteLine (R1. Name + "The amount of blood is:" + R1. Blood + "drop \ t Attack is:" + R1. Attack + "\ t defensive force:" + R1. Defence);
Console.WriteLine (R2. Name + "The amount of blood is" + R2. Blood + "drop \ t Attack is:" + R2. Attack + "\ t defensive force:" + R2. Defence);
Console.WriteLine ();
War
while (true)
{
Conditions for jumping out of a loop
if (R1. Blood <= 0 && R2. Blood <= 0)
{
Console.WriteLine (R1. Name + "and" + R2. Name + "perish");
Break
}
if (R1. Blood <= 0)
{
Console.WriteLine (R2. Name + "put" + R1. Name + "Ko");
Break
}
if (R2. Blood <= 0)
{
Console.WriteLine (R1. Name + "put" + R2. Name + "Ko");
Break
}
Start battle
int SHENFA = rand. Next (50) +50;
The speed is slightly slower some pause one second
System.Threading.Thread.Sleep (1000);
if (R2. Speed > Shenfa)
{
Console.WriteLine (R2. Name + "escaped" + R1. Name + "attack");
}
Else
{
int shanghai1 = rand. Next (100) + 50;//The first damage to the second
Shanghai1 + = R1. Attack-r2. Defence; The second person actually lost the blood
R2. Blood = (R2. BLOOD-SHANGHAI1) < 0? 0: (R2. BLOOD-SHANGHAI1);
Change text color
Console.foregroundcolor = Consolecolor.blue;
Console.Write (R1. Name + "Launch attack," + R2. Name + "Dropped" + (Shanghai1 < 0? 0:shanghai1) + "drop blood \ t");
Console.WriteLine ();
}
if (R1. Speed > Shenfa)
{
Console.WriteLine (R1. Name + "escaped" + R2. Name + "attack");
}
Else
{
int SHANGHAI2 = rand. Next (100) + 50;
SHANGHAI2 + = R2. Attack-r1. Defence;
R1. Blood = (R1. BLOOD-SHANGHAI2) < 0? 0: (R1. BLOOD-SHANGHAI2);
Change text color
Console.foregroundcolor = consolecolor.red;
Console.WriteLine (R2. Name + "Launch attack," + R1. Name + "Dropped" + (Shanghai2 < 0? 0:shanghai2) + "dripping blood");
}
Change text color
Console.foregroundcolor = Consolecolor.green;
Console.WriteLine (R1. Name + "The remaining amount of blood is" + R1. Blood + "\ T" + R2. Name + "The remaining amount of blood is" + R2. Blood);
Console.WriteLine ();
Console.WriteLine ();
}
}
}
}
January 5 structure (PvP mini-game)