Ejemplo n.º 1
0
        // GET: Home
        public async Task <ActionResult> Index()
        {
            var vm    = new GameListViewModel();
            var grain = GameListGrainFactory.GetGrain(0);

            foreach (var game in await grain.Unstarted())
            {
                var gamevm = new GameListViewModel.GameViewModel
                {
                    Name    = await game.Name(),
                    Players = new List <string>()
                };
                var players = await game.Players();

                foreach (var player in players)
                {
                    gamevm.Players.Add(await player.Name());
                }
                vm.Games.Add(gamevm);
            }
            return(View(vm));
        }
Ejemplo n.º 2
0
        public Task StartGame()
        {
            _state = GameState.InProgress;

            var usedStars      = _stars.Count * 0.25;
            var starsPerPlayer = (int)(usedStars / _players.Count);

            Console.WriteLine(" -- {0,-10} -- {1} stars per player.", "Game", starsPerPlayer);
            var offset = 0;

            foreach (var player in _players.Values)
            {
                foreach (var star in _stars.Skip(offset).Take(starsPerPlayer))
                {
                    star.ChangeOwnership(player);
                    player.AcquireStar(star);
                    offset++;
                }
            }
            Console.WriteLine(" -- {0,-10} -- {1} started.", "Game", _name);
            GameListGrainFactory.GetGrain(0).ChangeState(this, GameState.Unstarted, GameState.InProgress);
            return(TaskDone.Done);
        }