public IEnumerator ShareCard(DeckTag deck, int cardNum, float shareDelay) { WaitForSeconds delay = new WaitForSeconds(shareDelay); int tempTurn = TurnSystem.GetInstance().GetNowTurnPlayerIndex(); if (tempTurn < 0) { tempTurn = 0; } for (int i = 0; i < Players.Count; i++) { for (int j = 0; j < cardNum; j++) { Card card = DeckSystem.GetInstance().GetTopCardWithDeck(deck); if (tempTurn + i >= Players.Count) { tempTurn -= Players.Count; } Players[tempTurn + i].AddPlayerCard(card); yield return(delay); } } }
public void SetupOneCardAi() { IsStartAi.Subscribe(value => { if (value) { Debug.Log("ai start"); var cardIndex = 0; var playerId = TurnSystem.GetInstance().PlayerNowTurn.Value; var isPut = PlayerSystem.GetInstance().GetPlayerIsPutCard(playerId); Observable.Interval(TimeSpan.FromSeconds(0.5f)) .TakeWhile(_ => RandomCard(playerId, ref cardIndex) >= 0) .Subscribe(i => { var card = PlayerSystem.GetInstance().GetPlayerCard(playerId, cardIndex); PlayerSystem.GetInstance().PlayerPutCard(DeckTag.PUT_DECK, playerId, cardIndex, true); RuleSystem.GetInstance().CheckSpecialCard(card, isPut); }, () => { IsStartAi.Value = false; TurnSystem.GetInstance().EndTurn(); }); } }); }
private void ServerPacketParse(int length) { string msg = Encoding.UTF8.GetString(buffer, 2, length - 2); string[] text = msg.Split(':'); if (text[0].Equals("CONNECT")) { UnityEngine.Debug.Log("connect"); } else if (text[0].Equals("GUEST-ID")) { UnityEngine.Debug.Log("guest-login : "******"Guest" + text[1]; } else if (text[0].Equals("GAMESTART")) { for (int i = 0; i < text.Length - 1; i++) { if (PlayerSystem.GetInstance().MyPlayerId.Equals(text[i + 1])) { for (int j = 0; j < text.Length - 1; j++) { if (i + 1 >= text.Length) { i -= (text.Length - 1); } PlayerSystem.GetInstance().AddPlayer(PlayerTag.PLAYER_BOTTOM + j, text[1 + i], false); TurnSystem.GetInstance().AddTurnPlayer(text[1 + i]); i++; } break; } } TurnSystem.GetInstance().SetFirstTurn(text[1]); StartCoroutine(SceneSystem.GetInstance().NowScene.NextSceneAnimation()); } else if (text[0].Equals("ADD-CARD")) { int cardNum = Convert.ToInt32(text[2]); PlayerSystem.GetInstance().PlayerAddCardWithDeck(DeckTag.DRAW_DECK, text[1], cardNum); } else if (text[0].Equals("PUT-CARD")) { int playerCardIndex = Convert.ToInt32(text[2]); //PlayerSystem.GetInstance().PlayerPutCard(DeckTag.PUT_DECK,text[1],playerCardIndex, 0.5f); } else if (text[0].Equals("NEXT-TURN")) { TurnSystem.GetInstance().NextTurn(); } else if (text[0].Equals("GET-RANDOMSEED")) { int seed = Convert.ToInt32(text[1]); UnityEngine.Random.InitState(seed); } }
public void NextTurn(int playerIdx, int damage) { if (damage != 0) { PlayerSystem.GetInstance().PlayerAddCardWithDeck(DeckTag.DRAW_DECK, playerIdx, damage); EndAttackTurn(); } TurnSystem.GetInstance().NextTurn(); PlayerSystem.GetInstance().Players[playerIdx].IsPutCard = false; }
public void TurnEndBtnPress() { var nowId = TurnSystem.GetInstance().PlayerNowTurn.Value; if (nowId == PlayerSystem.GetInstance().MyPlayerId) { Button btn = TurnEndBtnObject.GetComponent <Button>(); btn.interactable = false; TurnSystem.GetInstance().EndTurn(); } }
/// <summary>플레이어 카드가 0장이 되었을 때 체크 </summary> /// <returns>0장이라면 true 아니라면 false</returns> public bool CheckWinPlayer() { var nowTurn = TurnSystem.GetInstance().GetNowTurnPlayerIndex(); var count = PlayerSystem.GetInstance().GetPlayerCardCount(nowTurn); var id = PlayerSystem.GetInstance().GetPlayerId(nowTurn); if (count <= 0) { TurnSystem.GetInstance().NextTurn(); PlayerSystem.GetInstance().RemovePlayer(id); TurnSystem.GetInstance().RemoveTurnPlayer(id); return(true); } return(false); }
public IEnumerator Test() { yield return(new WaitForSeconds(2)); PlayerSystem.GetInstance().AddPlayer(PlayerTag.PLAYER_BOTTOM, "test", false); TurnSystem.GetInstance().SetFirstTurn("test"); yield return(new WaitForSeconds(2)); DeckSystem.GetInstance().AllMoveCardDecktoDeck( DeckTag.ANIMATION_RIGHT_DECK, DeckTag.DRAW_DECK, 3, 0.05F, 3); }
public IEnumerator StartGame() { StartCoroutine(PlayerSystem.GetInstance().ShareCard(DeckTag.DRAW_DECK, 12, 0.1f)); yield return(new WaitForSeconds(PlayerSystem.GetInstance().Players.Count * 1)); DeckSystem.GetInstance().MoveCardDecktoDeck(DeckTag.DRAW_DECK, DeckTag.PUT_DECK, 1, 1, 0, 0.5f); yield return(new WaitForSeconds(1)); PlayerSystem.GetInstance().PlayerCardReverse(PlayerSystem.GetInstance().GetMyPlayerIndex(), 0.5f); yield return(new WaitForSeconds(1)); IsStartGame = true; TurnSystem.GetInstance().SetFirstTurn("1"); TurnSystem.GetInstance().StartTurn(); }
/// <summary>deck1의 카드가 부족할 때 deck2의 카드로 채우고 섞음 </summary> /// <param name="deck1"></param> /// <param name="deck2"></param> public void FillDecktoDeckofAttack(DeckTag deck1, DeckTag deck2) { var nowTurn = TurnSystem.GetInstance().GetNowTurnPlayerIndex(); var isPut = PlayerSystem.GetInstance().Players[nowTurn].IsPutCard; var damage = RuleSystem.GetInstance().GetAttackDamage(isPut); var deck2Count = DeckSystem.GetInstance().GetCardCountWithDeck(deck2); Action addCardAction = () => { DeckSystem.GetInstance().ShuffleDeck(DeckTag.DRAW_DECK, 1000); NextTurn(nowTurn, damage); }; if (damage > deck2Count) { var count = DeckSystem.GetInstance().GetCardCountWithDeck(deck1); if (count + deck2Count <= damage) { return; } Debug.Log("move put -> draw : " + count); DeckSystem.GetInstance().MoveCardDecktoDeck( deck1, deck2, 0, 0, count - 1, 0, 0.2f, addCardAction); } else { NextTurn(nowTurn, damage); } }
/// <summary>플레이어 카드가 룰의 Max 카드를 넘었을 때 </summary> /// <returns>플레이어가 패배했다면 true, 아니라면 false</returns> public bool CheckDefeatPlayer() { var nowTurn = TurnSystem.GetInstance().GetNowTurnPlayerIndex(); var isPut = PlayerSystem.GetInstance().Players[nowTurn].IsPutCard; var damage = RuleSystem.GetInstance().GetAttackDamage(isPut); var playerCardCount = PlayerSystem.GetInstance().GetPlayerCardCount(nowTurn); var playerId = PlayerSystem.GetInstance().GetPlayerId(nowTurn); var isReverse = PlayerSystem.GetInstance().MyPlayerId == playerId ? true : false; if (damage + playerCardCount > RuleSystem.GetInstance().PlayerMaxCard) { PlayerSystem.GetInstance().PlayerCardMoveDeck(DeckTag.DRAW_DECK, nowTurn, isReverse, 0.1f); DeckSystem.GetInstance().ShuffleDeck(DeckTag.DRAW_DECK, 1000); TurnSystem.GetInstance().NextTurn(); PlayerSystem.GetInstance().RemovePlayer(playerId); TurnSystem.GetInstance().RemoveTurnPlayer(playerId); EndAttackTurn(); return(true); } return(false); }
public void CheckSpecialCard(CardTag card, bool isPutCard) { if (card == CardTag.Q) { TurnSystem.GetInstance().ReverseTurn(); } else if (card == CardTag.J) { var jump = isPutCard ? 2 : 1; TurnSystem.GetInstance().JumpTurn(jump); if (TurnSystem.GetInstance().PlayerTurn.Peek() == TurnSystem.GetInstance().PlayerNowTurn.Value) { var playerId = TurnSystem.GetInstance().PlayerNowTurn.Value; PlayerSystem.GetInstance().GetPlayer(playerId).IsPutCard = false; } } else if (card == CardTag.K) { var playerId = TurnSystem.GetInstance().PlayerNowTurn.Value; PlayerSystem.GetInstance().GetPlayer(playerId).IsPutCard = false; } }
void Start() { GameManager.GetInstance().FadeOutWhiteImg(0.5f); CardSystem.GetInstance().AddAllCard(); CardSystem.GetInstance().SetCardActive(true); CardSystem.GetInstance().AllCardMoveDeck(DeckSystem.GetInstance().GetDeck(DeckTag.ANIMATION_RIGHT_DECK)); AiSystem.GetInstance().SetupOneCardAi(); if (PlayerSystem.GetInstance().Players.Count <= 0) { PlayerSystem.GetInstance().MyPlayerId = "1"; PlayerSystem.GetInstance().AddPlayer(PlayerTag.PLAYER_BOTTOM, "1", false); PlayerSystem.GetInstance().AddPlayer(PlayerTag.PLAYER_LEFT_DOWN, "3", true); PlayerSystem.GetInstance().AddPlayer(PlayerTag.PLAYER_TOP, "2", true); PlayerSystem.GetInstance().AddPlayer(PlayerTag.PLAYER_RIGHT_UP, "4", true); TurnSystem.GetInstance().AddTurnPlayer("1"); TurnSystem.GetInstance().AddTurnPlayer("2"); TurnSystem.GetInstance().AddTurnPlayer("3"); TurnSystem.GetInstance().AddTurnPlayer("4"); //NetworkSystem.GetInstance().SendServer("FIND-ROOM:" + "1"); } StartCoroutine(StartScene()); this.UpdateAsObservable() .Subscribe(_ => { if (!GameManager.GetInstance().IsStartGame) { return; } var nowId = TurnSystem.GetInstance().PlayerNowTurn.Value; if (nowId == PlayerSystem.GetInstance().MyPlayerId) { InputSystem.GetInstance().TouchUpdate(); } }); TurnSystem.GetInstance().PlayerNowTurn.Subscribe(name => { if (name == "") { return; } if (PlayerSystem.GetInstance().GetPlayer(name).IsAi) { AiSystem.GetInstance().IsStartAi.Value = true; } if (name == PlayerSystem.GetInstance().MyPlayerId) { OnTurnEndBtn(); } }); TurnSystem.GetInstance().IsFinishTurn.Subscribe(finish => { if (!GameManager.GetInstance().IsStartGame) { return; } if (finish) { Observable.Timer(TimeSpan.FromSeconds(1)) .Subscribe(_ => { if (GameManager.GetInstance().CheckDefeatPlayer()) { return; } if (GameManager.GetInstance().CheckWinPlayer()) { return; } GameManager.GetInstance().FillDecktoDeckofAttack(DeckTag.PUT_DECK, DeckTag.DRAW_DECK); }); } }); }