コード例 #1
0
ファイル: Game.cs プロジェクト: rjcg916/scrabble-fullstack
        public Game(List <string> playerNames)
        {
            this.numberOfPlayers = (byte)playerNames.Count;

            bool validNumberOfPlayers = (numberOfPlayers >= MINPLAYERS) && (numberOfPlayers <= MAXPLAYERS);

            if (!validNumberOfPlayers)
            {
                throw new Exception(MINMAXPLAYERERROR);
            }

            // initialize/choose lexicon
            this.lexicon = new Lexicon();

            // fill tile bag
            this.tileBag = new TileBag();

            // for each player, draw tiles from bag

            byte i = 1;

            playerNames.ForEach(name =>
            {
                var player = new Player(name);
                player.DrawTiles(this.tileBag);
                players.Add(i++, player);
            }
                                );

            // create board
            this.board = new Board();
        }
コード例 #2
0
ファイル: Game.cs プロジェクト: rjcg916/scrabble-fullstack
        public GameDetails GetDetails()
        {
            var details = new GameDetails();

            details.tileBag = this.tileBag;

            details.letterValues = TileBag.GetLetterValues();

            details.rowLabels = Board.GetRowLabels();

            details.colLabels = Board.GetColLabels();

            details.squares = this.board.GetCoordSquares();

            return(details);
        }
コード例 #3
0
        public List <Tile> DrawTiles(TileBag tileBag)
        {
            var tilesAvailable = tileBag.count;

            if (tilesAvailable == 0)
            {
                throw new Exception("No tiles available to draw.");
            }

            var tilesNeeded = Rack.capacity - this.rack.TileCount;

            var drawCount = tilesAvailable > tilesNeeded ? tilesNeeded : tilesAvailable;

            var tilesToAdd = tileBag.DrawTiles(drawCount);

            this.rack.AddTiles(tilesToAdd);

            return(tilesToAdd);
        }