Ejemplo n.º 1
0
    public void BeginTurn()
    {
        turnHasBegun = true;
        GetLocalPlayer().ResetDestinationLocation();

        orientationController.SetMovesLabel("Roll First");
        orientationController.SetRollDiceButtonStatus(true);

        if (GetIsLPOnBuildingEntrance())
        {
            taskController.SetVisitedBuilding(tileController.GetTile((int)GetLocalPlayer().location.x, (int)GetLocalPlayer().location.y).building);
            orientationController.SetEnterBuildingButtonStatus(true);
        }

        tileController.SetCanLightUpTile(true);
        SetInitialCameraPosition();
    }
Ejemplo n.º 2
0
    void Start()
    {
        introHolder    = FindObjectOfType <StartGameID> ();
        tileController = FindObjectOfType <TileController>();
        tileController.Setup();
        buildingController = FindObjectOfType <BuildingController> ();
        buildingController.Setup();
        inGameDBController    = FindObjectOfType <InGameDBController>();
        orientationController = FindObjectOfType <OrientationController>();
        taskController        = FindObjectOfType <TaskController>();
        taskController.Setup();
        inGameDBController.StartConnection();
        inGameDBController.FetchInitialGridData();
        tileController.CreateGrid(inGameDBController.GetGridSize());
        inGameDBController.FetchBuildingData();
        buildingController.CreateBuildings(inGameDBController.GetBuildingData());
        inGameDBController.SetGameID(introHolder.GetRoomID());
        inGameDBController.InsertRoomData(introHolder.GetTurnID(), introHolder.getIGNList(), introHolder.getPIDList());
        inGameDBController.FetchCurrentPlayerTurn();
        localPlayerPID    = introHolder.GetPID();
        localPlayerTurnID = introHolder.GetTurnID();
        //GameObject.Destroy (introHolder);

        players = new List <Player>();
        Debug.Log(inGameDBController.GetNumberOfPlayers());
        CreatePlayers(inGameDBController.GetNumberOfPlayers());
        inGameDBController.FetchTaskData();
        taskController.AssignBuildingTasks(inGameDBController.GetTaskData(), buildingController.GetBuildings());
        taskController.AssignLocalPlayerTasks(inGameDBController.GetTaskData(), GetLocalPlayer());
        taskController.InitializeLPTaskLabels(GetLocalPlayer().tasks);

        orientationController.ScaleUI();
        tileController.SetLocalPlayerModelRef(players[localPlayerTurnID].playerModel);

        SetInitialCameraPosition();
        remainingMoves = 0;
        turnHasBegun   = false;
        orientationController.SetMovesLabel("Wait Your Turn");
        orientationController.SetRollDiceButtonStatus(false);
        orientationController.SetEnterBuildingButtonStatus(false);
        orientationController.SetEndTurnButtonStatus(false);
        tileController.SetCanLightUpTile(false);

        if (GetIsLocalPlayerTurn())
        {
            BeginTurn();
        }

        timer = 0;
    }
