}//Fight() private bool WhichClass(string playerWeapon, string otherWeapon) { //set the playerWin here bool playerWin = false; switch (playerWeapon) { case "rock": PlayerRock playerGameR = new PlayerRock(); playerWin = playerGameR.Act(otherWeapon); break; case "paper": PlayerPaper playerGameP = new PlayerPaper(); playerWin = playerGameP.Act(otherWeapon); break; case "scissors": PlayerScissors playerGameS = new PlayerScissors(); playerWin = playerGameS.Act(otherWeapon); break; default: break; } return(playerWin); } //WhichClass()
public void Fight() { //Array of weapons string[] weapons = new string[3] { "rock", "paper", "scissors" }; //instance of random class Random rnd = new Random(); //Set flags for an individual win, or not bool playerOneWin = false; bool playerTwoWin = false; //Variables to hold weapon name for each player string playerOneWeapon = ""; string playerTwoWeapon = ""; //Counters for player wins int playerOneCounter = 0; int playerTwoCounter = 0; //Instantiate Player classes for playerOne PlayerRock playerOneRock = new PlayerRock(); PlayerPaper playerOnePaper = new PlayerPaper(); PlayerScissors playerOneScissors = new PlayerScissors(); //Instantiate Player classes for playerTwo PlayerRock playerTwoRock = new PlayerRock(); PlayerPaper playerTwoPaper = new PlayerPaper(); PlayerScissors playerTwoScissors = new PlayerScissors(); for (int i = 1; i <= 100; i++) { //playerOne gets their weapon int weaponId1 = rnd.Next(0, 2); playerOneWeapon = weapons[weaponId1]; //playerTwo gets their weapon int weaponId2 = rnd.Next(0, 2); playerTwoWeapon = weapons[weaponId2]; //Play each combination & return win status playerOneWin = WhichClass(playerOneWeapon, playerTwoWeapon); playerTwoWin = WhichClass(playerTwoWeapon, playerOneWeapon); if (playerOneWin) { playerOneCounter++; } else if (playerTwoWin) { playerTwoCounter++; } }//for NumPlayerOneWins = playerOneCounter; NumPlayerTwoWins = playerTwoCounter; }//Fight()
}//Fight() private bool WhichClass(string playerWeapon, string otherWeapon) { //set the playerWin here bool playerWin = false; switch (playerWeapon) { case "rock": PlayerRock playerGameR = new PlayerRock(); playerWin = playerGameR.Act(otherWeapon); break; case "paper": PlayerPaper playerGameP = new PlayerPaper(); playerWin = playerGameP.Act(otherWeapon); break; case "scissors": PlayerScissors playerGameS = new PlayerScissors(); playerWin = playerGameS.Act(otherWeapon); break; default: break; } return playerWin; }//WhichClass()