January 5 structure (PvP mini-game)

Source: Internet
Author: User

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)

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.