Guest User

Untitled

a guest
May 20th, 2018
124
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 2.28 KB | None | 0 0
  1. let gamePlayChoicesArr: [String] = ["rock", "paper", "scissors"]
  2. var gameOn: Bool = true
  3.  
  4. while gameOn {
  5. print("Let's go! Rock, paper, scissors...the choice is yours.")
  6. var playerResponse: String = readLine()!
  7. var randomIndex: Int = Int(arc4random_uniform(UInt32(gamePlayChoicesArr.count)))
  8. var compilerPlayerResponse = gamePlayChoicesArr[randomIndex]
  9.  
  10. if playerResponse == compilerPlayerResponse {
  11. print("Opponent: \(compilerPlayerResponse)")
  12. print("You have tied! Play again? Please respond with yes or no.")
  13. } else if playerResponse == "rock" && compilerPlayerResponse == "scissors" {
  14. print("Opponent: \(compilerPlayerResponse)")
  15. print("You win! Play again? Please respond with yes or no.")
  16. } else if playerResponse == "rock" && compilerPlayerResponse == "paper" {
  17. print("Opponent: \(compilerPlayerResponse)")
  18. print("You lose! Play again? Please respond with yes or no.")
  19. } else if playerResponse == "paper" && compilerPlayerResponse == "rock" {
  20. print("Opponent: \(compilerPlayerResponse)")
  21. print("You win! Play again? Please respond with yes or no.")
  22. } else if playerResponse == "paper" && compilerPlayerResponse == "scissors" {
  23. print("Opponent: \(compilerPlayerResponse)")
  24. print("You lose! Play again? Please respond with yes or no.")
  25. } else if playerResponse == "scissors" && compilerPlayerResponse == "paper" {
  26. print("Opponent: \(compilerPlayerResponse)")
  27. print("You win! Play again? Please respond with yes or no.")
  28. } else if playerResponse == "scissors" && compilerPlayerResponse == "rock" {
  29. print("Opponent: \(compilerPlayerResponse)")
  30. print("You lose! Play again? Please respond with yes or no.")
  31. } else if playerResponse != "rock" || playerResponse != "scissors" || playerResponse != "paper" {
  32. print("Please enter a valid response.")
  33. continue
  34. }
  35.  
  36. var doYouWantToPlayResponse = readLine()!
  37.  
  38. if doYouWantToPlayResponse == "yes" {
  39. continue
  40. } else {
  41. print("Have a good one!")
  42. gameOn = false
  43. }
  44.  
  45. }
Add Comment
Please, Sign In to add comment