private string getGameEndText() { AllPlayers p1 = players[1], p2 = players[1], p3 = players[1], p4 = players[1]; // Assignments are only temporary! string text; bool notDone = true; int i = 0; while (notDone) { if (players[i].placement == 1) { p1 = players[i]; notDone = false; } else { i++; } } notDone = true; i = 0; while (notDone) { if (players[i].placement == 2) { p2 = players[i]; notDone = false; } else { i++; } } notDone = true; i = 0; while (notDone) { if (players[i].placement == 3) { p3 = players[i]; notDone = false; } else { i++; } } notDone = true; i = 0; while (notDone) { if (players[i].placement == 4) { p4 = players[i]; notDone = false; } else { i++; } } text = $"The game is done! \n" + $"Congratulations to player {currentPlayerString(p1)} for winning! With Behavior: \n" + $"Player {currentPlayerString(p2)} got second place \n" + $"Player {currentPlayerString(p3)} got third place \n" + $"Player {currentPlayerString(p4)} got fourth place \n \n" + $"Thanks for playing!"; Ludo.ControlPanel.currentPlaytxt.Text = currentPlayerString(p1); // Sets display to winning player return(text); }
public void turnEnd(int pieceNum) { if (pieceNum != 99) // pieceNum is 99 if no pieces can move { Ludo.movePiece(currentPlayer.pieces[pieceNum - 1], diceValue); } if (currentPlayerExtraTurn && currentPlayer.placement == 0) // If the player has an extra turn { currentPlayerExtraTurn = false; Ludo.ControlPanel.dicebtn.Enabled = true; Ludo.ControlPanel.piecebtnOne.Enabled = false; Ludo.ControlPanel.piecebtnTwo.Enabled = false; Ludo.ControlPanel.piecebtnThree.Enabled = false; Ludo.ControlPanel.piecebtnFour.Enabled = false; if (players[currentPlayer.team - 1] is Xela) { giveTurnToXela(); } } else // If the player doesn't have an extra turn { // Gives the turn to the next player currentPlayer = nextPlayer(currentPlayer); if (gameDone == false) { diceRollsForCurrentPlayer = 0; currentPlayerExtraTurn = false; Ludo.ControlPanel.currentPlaytxt.Text = currentPlayerString(currentPlayer); Ludo.ControlPanel.dicebtn.Enabled = true; Ludo.ControlPanel.piecebtnOne.Enabled = false; Ludo.ControlPanel.piecebtnTwo.Enabled = false; Ludo.ControlPanel.piecebtnThree.Enabled = false; Ludo.ControlPanel.piecebtnFour.Enabled = false; Ludo.ControlPanel.dice.Image = Image.FromFile("Images/Dice/DiceBlank.png"); turnCount++; Ludo.ControlPanel.turnCount.Text = $"Turn: {turnCount}"; if (players[currentPlayer.team - 1] is Xela) { giveTurnToXela(); } } else // If the game is done (All players have gotten their pieces into goal) { endScreenShown = true; diceRollsForCurrentPlayer = 0; currentPlayerExtraTurn = false; Ludo.ControlPanel.dicebtn.Enabled = false; Ludo.ControlPanel.piecebtnOne.Enabled = false; Ludo.ControlPanel.piecebtnTwo.Enabled = false; Ludo.ControlPanel.piecebtnThree.Enabled = false; Ludo.ControlPanel.piecebtnFour.Enabled = false; Ludo.ControlPanel.dice.Image = Image.FromFile("Images/Dice/DiceBlank.png"); if (!noMessageBox) { MessageBox.Show(getGameEndText()); } Ludo.Close(); // Closes the ludo screen, after pressing OK to the messageBox } } }