C # Battle Game

Source: Internet
Author: User

Namespace Battle Game
{
Class Program
{
public struct Zhanshi
{
public string Mingzi;
public int Gongji;
public int Xueliang;
}


static void Main (string[] args)
{
Creating warriors gives the warrior attributes
Zhanshi zs1 = new Zhanshi ();
Zs1. Mingzi = "Zhang Mowgli";
Zs1. Gongji = 100;
Zs1. Xueliang = 1000;

Zhanshi zs2 = new Zhanshi ();
Zs2. Mingzi = "Hong Seven public";
Zs2. Gongji = 150;
Zs2. Xueliang = 700;

Playing
while (true)
{
int Shanghai = Program.putonggongji (zs1. Gongji);
Zs2. Xueliang = Zs2. Xueliang-shanghai;
Console.foregroundcolor = Consolecolor.green;
Console.WriteLine (ZS1. Mingzi + "pair" + zs2. Mingzi + "launched a common attack, resulting in" + Shanghai + "point damage," + ZS2. Mingzi + "remaining" + zs2. Xueliang + "point blood volume!" ");
Console.WriteLine ();
System.Threading.Thread.Sleep (1000);

Shanghai = Program.putonggongji (zs2. Gongji);
Zs1. Xueliang = Zs1. Xueliang-shanghai;
Console.foregroundcolor = Consolecolor.yellow;
Console.WriteLine (Zs2. Mingzi + "pair" + zs1. Mingzi + "launched a common attack, resulting in" + Shanghai + "point damage," + ZS1. Mingzi + "remaining" + zs1. Xueliang + "point blood volume!" ");
Console.WriteLine ();

System.Threading.Thread.Sleep (1000);

if (zs1. Xueliang <= 0 | | Zs2. Xueliang <= 0)
{
if (zs1. Xueliang <= 0 && zs2. Xueliang <= 0)
{
Console.WriteLine ("Two people perish!!!" ");
}
Else
{
if (zs1. Xueliang <= 0)
{
Console.WriteLine (Zs2. Mingzi + "won the final victory!!! ");
}
Else
{
Console.WriteLine (ZS1. Mingzi + "won the final victory!!! ");
}
}
Break
}
}

Judging winning or losing


Console.readkey ();
}
Generate floating attack damage
<summary>
Generate a floating attack value for a normal attack
</summary>
<param name= "A" > Common attack Base attack </param>
<returns></returns>
public static int Putonggongji (int a)
{
int cc = 0;
Random r = new Random ();
int aa = R.next (0, 141);
int bb = R.next (0, 2);
if (BB = = 0)
{
CC = a + AA;
}
Else
{
CC = A-AA;
}
return cc;
}
}
}

C # Battle 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.