-
Aug 20th, 2013, 01:04 AM
#1
Thread Starter
Member
I need help with my Texas HoldEm program.
Hello, I am trying to make a Texas HoldEm program and I need a little help with generating the cards.
When the play presses Button1 I want it to randomly generate 2 cards. These cards will generate in TextBox1 and TextBox2.
This is all I have so far. (I know, it's pathetic.)
Code:
Dim Rand As New Random
Dim Cards As String = ("A, 2, 3, 4, 5, 6, 7, 8, 9, 10, J, Q, K")
Private Sub Button1_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button1.Click
End Sub
Any help is appreciated. I am not good with VB.NET at all. (Yet.)
-
Aug 20th, 2013, 02:06 AM
#2
Re: I need help with my Texas HoldEm program.
Follow the CodeBank link in my signature and check out the two threads there on selecting random items from lists.
-
Aug 20th, 2013, 09:39 PM
#3
Thread Starter
Member
Re: I need help with my Texas HoldEm program.
I still don't understand, I read through your threads but they are too confusing to me. I am only a beginner.
-
Aug 20th, 2013, 10:10 PM
#4
Re: I need help with my Texas HoldEm program.
Did you actually try executing the code to see what it did? What exactly confused you? I'm afraid that it doesn't get too much simpler than what I provided there so you need to suck it up and learn. If you can indicate exactly what the stumbling block was then I can try to explain in more detail but I'm not going to just explain again what I've already explained with no particular indication that you'd understand that either.
-
Aug 22nd, 2013, 01:43 AM
#5
Thread Starter
Member
Re: I need help with my Texas HoldEm program.
Originally Posted by jmcilhinney
Did you actually try executing the code to see what it did? What exactly confused you? I'm afraid that it doesn't get too much simpler than what I provided there so you need to suck it up and learn. If you can indicate exactly what the stumbling block was then I can try to explain in more detail but I'm not going to just explain again what I've already explained with no particular indication that you'd understand that either.
I read through all of it, and I understand it.
I am trying to make it so that when you press Button1 you will get 2 "cards" from [A-2-3-4-5-6-7-8-9-10-J-Q-K] and each one of these cards have 4 different backcolors.
I understand your code, I am just not sure how to implement my idea into your code. That is what I am trying to get help with.
-
Aug 22nd, 2013, 02:16 AM
#6
Re: I need help with my Texas HoldEm program.
Originally Posted by Flavor Flav
I understand your code, I am just not sure how to implement my idea into your code. That is what I am trying to get help with.
Maybe that's what you should have said in the first place then, instead of saying that you didn't understand it when you actually did. I'm not going to simply divine things like that. I only know what you tell me.
Anyway, use the extension method provided in the thread on randomising a list. Create your array of all cards, call that Randomise method on that, call Take on the result and specify the number of items that you want to take from the randomised list, i.e. 2, and then call ToArray on the result. That will give you an array containing two random cards and you can do with them what you will.
-
Aug 22nd, 2013, 02:37 AM
#7
Thread Starter
Member
Re: I need help with my Texas HoldEm program.
Originally Posted by jmcilhinney
Maybe that's what you should have said in the first place then, instead of saying that you didn't understand it when you actually did. I'm not going to simply divine things like that. I only know what you tell me.
Anyway, use the extension method provided in the thread on randomising a list. Create your array of all cards, call that Randomise method on that, call Take on the result and specify the number of items that you want to take from the randomised list, i.e. 2, and then call ToArray on the result. That will give you an array containing two random cards and you can do with them what you will.
A noob like me has no idea what you just said. I am thankful you are helping but I don't understand.
-
Aug 22nd, 2013, 02:43 AM
#8
Re: I need help with my Texas HoldEm program.
Are you saying that you don't know how to call a method?
-
Aug 22nd, 2013, 08:11 AM
#9
Hyperactive Member
Re: I need help with my Texas HoldEm program.
I'll assume you read the codebank on Randoms and understand how they work. I'll also assume that you know how arrays work...
The simplest form of taking a Random is to pull the item at a random index of the array. I assume that you know how arrays are indexed? So, initialize a class level Random variable in your Form_Load method. Then, call randomVariableYouSet.Random(0,array.Length) to pick a random index value of the current array. Remove the item from the array, and do it again. This will leave you with your original array - the 2 randomly picked elements (ie your cards).
-
Aug 24th, 2013, 01:49 PM
#10
Thread Starter
Member
Re: I need help with my Texas HoldEm program.
Ok, so instead of me wanting to randomize the number and the backcolor of the textbox I just made 52 pictureboxes and inside of them are cards i made in photoshop.
How would i randomize these pictureboxes now...?
-
Aug 24th, 2013, 02:23 PM
#11
Re: I need help with my Texas HoldEm program.
For Texas Hold'em you won't need to show 52 cards at one time. 5 common cards + 2 additional for each player.
Have you looked at the CardGameStarterKit for MS?
-
Aug 24th, 2013, 10:42 PM
#12
Re: I need help with my Texas HoldEm program.
Originally Posted by Flavor Flav
Ok, so instead of me wanting to randomize the number and the backcolor of the textbox I just made 52 pictureboxes and inside of them are cards i made in photoshop.
How would i randomize these pictureboxes now...?
Even though it's not really the right question, I'll answer that anyway. You already have everything you need in the CodeBank threads I've already directed you to. If you have 52 Images and 52 PictureBoxes then you would put the Images in a list and then randomise it exactly as I demonstrate in one of my CodeBank threads. You can put those randomised Images into an array by calling ToArray on the result of OrderBy and you can put the PictureBoxes into an array too. Tada! You have two arrays each with 52 elements. You can now use a For loop to assign each Image in one array to the Image property of the PictureBox at the same index in the other array.
You seem determined to look at what you're doing as some special case that is somehow fundamentally different to other such cases. It's not. I've shown you how to randomise a list and I've shown you how to make unique, random selections from a list. What that list contains and what those items will be used for is COMPLETELY IRRELEVANT to the act of randomising them.
If you want to make this more realistic then would not be showing 52 cards at the same time. What you would more likely do would be to store your card objects in a list and then "shuffle" them, which is exactly what the randomising techniques that I've demonstrated correlate to. Just like a real card game, you would then "deal" the cards, which would involve getting a card object from the randomised list and putting into another list that represents a player's hand. For example, here's some code that shuffles a deck of Card objects and deals them out to four players, five cards to a player:
vb.net Code:
Private rng As New Random Private Sub InitiateGame() Dim deck = GetShuffledDeck() Dim hand1 As New List(Of Card) Dim hand2 As New List(Of Card) Dim hand3 As New List(Of Card) Dim hand4 As New List(Of Card) Deal(deck, 5, hand1, hand2, hand3, hand4) '... End Sub Private Function GetShuffledDeck() As List(Of Card) Dim deck = Enumerable.Range(1, 52).Select(Function(i) New Card).ToList() ShuffleDeck(deck) Return deck End Function Private Sub ShuffleDeck(deck As List(Of Card)) Dim shuffledDeck = deck.OrderBy(Function(c) Me.rng.NextDouble()).ToArray() For i = 0 To shuffledDeck.GetUpperBound(0) deck(i) = shuffledDeck(i) Next End Sub Private Sub Deal(deck As List(Of Card), cardCount As Integer, ParamArray hands As List(Of Card)()) For i = 1 To cardCount For Each hand In hands Dim card = deck(0) deck.RemoveAt(0) hand.Add(card) Next Next End Sub
That's a bit of a simplification but, again, it shows how your specific case is inherently based on the general case. You start with the general case and then you add and modify details to match your particular needs.
-
Aug 25th, 2013, 03:29 AM
#13
Thread Starter
Member
Re: I need help with my Texas HoldEm program.
Ugh, I really want to make this game but I don't understand at all what you guys are teaching me.
It's like trying to teach me calculus even though I'm in grade 3.
-
Aug 25th, 2013, 03:43 AM
#14
Re: I need help with my Texas HoldEm program.
I'd be inclined to say that you're having trouble with the LINQ part, which is something that you would not have encountered before, except that my CodeBank on Unique Random Selections doesn't include any LINQ and was, in fact, written before LINQ even existed. Using that thread (http://www.vbforums.com/showthread.p...ns-from-a-List) as a basis, what exactly is your issue? For instance, if you had a deck of cards, what exactly is stopping you using that code to select, say, 5 cards at random from that deck to make a hand?
-
Aug 25th, 2013, 02:34 PM
#15
Thread Starter
Member
Re: I need help with my Texas HoldEm program.
I don't understand a lot of what the code is doing. I am not that experienced with VB.
-
Aug 25th, 2013, 07:29 PM
#16
Re: I need help with my Texas HoldEm program.
Originally Posted by Flavor Flav
I don't understand a lot of what the code is doing. I am not that experienced with VB.
The code is about as simple as it can be for what it does and it has comments all through it so I'm afraid that, if you don't understand it and you can tell me what you don't understand, then I can only conclude that what you're trying to achieve is beyond your capabilities at present and you should try something easier.
-
Nov 28th, 2015, 11:41 AM
#17
New Member
Re: I need help with my Texas HoldEm program.
In the code sample you give is there a away of using an image list for picture boxes?
-
Nov 28th, 2015, 04:52 PM
#18
Re: I need help with my Texas HoldEm program.
Originally Posted by nmagner
In the code sample you give is there a away of using an image list for picture boxes?
There are certain circumstances in which you must use an ImageList, e.g. with a ListView. With a PictureBox though, if you were to use an ImageList, there's no direct connection between the two so you would have to manually retrieve the Image from the ImageList and assign it to the Image property of the PictureBox. As such there's not really any great advantage to using an ImageList so I wouldn't. The only thing it does for you is enable you to populate it at design time rather than run time, if that's what you want. I would tend to just use a List(Of Image) or Image array populated at run time. You'd then use that in exactly the same way as you would the Images collection of an ImageList.
Posting Permissions
- You may not post new threads
- You may not post replies
- You may not post attachments
- You may not edit your posts
-
Forum Rules
|
Click Here to Expand Forum to Full Width
|