Guest User

Untitled

a guest
May 19th, 2014
328
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C# 1.23 KB | None | 0 0
  1. class Program
  2.     {
  3.         static void Main(string[] args)
  4.         {
  5.             var players = new List<Player>();
  6.  
  7.             players.Add(new Player("Spelare1"));
  8.             players.Add(new Player("Spelare2"));
  9.  
  10.         }
  11.  
  12.         public void StartGame(IEnumerable<Player> players)
  13.         {
  14.             foreach (var player in players)
  15.             {
  16.                 while (player.throwCount <= 3)
  17.                 {
  18.                     // Do game logic
  19.                     var score = 45;
  20.  
  21.                     // Set score
  22.                     player.Score.Add(score);
  23.                     player.throwCount++;
  24.                 }
  25.             }
  26.  
  27.             // Get the winner based on the sum of scores
  28.             var winner = players.OrderByDescending(p => p.Score.Sum(s => s)).First();
  29.         }
  30.  
  31.         public class Player
  32.         {
  33.             public string Name { get; set; }
  34.             public int throwCount { get; set; }
  35.             public List<int> Score { get; set; }
  36.  
  37.             public Player(string name)
  38.             {
  39.                 Name = name;
  40.                 throwCount = 1;
  41.             }
  42.  
  43.             public Player()
  44.             {
  45.                 throwCount = 1;
  46.             }
  47.         }
  48.     }
Advertisement
Add Comment
Please, Sign In to add comment