Click here to Skip to main content
15,064,072 members

Comments by Alexander Sanchez 2021 (Top 27 by date)

Alexander Sanchez 2021 9-Oct-21 15:03pm View
   
Thanks, I reading it right now! You are right, you talked to me about this before. Thanks.
Alexander Sanchez 2021 9-Oct-21 13:56pm View
   
Nothing, is working as expected (apparently), but is not using all the cards, just the first 26 cards of the deck and is repeating cards, I just need your advise for that and on Removing Duplicates from a List in C#. Thanks
Alexander Sanchez 2021 9-Oct-21 13:52pm View
   
I have spent days checking codes websites and I have found some advises, but none of them seems to be useful for my code. Thanks
/// pick The fourth random card for player 1

Card c3 = deckOfPlayer1[3];

// pick The fourth random card for player 2

Card c4 = deckOfPlayer2[3];


if (c3.Value > c4.Value )
{

deckOfPlayer1.Add(c2);
deckOfPlayer2.Remove(c2);
deckOfPlayer1.Add(c1);
deckOfPlayer1.Remove(c1);

Card card1 = deckOfPlayer1[1];
deckOfPlayer1.Add(card1);
Card card2 = deckOfPlayer1[2];
deckOfPlayer1.Add(card2);
Card card3 = deckOfPlayer1[3];
deckOfPlayer1.Add(card3);

deckOfPlayer2.Remove(card1);
deckOfPlayer2.Remove(card2);
deckOfPlayer2.Remove(card3);

}
else
{

deckOfPlayer2.Add(c1);
deckOfPlayer1.Remove(c1);
deckOfPlayer1.Add(c2);
deckOfPlayer2.Remove(c2);

Card card1 = deckOfPlayer1[1];
deckOfPlayer1.Add(card1);
Card card2 = deckOfPlayer1[2];
deckOfPlayer1.Add(card2);
Card card3 = deckOfPlayer1[3];
deckOfPlayer1.Add(card3);

deckOfPlayer2.Remove(card1);
deckOfPlayer2.Remove(card2);
deckOfPlayer2.Remove(card3);
}


}
if (deckOfPlayer1.Count == 52)
{
label6.Text = ($"Player1 is the Final Winner with {deckOfPlayer1.Count} cards ");
button1.Enabled = false;
}
if (deckOfPlayer2.Count == 52)
{
label6.Text = ($"Player2 is the Final Winner with {deckOfPlayer2.Count} cards ");
button1.Enabled = false;
}

}
Alexander Sanchez 2021 9-Oct-21 13:46pm View
   
new Card{Name="jack",Value=11,Suit="Clubs"},
new Card{Name="queen",Value=12,Suit="Clubs"},
new Card { Name="king", Value=13, Suit="Clubs"},
new Card { Name=" ♣Ace", Value=14, Suit="Clubs"},

};

List<card> deckOfPlayer1 = new List<card>();
List<card> deckOfPlayer2 = new List<card>();

public Form1()
{

InitializeComponent();

int count = DeckOfCard.Count;


for (int i = 0; i < DeckOfCard.Count ; i ++)
{

label7.Text = ($" We have {DeckOfCard.Count} cards for this game, let's flip cards ");

}

Random random = new Random();
for (int i = 0; i < 26; i++)
{
//Card card = new Card();
//card = DeckOfCard[random.Next(26)];

deckOfPlayer1.Add(DeckOfCard[random.Next(26)]);
deckOfPlayer2.Add(DeckOfCard[random.Next(26)]);


label1.Text = ($"Player1 has {deckOfPlayer1.Count} ");
label2.Text = ($"Player2 has {deckOfPlayer2.Count}");
}


}

private void Form1_Load(object sender, EventArgs e)
{

}

private void label1_Click(object sender, EventArgs e)
{

}

private void label2_Click(object sender, EventArgs e)
{

}

