Ejemplo n.º 1
0
        private void SellFromGenre(Genre genre, Market market, List<Book>[] printedBooks, List<Book>[] eBooks, Player[] players, Random rand)
        {
            List<Book> printedOfGenre = new List<Book>();
            List<Book> digitalOfGenre = new List<Book>();

            //Gets the demands of the specific genre from the Market class
            int printedGenreDemand = market.GetDemand(genre, false);
            int digitalGenreDemand = market.GetDemand(genre, true);

            //Collects all the books of the specific genre from all players
            for (int i = 0; i < printedBooks.Length; i++)
                printedOfGenre.AddRange(printedBooks[i].Where(b => b.GetGenre() == genre));
            for (int i = 0; i < eBooks.Length; i++)
                digitalOfGenre.AddRange(eBooks[i].Where(b => b.GetGenre() == genre));

            foreach (Book book in printedOfGenre)
                book.CalcProfitablity();

            //Sell digital books
            for (int i = 0; i < digitalGenreDemand; i++)
            {
                if (digitalOfGenre.Count == 0)
                    break;

                int index = rand.Next(0, digitalOfGenre.Count);

                SellBook(genre, index, true, digitalOfGenre, players, market, ref digitalGenreDemand);
            }

            //Leftover demand for ebooks is sold printed books
            for (int i = 0; i < digitalGenreDemand; i++)
            {
                if (printedOfGenre.Count == 0)
                    break;

                int index = rand.Next(0, printedOfGenre.Count);

                SellBook(genre, index, true, printedOfGenre, players, market, ref digitalGenreDemand);
            }

            //Sell printed books
            for (int i = 0; i < printedGenreDemand; i++)
            {
                if (printedOfGenre.Count == 0)
                    break;

                int index = rand.Next(0, printedOfGenre.Count);

                SellBook(genre, index, false, printedOfGenre, players, market, ref printedGenreDemand);
            }
        }
Ejemplo n.º 2
0
        private void SellBook(Genre genre, int index, bool eBook, List<Book> books, Player[] players, Market market, ref int demand)
        {
            int sellChance = rand.Next(0, 101);

            if (books[index].SellChance >= sellChance)
            {
                if (!players[books[index].Owner].BookSold(books[index]))
                    return;

                market.RemoveDemand(genre, eBook, 1, books[index].Owner);
                demand -= 1;

                if (books[index].Stock <= 0 && !eBook)
                    books.RemoveAt(index);
            }
        }
Ejemplo n.º 3
0
        public void SellAllBooks(Market market, Player[] players)
        {
            List<Book>[] printedBooks, eBooks;
            printedBooks = new List<Book>[players.Length];
            eBooks = new List<Book>[players.Length];

            //Adds each player's books for sale to a list
            for (int i = 0; i < players.Length; i++)
                AddBooksToSell(printedBooks, eBooks, players[i]);

            int numberOfGenres = Book.numberOfGenres;

            //Goes through each genre and sells books from every player
            for (int i = 0; i < numberOfGenres; i++)
                SellFromGenre((Genre)i, market, printedBooks, eBooks, players, rand);
        }
Ejemplo n.º 4
0
        public void ReceiveInput(Input input, Player player)
        {
            archive.ReceiveInput(input, player.playerID);

            if (GameManager.phase == GameManager.TurnPhase.BookPicking)
            {
                if (input.ButtonA)
                {
                    Book transferedBook = archive.TransferSelectedBook(player.playerID);
                    transferedBook.Owner = player.playerID;
                    player.AddBook(transferedBook);
                    archive.DeactivateSelection(player.playerID);
                    player.OpenPublishMenu();
                    player.phaseDone = true;
                }
                else if (input.ButtonB)
                {
                    archive.DeactivateSelection(player.playerID);
                    player.phaseDone = true;
                }
            }
        }
Ejemplo n.º 5
0
        private void GameStart(TextureManager textureManager, StartMenu startMenu)
        {
            currentTurn = 1;
            phase = TurnPhase.BookPicking;
            inputManager = new InputManager(players.Length);

            for (int i = 0; i < players.Length; i++)
                players[i] = new Player(textureManager, i);

            bookManager.archive.ClearArchive();

            bookManager.GenerateBooks();
        }
Ejemplo n.º 6
0
 private void AddBooksToSell(List<Book>[] printedBooks, List<Book>[] eBooks, Player player)
 {
     printedBooks[player.playerID] = player.GetBooksForSale(false);
     eBooks[player.playerID] = player.GetBooksForSale(true);
 }