Answered step by step
Verified Expert Solution
Link Copied!

Question

1 Approved Answer

Hello. What is happening in this part of the code? :) ----------------------------------------------------------------------------------------------------------- public void AnnounceWinner() { if (!gameIsStarted) { System.Console.WriteLine(The game is not started yet.);

Hello. What is happening in this part of the code? :)

-----------------------------------------------------------------------------------------------------------

public void AnnounceWinner() { if (!gameIsStarted) { System.Console.WriteLine("The game is not started yet."); } else { Player winner = players[0]; foreach (var player in players) { if (player.TotalHandValue() > winner.TotalHandValue()) { winner = player; } } System.Console.WriteLine("Winner is: " + winner.Name); } }

------------------------------------------------------------------------------------------------------------------------

Also I was wondering why our teacher made a list for Player. If it is because it makes everything easier?

------------------------------------------------------------------------------------------------------------------------

CONTEXT:

using System.Collections.Generic; namespace CardGame { public class Game { private List players = new List(); private bool gameIsStarted = false; private Deck deck = null; private int NUMBER_OF_CARDS_TO_DEAL = 5; public Game(Deck deck) { this.deck = deck; //Shuffle og tager deck } public void AcceptPlayer(Player player) { if (!gameIsStarted) { players.Add(player); } else { // Maybe report on the console that the game has started? // Or throw an exception? // The requirements does not say anything about this scenario // so maybe we should go back to the product owner and ask. } } public void Start() { gameIsStarted = true; DealCards(); } private void DealCards() { foreach (var player in players) //For hver spiller giver den 5 kort { deck.DealTo(player, NUMBER_OF_CARDS_TO_DEAL); } } public void AnnounceWinner() { if (!gameIsStarted) { System.Console.WriteLine("The game is not started yet."); } else { Player winner = players[0]; //Startvrdi - Tnk Lasses rundkreds foreach (var player in players) //Kigger alle spillere igennem { if (player.TotalHandValue() > winner.TotalHandValue()) //Sammenligning { winner = player; } } System.Console.WriteLine("Winner is: " + winner.Name); } } } } 

--------------------------------------------------------------

Thank you!

Step by Step Solution

There are 3 Steps involved in it

Step: 1

blur-text-image

Get Instant Access to Expert-Tailored Solutions

See step-by-step solutions with expert insights and AI powered tools for academic success

Step: 2

blur-text-image_step_2

Step: 3

blur-text-image_step3

Ace Your Homework with AI

Get the answers you need in no time with our AI-driven, step-by-step assistance

Get Started

Recommended Textbook for

Database Concepts

Authors: David M Kroenke, David J Auer

6th Edition

ISBN: 0132742926, 978-0132742924

More Books

Students also viewed these Databases questions

Question

Which team solution is more likely to be pursued and why?

Answered: 1 week ago

Question

How do Excel Pivot Tables handle data from non OLAP databases?

Answered: 1 week ago