Skip to content

Commit

Permalink
Fixed win condition on forced exit
Browse files Browse the repository at this point in the history
  • Loading branch information
ahnaf26 committed Nov 24, 2020
1 parent 3b21cec commit 69c8b3c
Show file tree
Hide file tree
Showing 4 changed files with 38 additions and 17 deletions.
2 changes: 2 additions & 0 deletions .idea/.idea.Checkers/.idea/indexLayout.xml

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

13 changes: 11 additions & 2 deletions Assets/Scripts/Board.cs
Original file line number Diff line number Diff line change
Expand Up @@ -101,10 +101,18 @@ private void CheckPlayerNum()
{
if (PhotonNetwork.CurrentRoom != null)
{
// For awarding win to player if the other player disconnects
if (PhotonNetwork.CurrentRoom.PlayerCount <= 1 && !gameCompleted)
{
pv.RPC("EndGame", RpcTarget.All, (IsPlayer1() ? 1 : 2));
Debug.Log(PhotonNetwork.LocalPlayer + " Player:" + (IsPlayer1() ? 1 : 2));
if (PhotonNetwork.LocalPlayer.ActorNumber == 1)
{
pv.RPC("EndGame", RpcTarget.All, 1);
}
else
{
pv.RPC("EndGame", RpcTarget.All, 2);
}

PhotonNetwork.CurrentRoom.IsVisible = false;
restartBtn.SetActive(false);
}
Expand Down Expand Up @@ -492,6 +500,7 @@ void DebugWin()
}
}

//TODO: Win UI not loading properly if someone force closes a game
//After a person wins announce to both players
[PunRPC]
private void EndGame(int player)
Expand Down
34 changes: 22 additions & 12 deletions Assets/Scripts/Lobby/Scripts/Launcher.cs
Original file line number Diff line number Diff line change
Expand Up @@ -77,17 +77,7 @@ public override void OnJoinedRoom()
MenuManager.Instance.OpenMenu("room");
roomNameText.text = PhotonNetwork.CurrentRoom.Name;

Player[] players = PhotonNetwork.PlayerList;

foreach (Transform child in playerListContent)
{
Destroy(child.gameObject);
}

for (int i = 0; i < players.Count(); i++)
{
Instantiate(playerListItemPrefab, playerListContent).GetComponent<PlayerListItem>().SetUp(players[i]);
}
RefreshPlayerList();

startGameButton.SetActive(PhotonNetwork.IsMasterClient);
}
Expand Down Expand Up @@ -133,6 +123,7 @@ public override void OnRoomListUpdate(List<RoomInfo> roomList)
{
Destroy(trans.gameObject);
}


for (int i = 0; i < roomList.Count; i++)
{
Expand All @@ -150,11 +141,30 @@ public override void OnPlayerLeftRoom(Player otherPlayer)
{
base.OnPlayerLeftRoom(otherPlayer);
Debug.Log(otherPlayer.NickName + " has left the game");

RefreshPlayerList();
}

public override void OnPlayerEnteredRoom(Player newPlayer)
{
Instantiate(playerListItemPrefab, playerListContent).GetComponent<PlayerListItem>().SetUp(newPlayer);
Instantiate(playerListItemPrefab, playerListContent).GetComponent<PlayerListItem>().SetUp(newPlayer, 1);

RefreshPlayerList();
}

private void RefreshPlayerList()
{
Player[] players = PhotonNetwork.PlayerList;

foreach (Transform child in playerListContent)
{
Destroy(child.gameObject);
}

for (int i = 0; i < players.Count(); i++)
{
Instantiate(playerListItemPrefab, playerListContent).GetComponent<PlayerListItem>().SetUp(players[i], i + 1);
}
}
}
}
6 changes: 3 additions & 3 deletions Assets/Scripts/Lobby/Scripts/PlayerListItem.cs
Original file line number Diff line number Diff line change
Expand Up @@ -10,10 +10,10 @@ public class PlayerListItem : MonoBehaviourPunCallbacks
[SerializeField] TMP_Text text = default;
Player player;

public void SetUp(Player _player)
public void SetUp(Player p, int playerNum)
{
player = _player;
text.text = _player.NickName;
player = p;
text.text = "Player " + playerNum;
}

public override void OnPlayerLeftRoom(Player otherPlayer)
Expand Down

0 comments on commit 69c8b3c

Please sign in to comment.