Ejemplo n.º 3
0
    void Update()
    {
                #if UNITY_EDITOR
        if (Input.GetMouseButton(0) || Input.GetMouseButtonDown(0) || Input.GetMouseButtonUp(0))
        {
            touchList.Clear();

            Ray ray = Camera.main.ScreenPointToRay(Input.mousePosition);

            if (Physics.Raycast(ray, out hit, Mathf.Infinity, touchInputMask))
            {
                GameObject recipient = hit.transform.gameObject;
                if (recipient.GetComponent <Tile>().location != gameFlowController.GetCurrentPlayer().location&& recipient.GetComponent <Tile>().tileType == "None")
                {
                    touchesOld.Add(recipient);
                }
                Debug.Log("Touched " + recipient.name);
                float tileXDistance     = gameFlowController.GetLocalPlayer().location.x - recipient.GetComponent <Tile>().location.x;
                float tileYDistance     = gameFlowController.GetLocalPlayer().location.y - recipient.GetComponent <Tile>().location.y;
                int   totalTileDistance = (int)(Mathf.Abs(tileXDistance) + Mathf.Abs(tileYDistance));

                if (Input.GetMouseButtonDown(0))
                {
                    recipient.SendMessage("OnTouchDown", hit.point, SendMessageOptions.DontRequireReceiver);
                    if (recipient.GetComponent <Tile>().tileType == "None")
                    {
                        if (!orientationController.GetCanMovePlayer() || totalTileDistance > gameFlowController.GetRemainingMoves())
                        {
                            recipient.GetComponent <MeshRenderer>().material.color = tileController.redColor;
                        }
                        else
                        {
                            recipient.GetComponent <MeshRenderer>().material.color = tileController.blueColor;
                        }
                    }
                    lastMousePosition = Input.mousePosition;
                }

                if (Input.GetMouseButtonUp(0))
                {
                    recipient.SendMessage("OnTouchUp", hit.point, SendMessageOptions.DontRequireReceiver);
                    if (recipient.layer == (int)layerValues.tile)
                    {
                        if ((Input.mousePosition - lastMousePosition).sqrMagnitude < new Vector3(touchSenseLeeway, touchSenseLeeway, touchSenseLeeway).sqrMagnitude)
                        {
                            if (orientationController.GetCanMovePlayer() && gameFlowController.GetIsLocalPlayerTurn() &&
                                (recipient.GetComponent <Tile>().tileType == "None" || recipient.GetComponent <Tile>().tileType == "Entrance"))
                            {
                                if (totalTileDistance <= gameFlowController.GetRemainingMoves())
                                {
                                    inGameDBController.MovePlayer(gameFlowController.GetLocalPlayerTurnID(), recipient.GetComponent <Tile>().location);
                                    if (recipient.GetComponent <Tile>().tileType == "Entrance")
                                    {
                                        taskController.SetBuildingPanelTitle(recipient.GetComponent <Tile>().building.buildingName);
                                        orientationController.SetEnterBuildingButtonStatus(true);
                                        taskController.SetVisitedBuilding(recipient.GetComponent <Tile>().building);
                                    }
                                    else
                                    {
                                        orientationController.SetEnterBuildingButtonStatus(false);
                                    }
                                    gameFlowController.SetRemainingMoves(gameFlowController.GetRemainingMoves() - totalTileDistance);
                                }
                            }
                        }
                    }
                    for (int i = 0; i < touchesOld.Count; i++)
                    {
                        touchesOld[i].GetComponent <MeshRenderer>().material.color = tileController.defaultColor;
                    }
                    touchesOld.Clear();
                }
            }

            foreach (GameObject g in touchesOld)
            {
                if (!touchList.Contains(g))
                {
                    g.SendMessage("OnTouchExit", hit.point, SendMessageOptions.DontRequireReceiver);
                }
            }
        }
                #endif

        if (Input.touchCount == 1)
        {
            touchList.Clear();

            foreach (Touch touch in Input.touches)
            {
                Ray ray = Camera.main.ScreenPointToRay(touch.position);

                if (Physics.Raycast(ray, out hit, Mathf.Infinity, touchInputMask))
                {
                    GameObject recipient = hit.transform.gameObject;
                    if (recipient.GetComponent <Tile>().location != gameFlowController.GetCurrentPlayer().location || recipient.GetComponent <Tile>().tileType == "None")
                    {
                        touchesOld.Add(recipient);
                    }
                    float tileXDistance     = gameFlowController.GetLocalPlayer().location.x - recipient.GetComponent <Tile>().location.x;
                    float tileYDistance     = gameFlowController.GetLocalPlayer().location.y - recipient.GetComponent <Tile>().location.y;
                    int   totalTileDistance = (int)(Mathf.Abs(tileXDistance) + Mathf.Abs(tileYDistance));

                    if (touch.phase == TouchPhase.Began)
                    {
                        recipient.SendMessage("OnTouchDown", hit.point, SendMessageOptions.DontRequireReceiver);
                        lastTouchPosition = Input.touches[0].position;
                        if (recipient.GetComponent <Tile>().tileType == "None")
                        {
                            if (!orientationController.GetCanMovePlayer() || totalTileDistance > gameFlowController.GetRemainingMoves())
                            {
                                recipient.GetComponent <MeshRenderer>().material.color = tileController.redColor;
                            }
                            else
                            {
                                recipient.GetComponent <MeshRenderer>().material.color = tileController.blueColor;
                            }
                        }
                    }
                    if (touch.phase == TouchPhase.Ended)
                    {
                        recipient.SendMessage("OnTouchUp", hit.point, SendMessageOptions.DontRequireReceiver);
                        if (recipient.layer == (int)layerValues.tile)
                        {
                            if (Mathf.Abs(Vector2.Distance(Input.touches[0].position, lastTouchPosition)) < touchSenseLeeway)
                            {
                                if (orientationController.GetCanMovePlayer() && gameFlowController.GetIsLocalPlayerTurn() &&
                                    (recipient.GetComponent <Tile>().tileType == "None" || recipient.GetComponent <Tile>().tileType == "Entrance"))
                                {
                                    if (totalTileDistance <= gameFlowController.GetRemainingMoves())
                                    {
                                        inGameDBController.MovePlayer(gameFlowController.GetLocalPlayerTurnID(), recipient.GetComponent <Tile>().location);
                                        if (recipient.GetComponent <Tile>().tileType == "Entrance")
                                        {
                                            taskController.SetBuildingPanelTitle(recipient.GetComponent <Tile>().building.buildingName);
                                            orientationController.SetEnterBuildingButtonStatus(true);
                                            taskController.SetVisitedBuilding(recipient.GetComponent <Tile>().building);
                                        }
                                        else
                                        {
                                            orientationController.SetEnterBuildingButtonStatus(false);
                                        }
                                        gameFlowController.SetRemainingMoves(gameFlowController.GetRemainingMoves() - totalTileDistance);
                                    }
                                }
                            }
                        }
                        for (int i = 0; i < touchesOld.Count; i++)
                        {
                            touchesOld[i].GetComponent <MeshRenderer>().material.color = tileController.defaultColor;
                        }
                        touchesOld.Clear();
                    }
                    if (touch.phase == TouchPhase.Stationary || touch.phase == TouchPhase.Moved)
                    {
                        recipient.SendMessage("OnTouchStay", hit.point, SendMessageOptions.DontRequireReceiver);
                    }
                    if (touch.phase == TouchPhase.Canceled)
                    {
                        recipient.SendMessage("OnTouchExit", hit.point, SendMessageOptions.DontRequireReceiver);
                    }
                }
            }
            foreach (GameObject g in touchesOld)
            {
                if (!touchList.Contains(g))
                {
                    g.SendMessage("OnTouchExit", hit.point, SendMessageOptions.DontRequireReceiver);
                }
            }
        }
    }