Beispiel #1
0
    private void GameEnd(bool win)
    {
        StopCoroutine("Timer");
        GameEndData gameEndData = new GameEndData();

        gameEndData.win        = win;
        gameEndData.finalScore = _receivedEnergy;
        gameEndData.needScore  = _needEnergyToCompleteLevel;
        gameEndData.playerDie  = false;

        if (win)
        {
            SaveSystem.SaveLevelStatucByID(GameEconomy.curentLevel.levelSaveLoadID, true);
        }
        else
        {
            //SaveSystem.SaveLevelStatucByID(GameEconomy.curentLevel.levelSaveLoadID, false);
        }

        GameEconomy.AddPlayerMoney(_receivedEnergy);
        if (GameEconomy.curentItem && GameEconomy.curentItem.itemName != "Empty")
        {
            GameEconomy.curentItem.bought = false;
        }

        SetPauseEnabled();
        GameEconomy.SaveEconomy();
        GameEnded(gameEndData);
    }
    public void SaveGameEndData()
    {
        GameEndData mData = new GameEndData();
        string      mJson = JsonConvert.SerializeObject(mData, Formatting.Indented);

        File.WriteAllText(Application.persistentDataPath + "/GameEndValue.json", mJson);
    }
Beispiel #3
0
    public void onGameEnd(GameEndData gameEndData)
    {
        if (gameEndData.won)
        {
            Debug.Log("won game");
            //increment game index
            //load the selected preset

            currentLevel = (currentLevel + 1) % levelList.levels.Count;


            savePlayerState();
            gB.resetGame(levelList.levels[currentLevel]);
        }
        else
        {
            currentTries = Mathf.Max(0, currentTries - 1);

            //game loss
            if (currentTries > 0)
            {
                --currentTries;
                Debug.Log("using tries remaining is " + currentTries);
                gB.resetGame(levelList.levels[currentLevel]);
            }
            else
            {
                Debug.Log("trying to show ads here");
                //show add here

                currentTries = 0;
                StartCoroutine(_blockGame());
            }
        }
    }
Beispiel #4
0
        public bool Serialize(GameEndData packet)
        {
            bool ret     = true;
            int  request = (int)packet.request;

            ret &= Serialize(request);
            return(ret);
        }
Beispiel #5
0
        public bool Deserialize(ref GameEndData element)
        {
            if (GetDataSize() == 0)
            {
                return(false);
            }
            bool ret     = true;
            int  request = 0;

            ret            &= Deserialize(ref request);
            element.request = (GamePacketId)request;
            return(ret);
        }
    public void OnReceiveGameEndPacket(PacketId id, byte[] data)
    {
        GameEndPacket packet     = new GameEndPacket(data);
        GameEndData   packetData = packet.GetPacket();

        //상대방이 게임을 종료했을 시 -> 게임 승리로 간주
        if (packetData.request == GamePacketId.OpponentEnd)
        {
            networkManager.transportTCP.Disconnect();
            MatchingManager.instance.MatchState = MatchingManager.MatchingState.Nothing;
            SceneManager.LoadScene("Lobby");
        }
    }
Beispiel #7
0
    public void SetConfiguration(GameEndData gameEndData)
    {
        gameObject.SetActive(true);
        finalScore.text = gameEndData.finalScore.ToString();
        needScore.text  = gameEndData.needScore.ToString(); if (gameEndData.needScore < 0)
        {
            needScore.text = "НЕ ВАЖНО";
        }

        GameObject.FindGameObjectWithTag("MainCamera").GetComponent <AudioSource>().enabled = false;

        if (gameEndData.win)
        {
            audioSource.PlayOneShot(winSound);
            status.text = "ВЫ ВЫИГРАЛИ!";
            nextLevelButton.SetActive(true);
        }
        else
        {
            audioSource.PlayOneShot(loseSound);
            status.text = "ВЫ ПРОИГРАЛИ!";
        }
    }
Beispiel #8
0
    public void OnGameEnd()
    {
        GameEndData mGameEndData = new GameEndData();

        mGameEndData.mGameEnded = false;
    }
