The Form has 4 classes Card, Deck , Player and Game, game being the class that runs everything
The form has 3 TextBox named textName, textBooks and textProgress , ListBox named listHand, 2 buttons named buttonStart and buttonAsk
Card
classCard{publicValuesValue{ get;set;}publicSuitsSuit{get;set;}publicCard(Suits suit,Values value){this.Suit= suit;this.Value= value;}public string Name{
get {returnValue.ToString()+" of "+Suit.ToString();}}public override string ToString(){returnName;}publicstatic string Plural(Values value){if(value ==Values.Six)return"Sixes";elsereturn value.ToString()+"s";}}enumSuits{Spades,Clubs,Hearts,Diamonds,}enumValues{Ace=1,Two=2,Three=3,Four=4,Five=5,Six=6,Seven=7,Eight=8,Nine=9,Ten=10,Jack=11,Queen=12,King=13,}
Deck
classDeck{privateList<Card> cards;privateRandom random =newRandom();publicDeck(){
cards =newList<Card>();for(int suit =0; suit <=3; suit++)for(int value =1; value <=13; value++)
cards.Add(newCard((Suits)suit,(Values)value));}publicDeck(IEnumerable<Card> initialCards){
cards =newList<Card>(initialCards);}publicintCount{ get {return cards.Count;}}publicvoidAdd(Card cardToAdd){
cards.Add(cardToAdd);}publicCardDeal(int index){CardCardToDeal= cards[index];
cards.RemoveAt(index);returnCardToDeal;}publicvoidShuffle(){List<Card>NewCards=newList<Card>();while(cards.Count>0){intCardToMove= random.Next(cards.Count);NewCards.Add(cards[CardToMove]);
cards.RemoveAt(CardToMove);}
cards =NewCards;}publicIEnumerable<string>GetCardNames(){
string[]CardNames=new string[cards.Count];for(int i =0; i < cards.Count; i++)CardNames[i]= cards[i].Name;returnCardNames;}publicvoidSort(){
cards.Sort(newCardComparer_bySuit());}publicCardPeek(int cardNumber){return cards[cardNumber];}publicCardDeal(){returnDeal(0);}publicboolContainsValue(Values value){
foreach (Card card in cards)if(card.Value== value)returntrue;returnfalse;}publicDeckPullOutValues(Values value){Deck deckToReturn =newDeck(newCard[]{});for(int i = cards.Count-1; i >=0; i--)if(cards[i].Value== value)
deckToReturn.Add(Deal(i));return deckToReturn;}publicboolHasBook(Values value){intNumberOfCards=0;
foreach (Card card in cards)if(card.Value== value)NumberOfCards++;if(NumberOfCards==4)returntrue;elsereturnfalse;}publicvoidSortByValue(){
cards.Sort(newCardComparer_byValue());}}classCardComparer_bySuit:IComparer<Card>{publicintCompare(Card x,Card y){if(x.Suit> y.Suit)return1;if(x.Suit< y.Suit)return-1;if(x.Value> y.Value)return1;if(x.Value< y.Value)return-1;return0;}}classCardComparer_byValue:IComparer<Card>{publicintCompare(Card x,Card y){if(x.Value< y.Value)return-1;if(x.Value> y.Value)return1;if(x.Suit< y.Suit)return-1;if(x.Suit> y.Suit)return1;return0;}}
Player
classPlayer{private string name;public string Name{ get {return name;}}privateRandom random;privateDeck cards;privateTextBox textBoxOnForm;publicPlayer(String name,Random random,TextBox textBoxOnForm){this.name = name;this.random = random;this.textBoxOnForm = textBoxOnForm;this.cards =newDeck(newCard[]{});
textBoxOnForm.Text+= name +"has joined the game"+Environment.NewLine;}publicIEnumerable<Values>PullOutBooks(){List<Values> books =newList<Values>();for(int i =1; i<=13; i++){Values value =(Values)i;int howMany =0;for(int card =0; card < cards.Count; card++)if(cards.Peek(card).Value== value)
howMany++;if(howMany ==4){
books.Add(value);for(int card = cards.Count-1; card >=0; card--)
cards.Deal(card);}}return books;}publicValuesGetRandomValue(){Card randomCard = cards.Peek(random.Next(cards.Count));return randomCard.Value;}publicDeckDoYouHaveAny(Values value){Deck cardsIHave = cards.PullOutValues(value);
textBoxOnForm.Text+=Name+"has"+ cardsIHave.Count+""+Card.Plural(value)+Environment.NewLine;return cardsIHave;}publicvoidAskForACard(List<Player> players,int myIndex,Deck stock){Values randomValue =GetRandomValue();AskForACard(players, myIndex, stock, randomValue);}publicvoidAskForACard(List<Player>players,int myIndex,Deck stock,Values value){
textBoxOnForm.Text+=Name+"asks if anyone has a "+ value +Environment.NewLine;int totalCardsGiven =0;for(int i =0; i<players.Count; i++){if(i != myIndex){Player player = players[i];DeckCardsGiven= player.DoYouHaveAny(value);
totalCardsGiven +=CardsGiven.Count;while(CardsGiven.Count>0)
cards.Add(CardsGiven.Deal());}}if(totalCardsGiven ==0){
textBoxOnForm.Text+=Name+"must draw from teh stock."+Environment.NewLine;
cards.Add(stock.Deal());}}publicintCardCount{ get {return cards.Count;}}publicvoidTakeCard(Card card){ cards.Add(card);}publicIEnumerable<string>GetCardNames(){return cards.GetCardNames();}publicCardPeek(int cardNumber){return cards.Peek(cardNumber);}publicvoidSortHand(){ cards.SortByValue();}}
Game
classGame{privateList<Player> players;privateDictionary<Values,Player> books;privateDeck stock;privateTextBox textBoxOnForm;publicGame(string playerName,IEnumerable<string> opponentNames,TextBox textBoxOnForm){Random random =newRandom();this.textBoxOnForm = textBoxOnForm;
players =newList<Player>();
players.Add(newPlayer(playerName, random, textBoxOnForm));
foreach (string player in opponentNames)
players.Add(newPlayer(player, random, textBoxOnForm));
books =newDictionary<Values,Player>();
stock =newDeck();Deal();
players[0].SortHand();}privatevoidDeal(){
stock.Shuffle();for(int i =0; i <5; i++)
foreach (Player player in players)
player.TakeCard(stock.Deal());
foreach (Player player in players)PullOutBooks(player);}publicboolPlayOneRound(int selectedPlayerCard){Values cardToAskFor = players[0].Peek(selectedPlayerCard).Value;for(int i =0; i < players.Count; i++){if(i ==0)
players[0].AskForACard(players,0, stock, cardToAskFor);else
players[i].AskForACard(players, i, stock);if(PullOutBooks(players[i])){
textBoxOnForm.Text+= players[i].Name+"drew a new hand"+Environment.NewLine;int card =1;while(card <=5&& stock.Count>0){
players[i].TakeCard(stock.Deal());
card++;}}
players[0].SortHand();if(stock.Count==0){
textBoxOnForm.Text="The stock is out of cards.Game over!"+Environment.NewLine;returntrue;}}returnfalse;}publicboolPullOutBooks(Player player){IEnumerable<Values> booksPulled = player.PullOutBooks();
foreach (Values value in booksPulled)
books.Add(value, player);if(player.CardCount==0)returntrue;returnfalse;}public string DescribeBooks(){
string whoHasWhichBooks ="";
foreach (Values value in books.Keys)
whoHasWhichBooks += books[value].Name+"has a book of"+Card.Plural(value)+Environment.NewLine;return whoHasWhichBooks;}public string GetWinnerName(){Dictionary<string,int> winners =newDictionary<string,int>();
foreach (Values value in books.Keys){
string name = books[value].Name;if(winners.ContainsKey(name))
winners[name]++;else
winners.Add(name,1);}int mostBooks =0;
foreach (string name in winners.Keys)if(winners[name]> mostBooks)
mostBooks = winners[name];bool tie =false;
string winnerList ="";
foreach(string name in winners.Keys)if(winners[name]== mostBooks){if(!string.IsNullOrEmpty(winnerList)){
winnerList +="and";
tie =true;}
winnerList += name;}
winnerList +="with"+ mostBooks +"books";if(tie)return"A tie between"+ winnerList;elsereturn winnerList;}publicIEnumerable<string>GetPlayerCardNames(){return players[0].GetCardNames();}public string DescribePlayerHands(){
string description ="";for(int i=0; i < players.Count; i++){
description += players[i].Name+"hase"+ players[i].CardCount;if(players[i].CardCount==1)
description +="card."+Environment.NewLine;else
description +="cards."+Environment.NewLine;}
description +="The stock has"+ stock.Count+"cards left.";return description;}}
The Program
public partial classForm1:Form{publicForm1(){InitializeComponent();}privateGame game;privatevoid buttonStart_Click(object sender,EventArgs e){if(String.IsNullOrEmpty(textName.Text)){MessageBox.Show("Please enter your name"," Can't start the game yet");return;}
game =newGame(textName.Text,newList<string>{"Joe","Bob"}, textProgress);
buttonStart.Enabled=false;
textName.Enabled=false;
buttonAsk.Enabled=true;UpdateForm();}privatevoidUpdateForm(){
listHand.Items.Clear();
foreach (String cardName in game.GetPlayerCardNames())
listHand.Items.Add(cardName);
textBooks.Text= game.DescribeBooks();
textProgress.Text+= game.DescribePlayerHands();
textProgress.SelectionStart= textProgress.Text.Length;
textProgress.ScrollToCaret();}privatevoid buttonAsk_Click(object sender,EventArgs e){
textProgress.Text="";if(listHand.SelectedIndex<0){MessageBox.Show("Please select a card");return;}if(game.PlayOneRound(listHand.SelectedIndex)){
textProgress.Text+="The winner is..."+ game.GetWinnerName();
textBooks.Text= game.DescribeBooks();
buttonAsk.Enabled=false;}elseUpdateForm();}}
The Game runs fine, but my question here is , I can't understand how the method GetWinnerName( ) in the class Game is working
In this loop
foreach (Values value in books.Keys)
{
string name = books[value].Name;
if (winners.ContainsKey(name)) //What is ContainsKey ?
winners[name]++; // What is happening here ?
else
winners.Add(name, 1); // What is happening here ?
}
WinSnap 6.2.3 by Razvan Serea
WinSnap is a fast and user-friendly utility for taking and editing screenshots. It easily captures windows with rounded corners and transparent backgrounds from Aero Glass on Windows 7 to Mica Material on Windows 11. Right after capture, WinSnap instantly enhances screenshots with professional-looking shadows, reflections, outlines, highlights, watermarks, arrows, shapes and text annotations.
WinSnap runs on Windows 11, 10, 8, 7, Vista and XP (32-bit and 64-bit). It handles Aero Glass and shadows on all supported OS. Native 64-bit version is included in the setup package.
WinSnap key features:
Flexible screen capture capabilities
Smoothing shadow effect in Photoshop style
Powerful image processing and basic canvas transformations
Support of various image formats and advanced auto-save options
Easy Web publishing and E-Mail sending
Multilingual user interface (Unicode based)
Easy makes screenshots of windows with rounded corners
WinSnap saves info about window form and adds real smoothing shadows.
Alpha-Channel and PNG/TIFF transparency are supported.
Unique "Application" capture mode allows you to capture all visible windows of the foreground application with one click.
Unique "Multi-Object" capture mode allows you to select multiple windows on the screen and easy combine them into one screenshot.
Basic coloring effects and canvas transformations.
Advanced auto-save and auto-copy options.
Configurable External Tools menu to open image editors and optimizers.
Usual keyboard and mouse control (Print Screen replacement).
Advanced resize feature: to width/height and to percentage
Outline color and larger shadows for shapes and text
Pixelate tool to hide sensitive information on screenshots
Larger icons and buttons for high-DPI screens
Number keys are used for tool selection now
WinSnap 6.2.3 changelog:
Added Czech language and polished 12 other translations
Live window resize without "Processing..." text
Optimized drawing of multiple complex objects on screenshot
Improved shadow/blur generation speed on 4k+ resolutions
Reduced memory usage in region capture mode
Fixed an issue with reflection in 24bpp format
Some other minor improvements and bug fixes
Download: WinSnap 6.2.3 | 3.6 MB (Shareware)
View: WinSnap Website | Screenshot
Get alerted to all of our Software updates on Twitter at @NeowinSoftware
Sandboxie Plus 1.17.7 / Classic 5.72.7 by Razvan Serea
Run programs in a sandbox to prevent malware from making permanent changes to your PC. Sandboxie allows you to run your browser, or any other program, so that all changes that result from the usage are kept in a sandbox environment, which can then be deleted later.
Sandboxie is a sandbox-based isolation software for 32- and 64-bit Windows NT-based operating systems. It is being developed by David Xanatos since it became open source, before that it was developed by Sophos (which acquired it from Invincea, which acquired it earlier from the original author Ronen Tzur). It creates a sandbox-like isolated operating environment in which applications can be run or installed without permanently modifying the local or mapped drive. An isolated virtual environment allows controlled testing of untrusted programs and web surfing.
Sandboxie is available in two flavors Plus and Classic. Both have the same core components, this means they have the same level of security and compatibility. What's different is the user interface the Plus build has a modern Qt based UI which supports all new features that have been added since the project went open source. The Classic build has the old no longer developed MFC based UI, hence it lacks support for modern features, these features can however still be used when manually configured in the Sandboxie.ini.
Sandboxie Plus 1.17.7 / Classic 5.72.7 release notes:
Added
added a Global Settings checkbox for ForceBoxDocs under Program Control > Force Process Options
Changed
disabled rich text acceptance in 'Edit ini Section' baa6968
extended completion system with context-aware filtering, improved INI key resolution, regex updates, and tooltip placement enhancements 6db2a04
Fixed
fixed crash in VMware when running inside sandbox caused by NtQueryDirectoryObject hook returning non-null-terminated strings and uninitialized padding bytes in OBJECT_DIRECTORY_INFORMATION structures, which caused QueryDosDeviceW to crash in wcscmp #5390
Add short-name fallback cache and heuristics #5404
fixed addon setup not working introduced in a recent build
fixed Starting from version 1.17.4, using the 'Sandbox with Data Protection' type box causes PowerShell to wait indefinitely, while there is no such bug with other types. #5408
fixed Importing encrypted box no longer creates encrypted image in v1.17.6 #5399
fixed EditorSettings fuzzy matching not applied, showing few/no completion entries, and table cell highlighting not updating
fixed Error enumerating and deleting folder. #5406
fixed black box import/export when 'ProtectAdminOnly=y' (default) and SandMan does not run as admin
Download: Sandboxie Plus (64-bit) | 23.3 MB (Open Source)
Download: Sandboxie Classic (64-bit) | 3.0 MB
Links: Sandboxie Website | GitHub | ARM64 | Screenshot
Get alerted to all of our Software updates on Twitter at @NeowinSoftware
Ocenaudio 3.19.2 by Razvan Serea
Ocenaudio is a full featured, fast and easy to use audio and music editor. It is the ideal software for people who need to edit and analyze audio files without complications. Ocenaudio also has powerful features that will please more advanced users. To assist ocenaudio development, a powerful toolset of audio editing, analysis and manipulation called Ocen Framework was created. ocenaudio is also based on Qt framework, a well known library for cross-platform development.
Cross-platform support
ocenaudio is available for all major operating systems: Microsoft Windows, Mac OS X and Linux. Native applications are generated for each platform from a common source, in order to achieve excelent performance and seamless integration with the operating system. All versions of ocenaudio have a uniform set of features and the same graphical interface, so the skills you learn in one platform can be used in the others.
VST plugins support
Ocenaudio supports VST (Virtual Studio Technology) plugins, giving its users access to numerous effects. Like the native effects, VST effects can use real-time preview to aide configuration.
Real-time preview of effects
Applying effects such as EQ, gain and filtering is an important part of audio editing. However, it is very tricky to get the desired result by adjusting the controls configuration alone: you must listen the processed audio. To ease the configuration of audio effects, ocenaudio has a real time preview feature: you hear the processed signal while adjusting the controls. The effect configuration window also includes a miniature view of the selected audio signal. You can navigate on this miniature view in the same way as you do on the main interface, selecting parts that interest you and listening to the effect result in real time.
Multiselection for delicate editions
To speed up complex audio files editing, ocenaudio includes multi-selection. With this amazing tool, you can simultaneously select different portions of an audio file and listen, edit or even apply an effect to them. For example, if you want to normalize only the excerpts of an interview where the interviewee is talking, just select them and apply the effect.
Eficient edition of large files
With ocenaudio, there is no limit to the length or the quantity of the audio files you can edit. Using an advanced memory management system, the application keeps your files open without wasting any of your computer's memory. Even in files several hours long, common editing operations such as copy, cut or paste happen almost instantly.
Fully featured spectrogram
Besides offering an incredible waveform view of your audio files, ocenaudio has a powerful and complete spectrogram view. In this view, you can analyze the spectral content of your audio signal with maximum clarity. Advanced users will be surprised to find that the spectrogram settings are applied in real time. The display is updated immediately when altering features such as the number of frequency bands, window type and size and dynamic range of the display.
Ocenaudio 3.19.2 changelog:
Fixes a crash when starting the graphical interface without a display on Linux
Fixes MP3 metadata encoding and ID3 tag writing issues on Windows
Fixes a crash when loading audio with autosave enabled on Windows user paths containing non-ASCII characters
Fixes a freeze when batch-processing more than 5 files with a 64-bit VST plugin
Fixes some conditions in audio mixer
Fixes loudness statistics for surround files and Short-Term Maximum Loudness accuracy
Other bug fixes and improvements
Download: Ocenaudio 64-bit | Portable | ~40.0 MB (Freeware)
Download: Ocenaudio for Linux and Mac OS
View: Ocenaudio Homepage | Screenshot
Get alerted to all of our Software updates on Twitter at @NeowinSoftware
AnyDesk 9.7.5 by Razvan Serea
AnyDesk is a fast remote desktop system and enables users to access their data, images, videos and applications from anywhere and at any time, and also to share it with others. AnyDesk is the first remote desktop software that doesn't require you to think about what you can do. CAD, video editing or simply working comfortably with an office suite for hours are just a few examples. AnyDesk is designed for modern multi-core CPUs. Most of AnyDesk's image processing is done concurrently. This way, AnyDesk can utilize up to 90% of modern CPUs. AnyDesk works across multiple platforms and operating systems: Windows, Linux, Free BSD, Mac OS, iOS and Android.
Just 7 megabytes - downloaded in a glimpse, sent via email, or fired up from your USB drive, AnyDesk will turn any desktop into your desktop in seconds. No administrative privileges or installation needed.
AnyDesk 9.7.5 changelog:
Fixed an issue where AnyDesk One windows would open in inconsistent positions
Optimized dB bar rendering by synchronizing updates with the render timer
Fixed a crash related to high volumes of incoming messages
Fixed a crash that could occur when closing AnyDesk One from the tray icon
Fixed an issue where certain special characters could disappear when formatting text in Chat
Moved the "Jump to Newest Message" button to improve usability in Chat
Improved notification delivery speed after sending a message in Chat
Improved overall application stability
Download: AnyDesk 9.7.5 | 8.0 MB (Free for private use, paid upgrade available)
Links: AnyDesk Home Page | Other platforms | Release History | Screenshot
Get alerted to all of our Software updates on Twitter at @NeowinSoftware
You get the latest James Bond game free with this Nvidia RTX 5060 Ti deal all for $330 by Sayan Sen Last week released its Radeon RX 9070 GRE 1440p gaming GPU for $549 (check our review here). If you can find it for that price, it's a decent deal. However in case you want to do 1080p gaming and don't want to spend much more than $300, then the MSI Ventus 3X GeForce RTX 5060 Ti 8GB is a great option as it's currently on sale for just $330 thanks to a coupon (purchase link under the specs table down below). With this you will get close to around 80% of the GRE's performance at a much lower price.
The Ventus 3X line is known for its straightforward design. Here, MSI uses three of its TORX 5.0 axial fan systems, where linked fan blades are intended to stabilise airflow and maintain consistent cooling. A metal backplate with cutouts should help with heat dissipation while also reinforcing the card’s structure. The card’s shroud design is kept neutral in appearance, so it can blend into a wide range of builds without drawing attention.
The technical specifications of the MSI Ventus 3X OC RTX 5060 Ti 8GB are given in the table below:
Specification
Value
Model Name
G506T-8V3C
Interface
PCI Express® Gen 5 x16 (uses x8)
Core Clock (Extreme Performance)
2617 MHz (via MSI Center)
Core Clock (Boost)
2602 MHz
CUDA Cores
4608
Memory Speed
28 Gbps
Memory Capacity
8GB GDDR7
Memory Bus
128-bit
Display Outputs
3 × DisplayPort 2.1b
1 × HDMI 2.1b (up to 4K 480Hz or 8K 120Hz with DSC, Gaming VRR, HDR)
HDCP Support
Yes
Power Consumption
180 W
Power Connector
1 × 8-pin
Recommended PSU
600 W
Card Dimensions
304 × 121 × 44 mm
Maximum Displays
4
Maximum Digital Resolution
7680 × 4320
Get it at the link below:
MSI Ventus 3X OC GeForce RTX 5060 Ti 8GB GDDR7 (G506T-8V3C) + free 007 First Light (our review) bundle: $329.99 (with $50 promo code) (Sold and Shipped by Newegg US)
This Newegg deal is US-specific and not available in other regions unless specified. This is a first-party seller link (at the time of article publishing); ensure that you also purchase from a first-party seller link only.
If you don't like it or want to look at more options, check out the previous deals that we have covered, OR you can also visit Amazon US deals page.
Get Prime (SNAP), Prime Video, Audible Plus or Kindle / Music Unlimited. Free for 30 days.
As an Amazon Associate, we earn from qualifying purchases.
Question
Ch33f
The Form has 4 classes Card, Deck , Player and Game, game being the class that runs everything
The form has 3 TextBox named textName, textBooks and textProgress , ListBox named listHand, 2 buttons named buttonStart and buttonAsk
Card
Deck
Player
Game
The Program
The Game runs fine, but my question here is , I can't understand how the method GetWinnerName( ) in the class Game is working
In this loop
foreach (Values value in books.Keys)
{
string name = books[value].Name;
if (winners.ContainsKey(name)) //What is ContainsKey ?
winners[name]++; // What is happening here ?
else
winners.Add(name, 1); // What is happening here ?
}
Link to comment
https://www.neowin.net/forum/topic/1328866-having-problems-understanding-how-dictionary-is-working-in-this-program/Share on other sites
2 answers to this question
Recommended Posts