public bool NonTargeCasttSpell(int gamePlayerID, int spellCardRecordID) { if (CurrentGamePlayerID != gamePlayerID) { return(false); } CardRecord spellCardRecord; if (!GameCardManager.FindCard(spellCardRecordID, out spellCardRecord) || !(spellCardRecord is SpellCardRecord)) { return(false); } if (spellCardRecord.Effectors(GameCardManager).Any(x => x is TargetEffector || x is MinionTargetEffector)) { return(false); } GamePlayer gamePlayer = (gamePlayerID == 1) ? GamePlayer1 : GamePlayer2; if (CanUseCard(gamePlayer, spellCardRecord)) { UseCard(gamePlayer, spellCardRecord); foreach (var effector in spellCardRecord.Effectors(GameCardManager)) { if (effector is AutoExecutetEffector) { (effector as AutoExecutetEffector).Affect(gamePlayer); } } return(true); } else { return(false); } }
public void LoadCardTestMethod2() { GameCardManager gameCardManager = new GameCardManager(); gameCardManager.LoadCard(new SpellCardRecord(1, 15)); gameCardManager.LoadCard(new SpellCardRecord(1, 15)); }
public bool HeroAttack(int gamePlayerID, int targetID, bool isTargetServant) { if (CurrentGamePlayerID != gamePlayerID) { return(false); } GamePlayer gamePlayer = (gamePlayerID == 1) ? GamePlayer1 : GamePlayer2; if (isTargetServant) { CardRecord targetCardRecord; if (GameCardManager.FindCard(targetID, out targetCardRecord) && targetCardRecord is ServantCardRecord) { return(gamePlayer.Hero.AttackServant(targetCardRecord as ServantCardRecord, gamePlayer)); } else { return(false); } } else { if (targetID != 1 && targetID != 2 || targetID == CurrentGamePlayerID) { return(false); } else { Hero hero = (targetID == 1) ? GamePlayer1.Hero : GamePlayer2.Hero; return(gamePlayer.Hero.AttackHero(hero, gamePlayer)); } } }
public void SerializationTestMethod1() { GameCardManager gameCardManager = new GameCardManager(); GamePlayer gamePlayer = new GamePlayer(null, new Hero(1, 25, 30), new GameDeck(1, CardManager.Instance.Cards.Select(x => gameCardManager.CreateCardRecord(x).CardRecordID).ToList())); byte[] serializedData = SerializationHelper.Serialize(gamePlayer); GamePlayer deserializedGamePlayer = SerializationHelper.Deserialize <GamePlayer>(serializedData); Assert.IsNotNull(deserializedGamePlayer); Hero hero = deserializedGamePlayer.Hero; Assert.IsNotNull(hero); Assert.AreEqual(1, hero.HeroID); Assert.AreEqual(25, hero.RemainedHP); Assert.AreEqual(30, hero.HP); deserializedGamePlayer.ChangeHand(new int[0]); Assert.AreEqual(true, deserializedGamePlayer.HasChangedHand); GameDeck deck = deserializedGamePlayer.Deck; Assert.IsNotNull(deck); Assert.AreEqual(CardManager.Instance.Cards.Count(), deck.CardRecordIDs.Count()); foreach (var cardRecordID in deck.CardRecordIDs) { CardRecord record; Assert.IsTrue(gameCardManager.FindCard(cardRecordID, out record)); Card settingCard; Assert.IsTrue(CardManager.Instance.FindCard(record.Card.CardID, out settingCard)); Assert.AreEqual(settingCard.CardID, record.Card.CardID); Assert.AreEqual(settingCard.CardName, record.Card.CardName); } }
private void Hero_OnWeaponChanged(Hero hero, DataChangeCode changeCode) { if (changeCode == DataChangeCode.Remove) { CardRecord record; if (GameCardManager.FindCard(hero.WeaponCardRecordID, out record) && record is WeaponCardRecord) { (record as WeaponCardRecord).Destroy(); } } }
public GameDeck CreateGameDeck(int gameDeckID, Deck deck) { List <int> cardRecordIDs = new List <int>(); foreach (Card card in deck.Cards) { cardRecordIDs.Add(GameCardManager.CreateCardRecord(card).CardRecordID); } GameDeck gameDeck = new GameDeck(gameDeckID, cardRecordIDs); gameDeck.Shuffle(100); return(gameDeck); }
public Game(int gameID, GamePlayer gamePlayer1, GamePlayer gamePlayer2, int roundCount, int currentGamePlayerID, GameCardManager gameCardManager) { GameID = gameID; GamePlayer1 = gamePlayer1; GamePlayer2 = gamePlayer2; RoundCount = roundCount; CurrentGamePlayerID = currentGamePlayerID; Field1 = new Field(1); Field1.BindGame(this); Field2 = new Field(2); Field2.BindGame(this); GameCardManager = gameCardManager; EventManager = new GameEventManager(this); }
private void AssemblyFieldEvents(Field field) { field.OnCardChanged += (fieldCardRecord, changeCode) => { if (changeCode == DataChangeCode.Add) { CardRecord record; if (GameCardManager.FindCard(fieldCardRecord.CardRecordID, out record) && record is ServantCardRecord) { (record as ServantCardRecord).OnDestroyed += (servantCard) => { field.RemoveCard(fieldCardRecord.CardRecordID); }; } } }; }
public void EffectorsTestMethod1() { TestCardRecord test = new TestCardRecord(); GameCardManager manager = new GameCardManager(); Assert.IsTrue(test.Effectors(manager).Count() == 0, "Effectors count mismatch (should be 0): " + test.Effectors(manager).Count()); Assert.IsNotNull(manager.CreareEffector(new TestEffect(1))); test.AddEffector(1); Assert.IsTrue(test.Effectors(manager).Count() == 1, "Effectors count mismatch (should be 1): " + test.Effectors(manager).Count()); test.AddEffector(2); Assert.IsTrue(test.Effectors(manager).Count() == 1, "Effectors count mismatch (should be 1): " + test.Effectors(manager).Count()); Assert.IsNotNull(manager.CreareEffector(new TestEffect(2))); Assert.IsTrue(test.Effectors(manager).Count() == 2, "Effectors count mismatch (should be 2): " + test.Effectors(manager).Count()); }
public bool NonTargetDisplayServant(int gamePlayerID, int servantCardRecordID, int positionIndex) { if (CurrentGamePlayerID != gamePlayerID) { return(false); } Field field = (gamePlayerID == 1) ? Field1 : Field2; if (!field.DisplayCheck(positionIndex)) { return(false); } CardRecord servantCardRecord; if (!GameCardManager.FindCard(servantCardRecordID, out servantCardRecord) || !(servantCardRecord is ServantCardRecord)) { return(false); } if (servantCardRecord.Effectors(GameCardManager).Any(x => x is TargetEffector || x is MinionTargetEffector)) { return(false); } GamePlayer gamePlayer = (gamePlayerID == 1) ? GamePlayer1 : GamePlayer2; if (CanUseCard(gamePlayer, servantCardRecord)) { UseCard(gamePlayer, servantCardRecord); foreach (var effector in servantCardRecord.Effectors(GameCardManager)) { if (effector is AutoExecutetEffector) { (effector as AutoExecutetEffector).Affect(gamePlayer); } } (servantCardRecord as ServantCardRecord).IsDisplayInThisTurn = true; field.AddCard(servantCardRecordID, positionIndex); return(true); } else { return(false); } }
internal override bool Handle(PlayerEventCode eventCode, Dictionary <byte, object> parameters, out string errorMessage) { if (base.Handle(eventCode, parameters, out errorMessage)) { int gameID = (int)parameters[(byte)GameStartParameterCode.GameID]; int player1ID = (int)parameters[(byte)GameStartParameterCode.Player1ID]; string player1Nickname = (string)parameters[(byte)GameStartParameterCode.Player1Nickname]; Library.GamePlayer gamePlayer1 = SerializationHelper.Deserialize <Library.GamePlayer>((byte[])parameters[(byte)GameStartParameterCode.GamePlayer1DataByteArray]); int player2ID = (int)parameters[(byte)GameStartParameterCode.Player2ID]; string player2Nickname = (string)parameters[(byte)GameStartParameterCode.Player2Nickname]; Library.GamePlayer gamePlayer2 = SerializationHelper.Deserialize <Library.GamePlayer>((byte[])parameters[(byte)GameStartParameterCode.GamePlayer2DataByteArray]); int roundCount = (int)parameters[(byte)GameStartParameterCode.RoundCount]; int currentGamePlayerID = (int)parameters[(byte)GameStartParameterCode.CurrentGamePlayerID]; GameCardManager gameCardManager = SerializationHelper.Deserialize <GameCardManager>((byte[])parameters[(byte)GameStartParameterCode.GameCardManagerByteArray]); gamePlayer1.Player = new Library.Player(player1ID, player1Nickname); gamePlayer2.Player = new Library.Player(player2ID, player2Nickname); Library.Game game = new Library.Game ( gameID: gameID, gamePlayer1: gamePlayer1, gamePlayer2: gamePlayer2, roundCount: roundCount, currentGamePlayerID: currentGamePlayerID, gameCardManager: gameCardManager ); GameManager.Instance.AddGame(game); gamePlayer1.BindGame(game); gamePlayer2.BindGame(game); gameCardManager.BindGame(game); return(true); } else { return(false); } }
public void LoadCardTestMethod1() { GameCardManager gameCardManager = new GameCardManager(); int addCounter = 0, updateCounter = 0; gameCardManager.OnCardChanged += (eventCardRecord, changeCode) => { if (changeCode == Protocol.DataChangeCode.Add) { addCounter++; } else if (changeCode == Protocol.DataChangeCode.Update) { updateCounter++; } }; gameCardManager.LoadCard(new SpellCardRecord(1, 15)); Assert.AreEqual(1, addCounter); Assert.AreEqual(0, updateCounter); gameCardManager.LoadCard(new SpellCardRecord(1, 15)); Assert.AreEqual(1, addCounter); Assert.AreEqual(1, updateCounter); }
public Game(int gameID, Player player1, Player player2, Deck player1Deck, Deck player2Deck) { GameCardManager = new GameCardManager(); GameCardManager.BindGame(this); GameID = gameID; GamePlayer1 = new GamePlayer(player1, new Hero(1, 30, 30), CreateGameDeck(1, player1Deck)); GamePlayer1.BindGame(this); GamePlayer2 = new GamePlayer(player2, new Hero(2, 30, 30), CreateGameDeck(2, player2Deck)); GamePlayer2.BindGame(this); RoundCount = 0; Random randomGenerator = new Random(); if (randomGenerator.NextDouble() > 0.5) { CurrentGamePlayerID = 1; GamePlayer1.Draw(3); GamePlayer2.Draw(4); } else { CurrentGamePlayerID = 2; GamePlayer1.Draw(4); GamePlayer2.Draw(3); } Field1 = new Field(1); Field1.BindGame(this); Field2 = new Field(2); Field2.BindGame(this); AssemblyGamePlayerEvents(GamePlayer1); AssemblyGamePlayerEvents(GamePlayer2); AssemblyFieldEvents(Field1); AssemblyFieldEvents(Field2); EventManager = new GameEventManager(this); }
//public bool TargetEquipWeapon(int gamePlayerID, int weaponCardRecordID, int targetID, bool isTargetServant) //{ // if (CurrentGamePlayerID != gamePlayerID) // return false; // CardRecord weaponCardRecord; // if (!GameCardManager.FindCard(weaponCardRecordID, out weaponCardRecord) || !(weaponCardRecord is WeaponCardRecord)) // return false; // if (!weaponCardRecord.Effectors(GameCardManager).Any(x => x is TargetEffector || x is MinionTargetEffector)) // return false; // GamePlayer gamePlayer = (gamePlayerID == 1) ? GamePlayer1 : GamePlayer2; // if (CanUseCard(gamePlayer, weaponCardRecord)) // { // if (isTargetServant) // { // CardRecord targetCardRecord; // if (GameCardManager.FindCard(targetID, out targetCardRecord) && targetCardRecord is ServantCardRecord) // { // UseCard(gamePlayer, weaponCardRecord); // foreach (var effector in weaponCardRecord.Effectors(GameCardManager)) // { // if (effector is TargetEffector) // { // (effector as TargetEffector).AffectServant(targetCardRecord as ServantCardRecord, gamePlayer); // } // else if (effector is MinionTargetEffector) // { // (effector as MinionTargetEffector).AffectServant(targetCardRecord as ServantCardRecord, gamePlayer); // } // else if (effector is AutoExecutetEffector) // { // (effector as AutoExecutetEffector).Affect(gamePlayer); // } // } // } // else // { // return false; // } // } // else // { // if (targetID != 1 && targetID != 2) // return false; // else // { // UseCard(gamePlayer, weaponCardRecord); // Hero hero = (targetID == 1) ? GamePlayer1.Hero : GamePlayer2.Hero; // foreach (var effector in weaponCardRecord.Effectors(GameCardManager)) // { // if (effector is TargetEffector) // { // (effector as TargetEffector).AffectHero(hero, gamePlayer); // } // else if (effector is AutoExecutetEffector) // { // (effector as AutoExecutetEffector).Affect(gamePlayer); // } // } // } // } // gamePlayer.Hero.WeaponCardRecordID = weaponCardRecordID; // return true; // } // else // { // return false; // } //} public bool NonTargetEquipWeapon(int gamePlayerID, int weaponCardRecordID) { if (CurrentGamePlayerID != gamePlayerID) { return(false); } CardRecord weaponCardRecord; if (!GameCardManager.FindCard(weaponCardRecordID, out weaponCardRecord) || !(weaponCardRecord is WeaponCardRecord)) { return(false); } if (weaponCardRecord.Effectors(GameCardManager).Any(x => x is TargetEffector || x is MinionTargetEffector)) { return(false); } GamePlayer gamePlayer = (gamePlayerID == 1) ? GamePlayer1 : GamePlayer2; if (CanUseCard(gamePlayer, weaponCardRecord)) { UseCard(gamePlayer, weaponCardRecord); foreach (var effector in weaponCardRecord.Effectors(GameCardManager)) { if (effector is AutoExecutetEffector) { (effector as AutoExecutetEffector).Affect(gamePlayer); } } gamePlayer.Hero.WeaponCardRecordID = weaponCardRecordID; return(true); } else { return(false); } }
public bool TargetDisplayServant(int gamePlayerID, int servantCardRecordID, int positionIndex, int targetID, bool isTargetServant) { if (CurrentGamePlayerID != gamePlayerID) { return(false); } Field field = (gamePlayerID == 1) ? Field1 : Field2; if (!field.DisplayCheck(positionIndex)) { return(false); } CardRecord servantCardRecord; if (!GameCardManager.FindCard(servantCardRecordID, out servantCardRecord) || !(servantCardRecord is ServantCardRecord)) { return(false); } if (!servantCardRecord.Effectors(GameCardManager).Any(x => x is TargetEffector || (isTargetServant && x is MinionTargetEffector))) { return(false); } GamePlayer gamePlayer = (gamePlayerID == 1) ? GamePlayer1 : GamePlayer2; if (CanUseCard(gamePlayer, servantCardRecord)) { if (isTargetServant) { CardRecord targetCardRecord; if (GameCardManager.FindCard(targetID, out targetCardRecord) && targetCardRecord is ServantCardRecord) { UseCard(gamePlayer, servantCardRecord); foreach (var effector in servantCardRecord.Effectors(GameCardManager)) { if (effector is TargetEffector) { (effector as TargetEffector).AffectServant(targetCardRecord as ServantCardRecord, gamePlayer); } else if (effector is MinionTargetEffector) { (effector as MinionTargetEffector).AffectServant(targetCardRecord as ServantCardRecord, gamePlayer); } else if (effector is AutoExecutetEffector) { (effector as AutoExecutetEffector).Affect(gamePlayer); } } } else { return(false); } } else { if (targetID != 1 && targetID != 2) { return(false); } else { UseCard(gamePlayer, servantCardRecord); Hero hero = (targetID == 1) ? GamePlayer1.Hero : GamePlayer2.Hero; foreach (var effector in servantCardRecord.Effectors(GameCardManager)) { if (effector is TargetEffector) { (effector as TargetEffector).AffectHero(hero, gamePlayer); } else if (effector is AutoExecutetEffector) { (effector as AutoExecutetEffector).Affect(gamePlayer); } } } } (servantCardRecord as ServantCardRecord).IsDisplayInThisTurn = true; field.AddCard(servantCardRecordID, positionIndex); return(true); } else { return(false); } }
public void IncreaseCoverageTestMethod2() { GameCardManager gameCardManager = new GameCardManager(); Assert.IsNull(gameCardManager.CreareEffector(new TestEffect(1))); }
public void IncreaseCoverageTestMethod1() { GameCardManager gameCardManager = new GameCardManager(); Assert.IsNull(gameCardManager.CreateCardRecord(new TestCard())); }
public bool TargetCastSpell(int gamePlayerID, int spellCardRecordID, int targetID, bool isTargetServant) { if (CurrentGamePlayerID != gamePlayerID) { return(false); } CardRecord spellCardRecord; if (!GameCardManager.FindCard(spellCardRecordID, out spellCardRecord) || !(spellCardRecord is SpellCardRecord)) { return(false); } if (!spellCardRecord.Effectors(GameCardManager).Any(x => x is TargetEffector || (isTargetServant && x is MinionTargetEffector))) { return(false); } GamePlayer gamePlayer = (gamePlayerID == 1) ? GamePlayer1 : GamePlayer2; if (CanUseCard(gamePlayer, spellCardRecord)) { if (isTargetServant) { CardRecord targetCardRecord; if (GameCardManager.FindCard(targetID, out targetCardRecord) && targetCardRecord is ServantCardRecord) { UseCard(gamePlayer, spellCardRecord); foreach (var effector in spellCardRecord.Effectors(GameCardManager)) { if (effector is TargetEffector) { (effector as TargetEffector).AffectServant(targetCardRecord as ServantCardRecord, gamePlayer); } else if (effector is MinionTargetEffector) { (effector as MinionTargetEffector).AffectServant(targetCardRecord as ServantCardRecord, gamePlayer); } else if (effector is AutoExecutetEffector) { (effector as AutoExecutetEffector).Affect(gamePlayer); } } } else { return(false); } } else { if (targetID != 1 && targetID != 2) { return(false); } else { UseCard(gamePlayer, spellCardRecord); Hero hero = (targetID == 1) ? GamePlayer1.Hero : GamePlayer2.Hero; foreach (var effector in spellCardRecord.Effectors(GameCardManager)) { if (effector is TargetEffector) { (effector as TargetEffector).AffectHero(hero, gamePlayer); } else if (effector is AutoExecutetEffector) { (effector as AutoExecutetEffector).Affect(gamePlayer); } } } } return(true); } else { return(false); } }