Advertisement
Guest User

Untitled

a guest
Jan 20th, 2017
77
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.59 KB | None | 0 0
  1. using System;
  2. using System.Collections.Generic;
  3. using System.Linq;
  4. using System.Media;
  5. using System.Text;
  6. using System.Threading.Tasks;
  7.  
  8. namespace SSP
  9. {
  10. public class Program
  11. {
  12. static void Main(string[] args)
  13. {
  14. var game = new Game(new Random());
  15.  
  16. while (Console.ReadLine() != "stop")
  17. {
  18. game.Play();
  19. }
  20.  
  21. }
  22. }
  23.  
  24. public class Game
  25. {
  26. private readonly Random random;
  27. readonly string[] items = {"Камень", "Ножницы", "Бумага"};
  28. readonly string[] winner = {"Первый", "Второй", "Ничья"};
  29.  
  30. public Game(Random random)
  31. {
  32. this.random = random;
  33. }
  34.  
  35. public void Play()
  36. {
  37. var indexes = new[] {random.Next(3), random.Next(3)};
  38. Console.WriteLine($"{items[indexes[0]]} vs {items[indexes[1]]}. Winner: {WhoWinner(indexes)}");
  39. }
  40.  
  41. private string WhoWinner(int[] indexes)
  42. {
  43. if (indexes[0] == indexes[1])
  44. {
  45. return winner[2];
  46. }
  47. if (indexes[0] < indexes[1])
  48. {
  49. if (indexes[1] - indexes[0] == 1)
  50. {
  51. return winner[0];
  52. }
  53. return winner[1];
  54. }
  55. if (indexes[0] - indexes[1] == 1)
  56. {
  57. return winner[1];
  58. }
  59. else
  60. {
  61. return winner[0];
  62. }
  63. }
  64. }
  65. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement