標籤:amp else shang alt ret sleep bsp 分享 color
namespace 對戰遊戲
{
class Program
{
public struct ZhanShi
{
public string MingZi;
public int GongJi;
public int XueLiang;
}
static void Main(string[] args)
{
建立戰士給戰士賦予屬性
ZhanShi zs1 = new ZhanShi();
zs1.MingZi = "張無忌";
zs1.GongJi = 100;
zs1.XueLiang = 1000;
ZhanShi zs2 = new ZhanShi();
zs2.MingZi = "洪七公";
zs2.GongJi = 150;
zs2.XueLiang = 700;
//對打
while (true)
{
int ShangHai = Program.PuTongGongJi(zs1.GongJi);
zs2.XueLiang = zs2.XueLiang - ShangHai;
Console.ForegroundColor = ConsoleColor.Green;
Console.WriteLine(zs1.MingZi + " 對 " + zs2.MingZi + " 發動了普通攻擊,造成了" + ShangHai + "點傷害, " + zs2.MingZi + " 剩餘" + zs2.XueLiang + "點血量!");
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 + " 對 " + zs1.MingZi + " 發動了普通攻擊,造成了" + ShangHai + "點傷害, " + zs1.MingZi + " 剩餘" + zs1.XueLiang + "點血量!");
Console.WriteLine();
System.Threading.Thread.Sleep(1000);
if (zs1.XueLiang <= 0 || zs2.XueLiang <= 0)
{
if (zs1.XueLiang <= 0 && zs2.XueLiang <= 0)
{
Console.WriteLine("二位同歸於盡了!!!");
}
else
{
if (zs1.XueLiang <= 0)
{
Console.WriteLine(zs2.MingZi + "獲得了最終勝利!!!");
}
else
{
Console.WriteLine(zs1.MingZi + "獲得了最終勝利!!!");
}
}
break;
}
}
//判斷輸贏
Console.ReadKey();
}
產生浮動攻擊力
/// <summary>
/// 產生普通攻擊的浮動攻擊值
/// </summary>
/// <param name="a">普通攻擊的基礎攻擊力</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#對戰遊戲