//檢查生命值與扣點數 protected void CheckLife(AbstractMember m) { // 還活著 if (m.IsAlive != false) { if (m.Grade >= 0) { if (m.LifeValue == 0) { m.Grade -= 1; //扣等級點數 1 m.LifeValue = 2000; //補充生命值 2000 } m.LifeValue -= 1000; //扣生命點數 1000 if (m.LifeValue == 0 && m.Grade == 0) { m.IsAlive = false; ResultTxt.Text = m.Name + " 已經掛了~"; } else { ResultTxt.Text = "我是" + m.Name + ",我被攻擊了," + GetHelperList(m) + "快來救我,我的生命值只剩餘" + m.LifeValue + ";等級剩餘 " + m.Grade; CallHelp(m); //通知所有夥伴來救援 } } } else { ResultTxt.Text = m.Name + " 已經掛了~"; } }
//通知所有夥伴來救援(觀察者) protected void CallHelp(AbstractMember m) { //加入參數值 ControllerEventArgs.Who = m.Name; //通知所有訂閱者 ControllerEventHandler.Notify(ControllerEventArgs); }
//找出未被攻擊的夥伴請單 protected string GetHelperList(AbstractMember m) { string tmpNames = ""; IEnumerable <AbstractMember> query = from member in MemberList where member.Name != m.Name select member; foreach (var list in query) { tmpNames += list.Name + ","; } return(tmpNames); }