/// <summary> /// Trash the card from the field. /// </summary> /// <param name="fieldIndex">Field index.</param> /// <param name="cardStr">Card string.</param> /// <returns>Trashed card instance.</returns> public Card Trash(int fieldIndex, string cardStr) { GameStatus.Status nextStatus = status.Act(GameStatus.Action.Trash); if (GameStatus.Status.Error == nextStatus) { throw GameException.getAlreadyTrashedException(); } if (fieldIndex >= FIELD_NUM || fieldIndex < 0) { throw GameException.getFieldIndexException(); } CardDeck deck = this.fields[fieldIndex].CardList[this.turn]; if (this.fields[fieldIndex].IsFixed || deck.Last().Name != cardStr) { throw GameException.getCardAlreadyFixedException(); } Card card = deck.Move(cardStr, this.talon.Trash); this.lastTrashed = card; this.lastTrashedField = this.fields[fieldIndex]; status.Current = card.HasSpecial ? nextStatus : GameStatus.Status.Trashed; return(card); }
/// <summary> /// Proceed to the next turn. /// </summary> public void nextTurn() { foreach (Field field in this.fields) { field.Eval(); } if (this.Winner >= 0) { this.status.Current = GameStatus.Status.RoundEnd; return; } GameStatus.Status nextStatus = this.IsFilled ? GameStatus.Status.First : status.Act(GameStatus.Action.Next); if (GameStatus.Status.Error == nextStatus) { throw GameException.getNotTrashedException(); } this.card9 [this.turn] = Constants.CARD9_NONE; this.turn = (this.turn + 1) % 2; this.lastTrashedField = null; this.lastTrashed = null; int drawNum = 5 - this.Player.Hand.Count(); for (int i = 0; i < drawNum; i++) { this.Draw(); } this.status.Current = nextStatus; }
/// <summary> /// Judge if the card string equals to this card. /// </summary> /// <param name="cardStr">The card name.</param> /// <returns>True: same False: different.</returns> public bool IsMatch(string cardStr) { if (!regex.IsMatch(cardStr)) { throw GameException.getCardStrException(cardStr); } return(this.name == cardStr); }
/// <summary> /// Draw a card from this talon and send it to another deck. /// </summary> /// <param name="to">The deck to send the card.</param> /// <returns>Drawn card.</returns> public Card Draw(CardDeck to) { if (this.list.Count() == 0) { throw GameException.getNoCardException(); } Card card = this.list.First(); CardDeck.handler(this, to, card); this.Move(card.Name, to); return(card); }
/// <summary> /// Fire the special effect of the card. /// </summary> /// <param name="opt">Special effect option.</param> public void Special(params string[] opt) { GameStatus.Status nextStatus = status.Act(GameStatus.Action.Special); if (GameStatus.Status.Error == nextStatus) { throw GameException.getAlreadyTrashedException(); } bool ret = this.lastTrashed.Special(this, opt); if (ret) { status.Current = nextStatus; } }
/// <summary> /// The special skill of this card. /// </summary> /// <param name="game">Game instance.</param> /// <param name="opt">Input option parameter.</param> /// <returns>Result.</returns> public bool Special(CardGame game, params string[] opt) { bool ret = true; if (this.power == 1) { Field field = game.Fields[Int32.Parse(opt[1])]; if (field.IsFixed) { throw GameException.getCardAlreadyFixedException(); } string cardStr = opt[0]; game.Trash(field.Number, cardStr); //CardDeck fieldDeck = field.CardList[game.Turn]; //fieldDeck.Move(cardStr, game.Talon.Trash); ret = false; } else if (this.power == 3) { int count = game.Player.Hand.Count(); game.Player.Hand.MoveAll(game.Talon.Trash); for (int i = 0; i < count; i++) { game.Draw(); } } else if (this.power == 5) { Field field = game.LastTrashedField; char c = ((string)opt[0])[0]; field.Color = Color.Get(c); } else if (this.power == 7) { Field field = game.Fields[Int32.Parse(opt[1])]; if (field.IsFixed) { throw GameException.getCardAlreadyFixedException(); } string cardStr = (string)opt[0]; CardDeck fieldDeck = field.CardList[(game.Turn + 1) % 2]; fieldDeck.Move(cardStr, game.Talon.Trash); } else if (this.power == 9) { game.Card9[(game.Turn + 1) % 2] = Constants.CARD9_AFFECTED; } return(ret); }
/// <summary> /// Move all card to the deck. /// </summary> /// <param name="to">Target deck.</param> public void MoveAll(CardDeck to) { if (to.size >= 0 && to.list.Count() > to.size - this.list.Count) { throw GameException.getCardTooManyException(); } List <string> list = new List <string>(); foreach (Card card in this.list) { list.Add(card.Name); } foreach (string name in list) { this.Move(name, to); } }
/// <summary> /// Move the specified card to the another deck. /// </summary> /// <param name="cardStr">card string.</param> /// <param name="to">Target deck.</param> /// <returns>Card instance.</returns> public Card Move(string cardStr, CardDeck to) { if (to.size >= 0 && to.list.Count() == to.size) { throw GameException.getCardTooManyException(); } Card card = this.Get(cardStr); if (card == null) { throw GameException.getNoCardException(); } if (!this.list.Remove(card)) { throw new Exception(); } CardDeck.handler(this, to, card); to.list.Add(card); return(card); }
/// <summary> /// Discard the card to the field. /// </summary> /// <param name="fieldIndex">Field index.</param> /// <param name="cardStr">Card string.</param> /// <returns>Discarded card instance.</returns> public Card Discard(int fieldIndex, string cardStr) { GameStatus.Status nextStatus = status.Act(GameStatus.Action.Discard); if (GameStatus.Status.Error == nextStatus) { throw GameException.getAlreadyDiscardedException(); } if (fieldIndex >= FIELD_NUM || fieldIndex < 0) { throw GameException.getFieldIndexException(); } CardDeck hand = this.players[turn].Hand; Card card = hand.Get(cardStr); if (card == null) { throw GameException.getCardNotFoundException(cardStr); } hand.Move(cardStr, this.fields[fieldIndex].CardList[turn]); if (this.players[turn].Hand.Count() == 0 || this.IsFilled) { status.Current = GameStatus.Status.End; } else if (this.card9[turn] == Constants.CARD9_AFFECTED) { status.Current = GameStatus.Status.Trashed; } else { status.Current = nextStatus; } return(card); }
public void CmdError(LilyAcolasia.GameRound round, LilyAcolasia.GameException ex) { IsCmdSuccess = false; Debug.Log("Error: " + ErrorMessages[ex.Type]); this.master.UpdateStatus(); }