Skip to content

Commit

Permalink
Changed player checking
Browse files Browse the repository at this point in the history
  • Loading branch information
kc3294 committed Nov 24, 2020
1 parent dd0804c commit 3b21cec
Showing 1 changed file with 17 additions and 6 deletions.
23 changes: 17 additions & 6 deletions Assets/Scripts/Board.cs
Original file line number Diff line number Diff line change
Expand Up @@ -33,6 +33,9 @@ public class Board : MonoBehaviourPunCallbacks
private string player1Color = "Dark";
private string player2Color = "Light";
private int priority = default;
private string p1ID = default;
private string p2ID = default;


[Header("Board Attributes")]
private PhotonView pv = default;
Expand Down Expand Up @@ -63,12 +66,12 @@ void Start()
playerSelected2.SetActive(false);

CreateBoard();
if (PhotonNetwork.LocalPlayer.ActorNumber == 2)
if (!IsPlayer1())
transform.localRotation = Quaternion.Euler(0, 0, 180);
//Set player1 and player2 color
winGUI.SetActive(false);

Debug.Log(PhotonNetwork.LocalPlayer.ActorNumber);
Debug.Log(PhotonNetwork.LocalPlayer);
}

void Update()
Expand All @@ -85,15 +88,23 @@ void Update()
ClickPiece();
}

//Returns true if player is the first player in the playerlist
private bool IsPlayer1()
{
//Debug.Log(PhotonNetwork.LocalPlayer);
if (PhotonNetwork.PlayerList.GetValue(0).Equals(PhotonNetwork.LocalPlayer))
return true;
return false;
}

private void CheckPlayerNum()
{
if (PhotonNetwork.CurrentRoom != null)
{
if (PhotonNetwork.CurrentRoom.PlayerCount <= 1 && !gameCompleted)
{
pv.RPC("EndGame", RpcTarget.All, PhotonNetwork.LocalPlayer.ActorNumber);
Debug.Log(PhotonNetwork.LocalPlayer.ActorNumber);
pv.RPC("EndGame", RpcTarget.All, (IsPlayer1() ? 1 : 2));
Debug.Log(PhotonNetwork.LocalPlayer + " Player:" + (IsPlayer1() ? 1 : 2));
PhotonNetwork.CurrentRoom.IsVisible = false;
restartBtn.SetActive(false);
}
Expand Down Expand Up @@ -137,7 +148,7 @@ private void ClickPiece()
if (Input.GetMouseButtonDown(0))
{
DebugBoard();
if (PhotonNetwork.LocalPlayer.ActorNumber != turn)
if ((IsPlayer1() ? 1 : 2) != turn)
return;
if (turn == 2)
{
Expand Down Expand Up @@ -632,7 +643,7 @@ private void FindMoves()
p.ClearMoves();
}
}
if (PhotonNetwork.LocalPlayer.ActorNumber == turn)
if ((IsPlayer1() ? 1 : 2) == turn)
HighlightMovable();
}

Expand Down

0 comments on commit 3b21cec

Please sign in to comment.