public void LoadAllJsonFromPP() { ReadBible("kor_bible_json"); _MD = new MainData(); _VD = new VerseData(); _OD = new OverlapData(); _CL = new CardList(); _CLC = new CardListPerChapter(); _LD = new LevelData(); if (!PlayerPrefs.HasKey("MainData")) { InitAllJsonToPP(); } _mainJson = PlayerPrefs.GetString("MainData"); _verseJson = PlayerPrefs.GetString("VerseData"); _overlapJson = PlayerPrefs.GetString("OverlapData"); _cardJson = PlayerPrefs.GetString("CardData"); _levelJson = PlayerPrefs.GetString("LevelData"); _CLC.allVerseJsonPerChapter = new Dictionary <string, string>(); _CL.verseList = Enumerable.Repeat <List <BibleCard> >(null, 1189).ToArray(); _OD.verseCodeAndOverlapCount = new Dictionary <int, int>(); _OD.verseCodeAndBestRank = new Dictionary <int, int>(); for (int i = 0; i < 1189; i++) { _verseJsonListPerCht[i] = JsonHelper.FromJson <string>(_cardJson)[i]; var a = JsonUtility.FromJson <Serialization <string, string> >(_verseJsonListPerCht[i]).ToDictionary(); _CLC.allVerseJsonPerChapter.Add(a.Keys.ElementAt(0), a.Values.ElementAt(0)); _CL.verseList[i] = JsonUtility.FromJson <Serialization <BibleCard> >(_CLC.allVerseJsonPerChapter["cht" + (i + 1)]).ToList(); } //Debug.Log(JsonHelper.FromJson<string>(_overlapJson)[1]); _OD.verseCodeAndOverlapCount = JsonUtility.FromJson <Serialization <int, int> > (JsonHelper.FromJson <string>(_overlapJson)[0]).ToDictionary(); _OD.verseCodeAndBestRank = JsonUtility.FromJson <Serialization <int, int> >(JsonHelper.FromJson <string>(_overlapJson)[1]).ToDictionary(); }
void CheckOverlap(int playerId, int pieceId, int moves, System.Action <OverlapData> result) { // Check if any pieces have the same position and // if the the other player is NOT on a rosette tile within the neutral zone // If so, restart the other player // If the other player IS on a rossette tile within the neutral zone, // move the advancing player one tile back from the player on the rosette tile OverlapData overlapData = IsOverlapping(playerId, pieceId, moves); result(overlapData); if (overlapData.IsOverlaping) { int positionOfOverlap = overlapData.AtPosition; print("positionOfOverlap = " + positionOfOverlap); if (playerId == 0) { if (!overlapData.SelfOverlap) { // Conflict at the rosette tile if (positionOfOverlap == 7) { // If opponent piece on rosette if (FindIdByPosition(1, 7) != -1) { // If opponent on tile behind rosette as well, // remove that piece and put this piece there if (FindIdByPosition(1, 6) != -1) { player2Positions[FindIdByPosition(1, 6)].position = -1; } player1Positions[pieceId].position = 6; } else { player2Positions[FindIdByPosition(1, positionOfOverlap)].position = -1; player1Positions[pieceId].position = positionOfOverlap; } } else { int opponentId = FindIdByPosition(1, positionOfOverlap); // If there is an opponent piece on positionOfOverlap if (opponentId != -1) { player2Positions[opponentId].position = -1; player1Positions[pieceId].position = positionOfOverlap; } } } } else { if (!overlapData.SelfOverlap) { // Conflict at the rosette tile if (positionOfOverlap == 7) { // If opponent piece at rosette if (FindIdByPosition(0, 7) != -1) { // If opponent on tile behind rosette as well, // remove that piece and put this piece there if (FindIdByPosition(0, 6) != -1) { player1Positions[FindIdByPosition(0, 6)].position = -1; } player2Positions[pieceId].position = 6; } else { player1Positions[FindIdByPosition(0, positionOfOverlap)].position = -1; player2Positions[pieceId].position = positionOfOverlap; } } else { int opponentId = FindIdByPosition(0, positionOfOverlap); // If there is an opponent piece on positionOfOverlap if (opponentId != -1) { player1Positions[opponentId].position = -1; player2Positions[pieceId].position = positionOfOverlap; } } } } // Update both players' positions for (int i = 0; i < player1Positions.Count; i++) { StartCoroutine(UpdatePosition(0, i)); StartCoroutine(UpdatePosition(1, i)); } } }
void AdvancePlayer(int playerId, int pieceId, int moves) { // Player 1 if (playerId == 0) { // If the player gets to score a point if ((player1Pathway.Count - player1Positions[pieceId].position) == moves) { ScorePoint(playerId, pieceId); } // Otherwise, the player is still somewhere on the board else if ((player1Pathway.Count - player1Positions[pieceId].position) > moves) { // Check for any possible overlap OverlapData overlapData = new OverlapData(); CheckOverlap(playerId, pieceId, moves, value => overlapData = value); if (overlapData != null) { //Debug.Log("self overlap = " + overlapData.SelfOverlap); if (overlapData.SelfOverlap) { print("Can't move that piece! Move a different piece."); return; } } player1Positions[pieceId].position += moves; if (player1Positions[pieceId].position >= player1Pathway.Count) { ScorePoint(playerId, pieceId); } bool onRosette = (player1Positions[pieceId].position == 3 || player1Positions[pieceId].position == 7 || player1Positions[pieceId].position == 13) && moves > 0; NextTurn(onRosette); } StartCoroutine(UpdatePosition(playerId, pieceId)); } // Player 2 else { // If the player gets to score a point if ((player2Pathway.Count - player2Positions[pieceId].position) == moves) { ScorePoint(playerId, pieceId); } // Otherwise, the player is still somewhere on the board else if ((player2Pathway.Count - player2Positions[pieceId].position) > moves) { // Check for any possible overlap OverlapData overlapData = null; CheckOverlap(playerId, pieceId, moves, value => overlapData = value); if (overlapData != null) { if (overlapData.SelfOverlap) { print("Can't move that piece! Move a different piece."); return; } } player2Positions[pieceId].position += moves; if (player2Positions[pieceId].position >= player2Pathway.Count) { ScorePoint(playerId, pieceId); } bool onRosette = (player2Positions[pieceId].position == 3 || player2Positions[pieceId].position == 7 || player2Positions[pieceId].position == 13) && moves > 0; NextTurn(onRosette); } StartCoroutine(UpdatePosition(playerId, pieceId)); } }