void UpdatePlayed() { if (selfIdx != -1 && opponentIdx != -1) { roundInfo = ""; int selfID = selfState.hand[selfIdx]; int opponentID = opponentState.hand[opponentIdx]; Card selfCard = CardDatabase.GetCard(selfID); Card opponentCard = CardDatabase.GetCard(opponentID); var result = Card.Compare(selfCard.type, opponentCard.type); roundInfo += "Played " + selfCard.Name() + "\n"; roundInfo += "Opponent played " + opponentCard.Name() + "\n"; roundInfo += "Round " + result; if (result == CardResult.Win) { selfCard.Win(selfState, opponentState); opponentCard.Lose(opponentState, selfState); } else if (result == CardResult.Lose) { selfCard.Lose(selfState, opponentState); opponentCard.Win(opponentState, selfState); } else if (result == CardResult.Tie) { selfCard.Tie(selfState, opponentState); opponentCard.Tie(opponentState, selfState); } selfState.hand.RemoveAt(selfIdx); selfState.Draw(); opponentState.hand.RemoveAt(opponentIdx); opponentState.Draw(); newRound(); } }
public void OnEvent(EventData photonEvent) { if (photonEvent.Code == EventCode.kSyncInitCards) { var player = PhotonNetwork.CurrentRoom.GetPlayer(photonEvent.Sender); if (player == self) { Debug.LogError("Receiving command not sent to self."); return; } object[] data = (object[])photonEvent.CustomData; opponentState = new RPSPlayerState(); for (int i = 0; i < opponentState.deck.Count; ++i) { opponentState.deck[i] = (int)data[i]; } for (int i = 0; i < RPSPlayerState.kDefaultHandSize; ++i) { selfState.Draw(); } for (int i = 0; i < RPSPlayerState.kDefaultHandSize; ++i) { opponentState.Draw(); } } if (photonEvent.Code == EventCode.kPlayedCard) { var player = PhotonNetwork.CurrentRoom.GetPlayer(photonEvent.Sender); object[] data = (object[])photonEvent.CustomData; int idx = (int)data[0]; if (player == self) { selfIdx = idx; int selfID = selfState.hand[selfIdx]; } else if (player == opponent) { opponentIdx = idx; int opponentId = opponentState.hand[opponentIdx]; } else { Debug.LogError("Unknown player event raised in room"); return; } UpdatePlayed(); } }