Beispiel #9
0
    public void SavePauseButton()
    {
        GameEndData mGameEndData = new GameEndData();

        mGameEndData.mGameEnded = true;
    }
    /*private void SendAndCreateToServer()
     * {
     *  switch (sendOptions)
     *  {
     *      case SendOptions.AI_VS_AI:
     *          SendAI_VS_AI_Data();
     *          break;
     *
     *      case SendOptions.AckAI_VS_AI:
     *          SendAck();
     *          break;
     *
     *      case SendOptions.Ack:
     *          SendAck();
     *          break;
     *
     *      default:
     *          break;
     *  }
     * }*/

    private IEnumerator RecieveAndParseServerReply()
    {
        recievingInCorutine = true;

        while (!s.DataAvailable)
        {
            yield return(null);
        }

        string ServerReply = sr.ReadLine();

        Debug.Log("Recvd " + ServerReply);
        loggerText.text = "Recvd " + ServerReply + "\n";

        Dictionary <string, object> ServerReplyDict = JsonConvert.DeserializeObject <Dictionary <string, object> >(ServerReply);

        MsgsEnum ServerReplytype = (MsgsEnum)int.Parse(ServerReplyDict["type"].ToString());

        string serverMsg = ServerReplyDict["msg"].ToString();

        switch (ServerReplytype)
        {
        case MsgsEnum.AI_VS_AI:
            break;

        case MsgsEnum.AckAI_VS_AI:

            AckAI_VS_AI_Data ackAI_VS_AI = JsonConvert.DeserializeObject <AckAI_VS_AI_Data>(serverMsg);

            manager.SetMyTurn(ackAI_VS_AI.myTurn);

            if (ackAI_VS_AI.ourRemainingTime > 0)
            {
                manager.SetOurTimer(ackAI_VS_AI.ourRemainingTime / 1000.0f);
            }

            if (ackAI_VS_AI.theirRemainingTime > 0)
            {
                manager.SetTheirTimer(ackAI_VS_AI.theirRemainingTime / 1000.0f);
            }

            SendAck();

            break;

        case MsgsEnum.moveConfigrations:

            MoveData moveConfigData = JsonConvert.DeserializeObject <MoveData>(serverMsg);
            boardObject.PlaceStone(moveConfigData.y, moveConfigData.x, moveConfigData.color != 'b');

            if (moveConfigData.ourScore > 0 || moveConfigData.theirScore > 0)
            {
                manager.SetScore(moveConfigData.ourScore, moveConfigData.theirScore);
            }

            if (moveConfigData.ourTimer > 0)
            {
                manager.SetOurTimer(moveConfigData.ourTimer / 1000.0f);
            }

            if (moveConfigData.theirTimer > 0)
            {
                manager.SetTheirTimer(moveConfigData.theirTimer / 1000.0f);
            }

            manager.GamePlayedAvA();

            //sendOptions = SendOptions.Ack;
            SendAck();

            break;

        case MsgsEnum.gameEnd:

            GameEndData gameEndData = JsonConvert.DeserializeObject <GameEndData>(serverMsg);
            manager.GameEnd(gameEndData.ourScore, gameEndData.theirScore, gameEndData.win);

            SendAck();

            break;

        case MsgsEnum.gamePaused:

            manager.PauseGame();

            SendAck();

            break;

        case MsgsEnum.exit:
            break;

        case MsgsEnum.ack:

            AckData ackData = JsonConvert.DeserializeObject <AckData>(serverMsg);
            Debug.Log("Ack data " + ackData.reason + " " + ackData.valid + " " + ackData.valid);

            if (ackData.valid)
            {
                manager.PlayerMoveAccepted();

                if (ackData.ourScore > 0 || ackData.theirScore > 0)
                {
                    manager.SetScore(ackData.ourScore, ackData.theirScore);
                }
            }
            else
            {
                manager.PlayerMoveNotAccepted();
            }

            manager.ShowWarning(ackData.reason);

            SendAck();

            break;

        case MsgsEnum.gameStart:

            GameStartData gameStartData = JsonConvert.DeserializeObject <GameStartData>(serverMsg);

            manager.SetMyTurn(gameStartData.myTurn);

            if (gameStartData.ourRemainingTime > 0)
            {
                manager.SetOurTimer(gameStartData.ourRemainingTime / 1000.0f);
            }

            if (gameStartData.theirRemainingTime > 0)
            {
                manager.SetTheirTimer(gameStartData.theirRemainingTime / 1000.0f);
            }

            manager.ResumeGame();

            SendAck();

            break;

        case MsgsEnum.AI_VSHuman:
            break;

        case MsgsEnum.move:

            MoveData moveData = new MoveData();
            moveData.countCaptured = 0;

            moveData = JsonConvert.DeserializeObject <MoveData>(serverMsg);
            boardObject.PlaceStone(moveData.y, moveData.x, moveData.color != 'b');

            manager.AiPlayed();

            if (moveData.ourScore > 0 || moveData.theirScore > 0)
            {
                manager.SetScore(moveData.ourScore, moveData.theirScore);
            }

            //sendOptions = SendOptions.Ack;
            SendAck();

            break;

        case MsgsEnum.forfeit:
            break;

        case MsgsEnum.remove:

            RemoveData removeData = JsonConvert.DeserializeObject <RemoveData>(serverMsg);
            boardObject.RemoveStone(removeData.y, removeData.x);

            //sendOptions = SendOptions.Ack;
            SendAck();

            break;

        default:
            break;
        }

        recievingInCorutine = false;
    }
Beispiel #11
0
 private void GameEnded(GameEndData gameEndData)
 {
     gameEndUI.SetConfiguration(gameEndData);
 }