Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- let gamePlayChoicesArr: [String] = ["rock", "paper", "scissors"]
- var gameOn: Bool = true
- while gameOn {
- print("Let's go! Rock, paper, scissors...the choice is yours.")
- var playerResponse: String = readLine()!
- var randomIndex: Int = Int(arc4random_uniform(UInt32(gamePlayChoicesArr.count)))
- var compilerPlayerResponse = gamePlayChoicesArr[randomIndex]
- if playerResponse == compilerPlayerResponse {
- print("Opponent: \(compilerPlayerResponse)")
- print("You have tied! Play again? Please respond with yes or no.")
- } else if playerResponse == "rock" && compilerPlayerResponse == "scissors" {
- print("Opponent: \(compilerPlayerResponse)")
- print("You win! Play again? Please respond with yes or no.")
- } else if playerResponse == "rock" && compilerPlayerResponse == "paper" {
- print("Opponent: \(compilerPlayerResponse)")
- print("You lose! Play again? Please respond with yes or no.")
- } else if playerResponse == "paper" && compilerPlayerResponse == "rock" {
- print("Opponent: \(compilerPlayerResponse)")
- print("You win! Play again? Please respond with yes or no.")
- } else if playerResponse == "paper" && compilerPlayerResponse == "scissors" {
- print("Opponent: \(compilerPlayerResponse)")
- print("You lose! Play again? Please respond with yes or no.")
- } else if playerResponse == "scissors" && compilerPlayerResponse == "paper" {
- print("Opponent: \(compilerPlayerResponse)")
- print("You win! Play again? Please respond with yes or no.")
- } else if playerResponse == "scissors" && compilerPlayerResponse == "rock" {
- print("Opponent: \(compilerPlayerResponse)")
- print("You lose! Play again? Please respond with yes or no.")
- } else if playerResponse != "rock" || playerResponse != "scissors" || playerResponse != "paper" {
- print("Please enter a valid response.")
- continue
- }
- var doYouWantToPlayResponse = readLine()!
- if doYouWantToPlayResponse == "yes" {
- continue
- } else {
- print("Have a good one!")
- gameOn = false
- }
- }
Add Comment
Please, Sign In to add comment