Computer Science Canada Help with 21 card game |
Author: | bao_luk [ Thu May 15, 2008 8:56 pm ] | ||
Post subject: | Help with 21 card game | ||
Here is the question: Create a Game 21 application to simulate a simplified version of the game '21'. A deck of cards numbered 1 through 10 is used and any number can be repeated. The computer starts by dealing you (the user) two randomly picked cards, and deals itself three randomly picked cards that are not revealed until the Check Scores button is clicked. You may then draw as many cards as you want, one by one. If both scores are over 21, or if both are equal but under 21, the game is declared a draw. Otherwise, the winner is the one with highest score less than or equal to 21. If one score is over 21 and the other is 21 or less, the player with 21 or less is declared the winner. The result should be displayed in a message box. So what I did is this:
But there are some errors... The Message Box is always displaying "That's a Draw." no matter what, even when the player or the computer is supposed to win. So is there any problem with my If statements? and one more question is that it says "You may then draw as many cards as you want, one by one. " So how do I let the program display one card each time when I click the button "Draw Card"?? Thanks a lot,,hope I can get a solution to that. and please reply ASAP =) |
Author: | Steven Toews [ Fri May 16, 2008 1:02 pm ] |
Post subject: | Re: URGENT!!!------>> Can someone help me?? |
Well I'm not at all fluent with Visual Basic, but I would recommend trying just if statements inside of a function instead of have a bunch of else ifs. Else if, has been known to cause errors or not work most of the time with alot of languages I've encountered, such as flash actionscript. |
Author: | bao_luk [ Sat May 17, 2008 6:13 am ] |
Post subject: | Re: URGENT!!!------>> Can someone help me?? |
Steven Toews @ Fri May 16, 2008 1:02 pm wrote: Well I'm not at all fluent with Visual Basic, but I would recommend trying just if statements inside of a function instead of have a bunch of else ifs. Else if, has been known to cause errors or not work most of the time with alot of languages I've encountered, such as flash actionscript.
What will be that function?? |
Author: | McKenzie [ Sat May 17, 2008 7:06 am ] | ||
Post subject: | Re: URGENT!!!------>> Can someone help me?? | ||
First, I'll warn you that putting URGENT and ASAP in your post make most people not want to help you. If you are asking for a favour it is rude to DEMAND results quickly. That said, you have a number of errors in your program. I think the one that is causing the tie is:
Types in VB are kinda funky. The values in the labels are strings. If you assign a string to an integer variable VB converts the string to an int if it can, if you try to add a string to an int it will convert the string. What you are doing here is adding the strings then assigning the value to an integer. So if the card values are "4", "10", "7" you get an integer 4107. You want to convert each of the labels to integer BEFORE you add them (I believe it is the Int() function.) |
Author: | bao_luk [ Sat May 17, 2008 12:33 pm ] | ||
Post subject: | Re: URGENT!!!------>> Can someone help me?? | ||
McKenzie @ Sat May 17, 2008 7:06 am wrote: First, I'll warn you that putting URGENT and ASAP in your post make most people not want to help you. If you are asking for a favour it is rude to DEMAND results quickly.
That said, you have a number of errors in your program. I think the one that is causing the tie is:
Types in VB are kinda funky. The values in the labels are strings. If you assign a string to an integer variable VB converts the string to an int if it can, if you try to add a string to an int it will convert the string. What you are doing here is adding the strings then assigning the value to an integer. So if the card values are "4", "10", "7" you get an integer 4107. You want to convert each of the labels to integer BEFORE you add them (I believe it is the Int() function.) Sorry and thanks but I still have one question,, how do I let the program add up the numbers displayed automatically everytime I click the button "Draw Card"?? |