private void button1_Click(object sender, EventArgs e)
{

label1.Text = "";
label2.Text = "";
label3.Text = "";
label4.Text = "";
label5.Text = "";
label7.Text = "";

// pick The TOP random card for player 1

Card c1 = deckOfPlayer1[0];


// pick The Top random card for player 2

Card c2 = deckOfPlayer2[0];



if (c1.Value > c2.Value)
{

label1.Text = ($"Player1 wins with {c1} as the top card");
label2.Text = ($"Player2 lost with {c2} as the top card");
deckOfPlayer1.Add(c2);
deckOfPlayer2.Remove(c2);
deckOfPlayer1.Add(c1);
deckOfPlayer1.Remove(c1);
label3.Text = ($"Player1 has {deckOfPlayer1.Count} ");
label4.Text = ($"Player2 has {deckOfPlayer2.Count}");
}
else if (c2.Value > c1.Value)
{
label2.Text = ($"Player2 wins with {c2} as the top card the top card");
label1.Text = ($"Player1 lost with {c1} as the top card the top card");
deckOfPlayer2.Add(c1);
deckOfPlayer1.Remove(c1);
deckOfPlayer2.Add(c2);
deckOfPlayer2.Remove(c2);
label3.Text = ($"Player1 has {deckOfPlayer1.Count} ");
label4.Text = ($"Player2 has {deckOfPlayer2.Count}");
}

else if (c2.Value == c1.Value)
{

label1.Text = ($"Player1 has {deckOfPlayer1[0].Name}{deckOfPlayer1[0].Suit} {deckOfPlayer1[0].Value}");
label2.Text = ($"Player2 has {deckOfPlayer2[0].Name}{deckOfPlayer2[0].Suit} {deckOfPlayer2[0].Value}");

label5.Text = ("Its a tie! Next three cards in deck are played face down, " +
"4th card face up, whoever has the highest card wins");

if (deckOfPlayer1.Count < 4 && deckOfPlayer2.Count < 4)
{
button1.Enabled = false;
}

/// pick The
Alexander Sanchez 2021 9-Oct-21 13:44pm View
   
using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using System.Windows.Forms;

namespace Wargame2
{

public partial class Form1 : Form
{
class Card
{
public string Name;
public int Value;
public string Suit;
public override string ToString() { return string.Format("{0} of {1}", Name, Suit); }
public const int NCARDS = 52;

}
static List<card> DeckOfCard {get; set;}=new List<card>
{

new Card{Name=" two",Value=2,Suit=" ♣ Heart"},
new Card{Name=" three",Value=3,Suit=" ♣ Heart"},
new Card{Name=" four",Value=4,Suit=" ♣ Heart"},
new Card{Name="five", Value=5, Suit=" ♣ Heart"},
new Card{Name=" six",Value=6,Suit=" ♣ Heart"},
new Card{Name="seven",Value=7,Suit=" ♣ Heart"},
new Card{Name="eight",Value=8,Suit=" ♣ Heart"},
new Card { Name="Nine", Value=9, Suit=" ♣ heart"},
new Card{Name="ten",Value=10,Suit=" ♣ Heart"},
new Card{Name="jack",Value=11,Suit=" ♣ Heart"},
new Card{Name="queen",Value=12,Suit=" ♣ Heart"},
new Card { Name="king", Value=13, Suit=" ♣ heart"},
new Card { Name="Ace", Value=14, Suit=" ♣ Heart"},


new Card{Name="two",Value=2,Suit="Spades"},
new Card{Name="three",Value=3,Suit="Spades"},
new Card{Name="four",Value=4,Suit="Spades"},
new Card { Name="five", Value=5, Suit="Spades"},
new Card{Name="six",Value=6,Suit="Spades"},
new Card{Name="seven",Value=7,Suit="Spades"},
new Card{Name="eight",Value=8,Suit="Spades"},
new Card { Name="Nine", Value=9, Suit="Spades"},
new Card{Name="ten",Value=10,Suit="Spades"},
new Card{Name="jack",Value=11,Suit="Spades"},
new Card{Name="queen",Value=12,Suit="Spades"},
new Card { Name="king", Value=13, Suit="Spades"},
new Card { Name="Ace", Value=14, Suit="Spades"},


new Card{Name="two",Value=2,Suit="Diamonds"},
new Card{Name="three",Value=3,Suit="Diamonds"},
new Card{Name="four",Value=4,Suit="Diamonds"},
new Card { Name="five", Value=5, Suit="Diamonds"},
new Card{Name="six",Value=6,Suit="Diamonds"},
new Card{Name="seven",Value=7,Suit="Diamonds"},
new Card{Name="eight",Value=8,Suit="Diamonds"},
new Card { Name="Nine", Value=9, Suit="Diamonds"},
new Card{Name="ten",Value=10,Suit="Diamonds"},
new Card{Name="jack",Value=11,Suit="Diamonds"},
new Card{Name="queen",Value=12,Suit="Diamonds"},
new Card { Name="king", Value=13, Suit="Diamonds"},
new Card { Name="Ace", Value=14, Suit="Diamonds"},

new Card{Name="two",Value=2,Suit="Clubs"},
new Card{Name="three",Value=3,Suit="Clubs"},
new Card{Name="four",Value=4,Suit="Clubs"},
new Card { Name="five", Value=5, Suit="Clubs"},
new Card{Name="six",Value=6,Suit="Clubs"},
new Card{Name="seven",Value=7,Suit="Clubs"},
new Card{Name="eight",Value=8,Suit="Clubs"},
new Card { Name="Nine", Value=9, Suit="Clubs"},
new Card{Name="ten",Value=10,Suit="Clubs"},
Alexander Sanchez 2021 9-Oct-21 13:41pm View
   
Sorry, You right. I didn't send the code because I didn't want to bother you on taking much time analyzing it, You are probably busy or enjoying your weekend. Essentially, is working good, and at the end, eventually is giving a winner, but I realized that is just using the first 26 cards (Hearts and spades), and it repeats the cards. Anyway, I am sending it right away.Thanks.
Alexander Sanchez 2021 9-Oct-21 11:08am View
   
Dear Mr.OriginalGriff:
Good morning
I did the changes you advised me to do in my card war game, but my car game still have two issues: The 2 Players are just using the first 26 cards and they both continue using duplicate cards. Could you help me, please? Thanks
Alexander Sanchez 2021 1-Oct-21 23:41pm View
   
Dear BillWoodruff :
Because it worked perfect at that moment on a console, but now I am trying to make it work in a GUI and for some reason that I don't know is not working.
Thanks
Alexander Sanchez 2021 1-Oct-21 20:42pm View
   
I commented out the Part of the "Its a tie! Next three cards in deck are played face down, 4th card face up, whoever has the highest card wins" and the codes that follows it and now is like stuck, when compiling button is pressed is doing nothing. Thanks
Alexander Sanchez 2021 1-Oct-21 20:36pm View
   
Good question!, but, I sincerely don't know. Sorry. It's never mentioned in the rules of the game.

The rules are There are 52 cards in a deck. 1-10, Jack, Queen, King, Ace (Ace is the highest card) War is a 2players game, each player starts with 26 cards (half the deck)
The game starts with each player flipping over 1 card and whomever has the highest card wins. The winner receives the other players card.
If there is a tie, the next three cards in your deck are played face down and the 4th card dealt face up, whomever has the highest card wins. The winner receives all of the cards played.
The game is played until 1 player has all of the cards
I have never thought of that question, so do you think I must create some code in the loop for that case, too?
Alexander Sanchez 2021 1-Oct-21 18:00pm View
   
Thank you!
Alexander Sanchez 2021 1-Oct-21 14:25pm View
   
Dear Mr.OriginalGriff

Thank you for your answer, I really appreciate it. Of course, that I accept your constructive criticism. You are welcome to give me any, YES, please!

1- You typed “stop using Visual Studio default names for everything” …"TextBox8 is the mobile number today, but when you have to modify it in three weeks’ time, will you then? Use descriptive names - "tbMobileNo" for example - and your code becomes easier to read, more self documenting, easier to maintain - and surprisingly quicker to code because Intellisense can get to to "tbMobile" in three keystrokes, where "TextBox8" takes thinking about and 8 keystrokes...
Call it "button3" and I have no idea what it does without looking closely. As "butDealCardsToAllPlayers" it's very obvious. This applies to all controls, not just buttons!”
Sorry, I kind of understand a little what you mean, but could you be more explanatory, please!! Explain it like I am a 6th grade boy, please. What do you mean with"TextBox8 is the mobile number today (?), but when you have to modify it in three weeks’ time, will you then?”, Please?
SORRY, please, I am not familiar with Software developer’s Slang. THANKS.
2-Additionally (Sorry, please) what do you mean when you typed “Don't declare a Random as a local variable: declare one Random object as a private class level variable, and use that throughout. Each time you create an instance of Random, it is initialized from the system clock - so if two methods get executed close together and they both create their own Random, they can get the same sequence of numbers.” Could you give me an example of this , please? thanks
Alexander Sanchez 2021 23-Sep-21 11:24am View
   
This is the continuation of the code. Space issues.

}
while (dealer == player);

}
public void button3_Click(object sender, EventArgs e)
{
Random random = new Random();
int dealer = random.Next(1, 10);

int player = random.Next(1, 10);

int randomNumber = random.Next(1, 10);
player += randomNumber;

PlayGame(dealer, player);

}

private void button4_Click(object sender, EventArgs e)
{

Random random = new Random();
int dealer = random.Next(1, 10);

int player = random.Next(1, 10);

int randomNumber = random.Next(1, 10);
player += randomNumber;

PlayGame(dealer, player);
}

private void label2_Click_1(object sender, EventArgs e)
{

}

private void button5_Click(object sender, EventArgs e)
{
label1.Text = "";
label2.Text = "";
label3.Text = "";
label4.Text = "";
}

private void button6_Click(object sender, EventArgs e)
{
List<card> DeckOfCards = new List<card>()
{

new Card{Name="two",Value=2,Suit="Heart"},
new Card{Name="three",Value=3,Suit="Heart"},
new Card{Name="four",Value=4,Suit="Heart"},
new Card{Name = "five", Value = 5, Suit = "Heart" },
new Card{Name = "six", Value = 6, Suit = "Heart" },
new Card{Name = "seven", Value = 7, Suit = "Heart" },
new Card{Name = "eight", Value = 8, Suit = "Heart" },
new Card{Name = "Nine", Value = 9, Suit = "heart" },
new Card{Name = "ten", Value = 10, Suit = "Heart" },

new Card { Name = "two", Value = 2, Suit = "Spades" },
new Card { Name = "three", Value = 3, Suit = "Spades" },
new Card { Name = "four", Value = 4, Suit = "Spades" },
new Card { Name = "five", Value = 5, Suit = "Spades" },
new Card { Name = "six", Value = 6, Suit = "Spades" },
new Card { Name = "seven", Value = 7, Suit = "Spades" },
new Card { Name = "eight", Value = 8, Suit = "Spades" },
new Card { Name = "Nine", Value = 9, Suit = "Spades" },
new Card { Name = "ten", Value = 10, Suit = "Spades" },


new Card { Name = "two", Value = 2, Suit = "Diamonds" },
new Card { Name = "three", Value = 3, Suit = "Diamonds" },
new Card { Name = "four", Value = 4, Suit = "Diamonds" },
new Card { Name = "five", Value = 5, Suit = "Diamonds" },
new Card { Name = "six", Value = 6, Suit = "Diamonds" },
new Card { Name = "seven", Value = 7, Suit = "Diamonds" },
new Card { Name = "eight", Value = 8, Suit = "Diamonds" },
new Card { Name = "Nine", Value = 9, Suit = "Diamonds" },
new Card { Name = "ten", Value = 10, Suit = "Diamonds" },


new Card { Name = "two", Value = 2, Suit = "Clubs" },
new Card { Name = "three", Value = 3, Suit = "Clubs" },
new Card { Name = "four", Value = 4, Suit = "Clubs" },
new Card { Name = "five", Value = 5, Suit = "Clubs" },
new Card { Name = "six", Value = 6, Suit = "Clubs" },
new Card { Name = "seven", Value = 7, Suit = "Clubs" },
new Car
Alexander Sanchez 2021 23-Sep-21 11:21am View
   
Mr. OrginalGriff, I keep my promised to show you my code when finished. Thanks

using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using System.Windows.Forms;
namespace GUI_BLACKJACK
{
public partial class Form1 : Form
{

public object DeckOfCards { get; private set; }

class Card
{

public string Name;
public int Value;
public string Suit;
public override string ToString() { return string.Format("{0} of {1}", Name, Suit); }

}

public Form1()
{
InitializeComponent();
}

private void Form1_Load(object sender, EventArgs e)
{

}

private void label2_Click(object sender, EventArgs e)
{

}

private void label1_Click(object sender, EventArgs e)
{

}

private void button1_Click(object sender, EventArgs e)
{

Random random = new Random();

int dealer = random.Next(1, 10);

int player = random.Next(1, 10);


label4.Text = ($"Let's play a modified version of the card game blackjack," +
$" The dealer is showing a {dealer}, the other card is hidden");

label1.Text = ("you were dealt 2 cards that total " + player);
}
private void label3_Click(object sender, EventArgs e)
{

}

private void button2_Click(object sender, EventArgs e)
{
label4.Text = ("Do you want another card? Type [Y]es or [N]o");

}

private void label6_Click(object sender, EventArgs e)
{

}

public string PlayGame(int dealer, int player)
{

do
{

string response = "";

if (player <= 21 && dealer > 21)
{
label1.Text = ($"You WON with {player}");
label2.Text = ($"The dealer ended with {dealer}");

}

else if (player < 21 && dealer < 21 && dealer > player)
{
label1.Text = ($"You lost with {player} ");
label2.Text = ($"The dealer ended with {dealer}");
}

else if (player < 21 && dealer < 21 && player > dealer)
{
label1.Text = ($"You WON with {player} ");
label2.Text = ($"The dealer ended with {dealer}");
}

else if (player > 21 && dealer < player)
{
label1.Text = ($"You lost with {player}");
label2.Text = ($"The dealer ended with {dealer}");
}
else if (player == 21 && dealer < player)
{
label1.Text = ($"You WON with {player}");
label2.Text = ($"The dealer ended with {dealer}");
}
else if (player > 21)
{
label1.Text = ($"You lost with {player}");
label2.Text = ($"The dealer ended with {dealer}");
}

{
return response;
}


}
while (dealer == player);

}
public void button3_Click(object sender, EventArgs e)
{
Alexander Sanchez 2021 23-Sep-21 11:15am View
   
Deleted
Mr. OroginalGriff, as promised to show you my code when finisehed, my code is done and working as expected. I keep my promise. Thanks

using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using System.Windows.Forms;
namespace GUI_BLACKJACK
{
public partial class Form1 : Form
{

public object DeckOfCards { get; private set; }

class Card
{

public string Name;
public int Value;
public string Suit;
public override string ToString() { return string.Format("{0} of {1}", Name, Suit); }

}

public Form1()
{
InitializeComponent();
}

private void Form1_Load(object sender, EventArgs e)
{

}

private void label2_Click(object sender, EventArgs e)
{

}

private void label1_Click(object sender, EventArgs e)
{

}

private void button1_Click(object sender, EventArgs e)
{

Random random = new Random();

int dealer = random.Next(1, 10);

int player = random.Next(1, 10);


label4.Text = ($"Let's play a modified version of the card game blackjack," +
$" The dealer is showing a {dealer}, the other card is hidden");

label1.Text = ("you were dealt 2 cards that total " + player);
}
private void label3_Click(object sender, EventArgs e)
{

}

private void button2_Click(object sender, EventArgs e)
{
label4.Text = ("Do you want another card? Type [Y]es or [N]o");

}

private void label6_Click(object sender, EventArgs e)
{

}

public string PlayGame(int dealer, int player)
{

do
{

string response = "";

if (player <= 21 && dealer > 21)
{
label1.Text = ($"You WON with {player}");
label2.Text = ($"The dealer ended with {dealer}");

}

else if (player < 21 && dealer < 21 && dealer > player)
{
label1.Text = ($"You lost with {player} ");
label2.Text = ($"The dealer ended with {dealer}");
}

else if (player < 21 && dealer < 21 && player > dealer)
{
label1.Text = ($"You WON with {player} ");
label2.Text = ($"The dealer ended with {dealer}");
}

else if (player > 21 && dealer < player)
{
label1.Text = ($"You lost with {player}");
label2.Text = ($"The dealer ended with {dealer}");
}
else if (player == 21 && dealer < player)
{
label1.Text = ($"You WON with {player}");
label2.Text = ($"The dealer ended with {dealer}");
}
else if (player > 21)
{
label1.Text = ($"You lost with {player}");
label2.Text = ($"The dealer ended with {dealer}");
}

{
return response;
}


}
while (dealer == player);

}
public void button3_Click
Alexander Sanchez 2021 17-Sep-21 12:07pm View
   
Thank you for your guide, MR OriginalGriff, I will follow all of your advises, I am reading the Farrell C# (our text Book), too. You are right and I have realized that the Console is quite different from GUI. I started learn C# GUI first time in my life a couple of months ago. As soon as I come up with the final product, you will be first one to see it. I need to continue working on it, and I wont do that again, to copy and paste, not even my own worked code, is not a good way to learn coding. Thanks
Alexander Sanchez 2021 17-Sep-21 11:13am View
   
Because I am new in this world, I just started to learn how to code a few months ago, Mr. OriginalGriff, and I still don't have the amazing experience and "reflexes" and "the mindset" that you were born with, and to clarify: This code I did all my myself, in Console, it worked perfect, but then, I copied part of it and paste it to adapt it for making a GUI.
Alexander Sanchez 2021 17-Sep-21 10:54am View
   
Why are you doubting yourself that I wrote all my code by my own effort? Do you know me? You are guessing very wrong, I wrote all of that code my self.
Alexander Sanchez 2021 17-Sep-21 10:04am View
   
Dear OriginalGiff
Thank you for your answer and ideas. One more question, please: In addition to study hard and practice, how could I become a good programmer? Any tips ?
Thanks
Alexander Sanchez 2021 22-Jul-21 18:24pm View
   
Hello, OriginalGriff!
So, the loop is not needed?
Thanks
Alexander Sanchez 2021 22-Jul-21 12:45pm View
   
Thank you, OriginalGriff!
Alexander Sanchez 2021 22-Jul-21 12:44pm View
   
Thanks, Dave!
Alexander Sanchez 2021 23-Apr-21 10:03am View
   
Mr. Chill60
I think your logic is better than mine, I am probably not handling Aces properly. Instead of checking for Card.value = 1 (and then ignoring the Ace altogether) I will just give the Aces a value of 14 - one higher than a King.
Thanks
Alexander
Alexander Sanchez 2021 23-Apr-21 10:00am View
   
Good morning
I followed Mr. Pallini's advise and it really worked. The issue is that I tried to add more items to the programs like checking how many cards each one of the players have on hand at the beginning of the game and I noticed that they didn't have 26 each as planned. That is the main issue, everything else is ok. Thanks, MrChill60
Alexander Sanchez 2021 17-Apr-21 11:24am View
   
What is the OP?
Alexander Sanchez 2021 16-Apr-21 20:14pm View
   
Thank you very much, Mr.Pallini! It worked, you are amazing!
Alexander Sanchez 2021 16-Apr-21 20:13pm View
   
Thank you.