So I am trying to make a gui this time for this game, it doesnt display the result .... but there's no errors
http://www.4shared.com/rar/DtIIpB1J/Myfile.html
Loading
Know the answer? Post it — somebody with the same question will find it here.
Sign in to answer this question
It is the same account you read, post and publish with — and you will come straight back to this page.
VulpesPosted Jan 14, 2012, 8:41 AM
I'd delete that and replace it with a textBox, outputTextBox, and set the following properties in its Properties Box:
Multiline - True
ReadOnly - True
ScrollBars - Verical
All you need to do now is to replace the code you currently have in button1_Click with the following and it should work:
Prime bPosted Jan 15, 2012, 12:37 PM
VulpesPosted Jan 15, 2012, 12:34 PM
Prime bPosted Jan 15, 2012, 12:31 PM
except this doesn't make sense
int num = deck[lastCardIndex]; //index = 0
lastCardIndex++;
suit = suits[(num - 1) % 4]; // tells us what suit it is
return (num - 1) / 4 + 1;
so lastCardIndex has 0 which assigns it to deck and then to num
but why do we increment lastCardIndex?
and then, we do the math , suit [num-1] <<< but the num is zero! because of the the statement above
and then this suit = suits[(num - 1) % 4] , I understand the whole modulus thing now, how it assings 1-3 a number and it determines the suit, but how does the computer know to assign particularly that number to cards array?
VulpesPosted Jan 15, 2012, 12:03 PM
deal = 0; // start again on next button click
and replace it with these:
button1.Enabled = false;
DialogResult dr = MessageBox.Show("Want to play again?", "Replay", MessageBoxButtons.YesNo);
if (dr == DialogResult.Yes)
{
button1.Enabled = true;
deal = 0; // start again on next button click
}
If they don't want to play again and you want to close the application at that point, just add:
else this.Close();
A new line in Windows is supposed to be "\r\n" and in Unix it's "\n". See the docs for the Environment.NewLine property:
http://msdn.microsoft.com/en-us/library/system.environment.newline.aspx
However, "\n" still seems to work in some types of Windows applications such as console applications.
Prime bPosted Jan 15, 2012, 11:59 AM
int num = deck[lastCardIndex]; //index = 0
lastCardIndex++;
suit = suits[(num - 1) % 4]; // tells us what suit it is
return (num - 1) / 4 + 1;
so lastCardIndex has 0 which assigns it to deck and then to num
but why do we increment lastCardIndex?
and then, we do the math , suit [num-1] <<< but the num is zero! because of the the statement above
and then this suit = suits[(num - 1) % 4] , I understand the whole modulus thing now, how it assings 1-3 a number and it determines the suit, but how does the computer know to assign particularly that number to cards array?
Prime bPosted Jan 15, 2012, 11:53 AM
but isn't \n is new line?
then why \r is in there?
Prime bPosted Jan 15, 2012, 11:47 AM
Vulpes, what if after 26 deals play button would disappear and window would pop up saying
want to play again?
yes no
How would I do that
VulpesPosted Jan 15, 2012, 11:45 AM
Prime bPosted Jan 15, 2012, 11:43 AM
VulpesPosted Jan 15, 2012, 11:41 AM
However, if you click the button again after that, it will erase the previous deals and start again with a new batch of 26 deals.
If you've altered the code in a piecemeal fashion, I'd check that you've using:
outputTextBox.Text += temp;
rather than:
outputTextBox.Text = temp;
Prime bPosted Jan 15, 2012, 11:26 AM
VulpesPosted Jan 15, 2012, 8:53 AM
First you need to add the following to your fields - I've made them static as your other fields are static but it doesn't really matter:
static int totalComputer = 0;
static int totalPlayer = 0;
static int deal = 0;
You'll also need to resurrect your outputLabel and I'd change the font to the fixed-width Consolas to make layout easier.
Now you need to change the code in the button1_Click eventhandler as follows:
public void button1_Click(object sender, EventArgs e)
{
if (deal == 0)
{
totalComputer = 0;
totalPlayer = 0;
Array.Clear(deck, 0, deck.Length);
lastCardIndex = 0;
FillDeck();
outputTextBox.Clear();
outputLabel.Text = "";
}
string computerSuit;
int computer = SelectCard(out computerSuit) - 1;
string playerSuit;
int player = SelectCard(out playerSuit) - 1;
if (computer > player)
{
totalComputer += 2;
}
else if (computer < player)
{
totalPlayer += 2;
}
else
{
totalComputer += 1;
totalPlayer += 1;
}
string temp = String.Format("Deal # {0}\r\n", deal + 1);
temp += String.Format(" Computer has {0} of {1}\r\n", cards[computer], computerSuit);
temp += String.Format(" Player has {0} of {1}\r\n", cards[player], playerSuit);
temp += String.Format("Computer Score is {0}\r\n", totalComputer);
temp += String.Format("Player Score is {0}\r\n", totalPlayer);
if (deal < 25) temp += "\r\n";
outputTextBox.Text += temp;
outputTextBox.SelectionStart = outputTextBox.Text.Length; // place caret at end of text
outputTextBox.ScrollToCaret(); // make sure last deal is visible
deal++;
if (deal < 26) return;
if (totalComputer > totalPlayer)
{
temp = "THE WINNER IS THE COMPUTER!";
}
else if (totalPlayer > totalComputer)
{
temp = "THE WINNER IS THE PLAYER!";
}
else
{
temp = "IT'S A DRAW!";
}
temp += "\r\n\r\n" + " FINAL SCORE\r\n";
temp += "Computer Player\r\n";
temp += " " + totalComputer + " " + totalPlayer;
outputLabel.Text = temp;
deal = 0; // start again on next button click
}
Prime bPosted Jan 14, 2012, 12:04 PM
something like.
THE WINNER IS (whoever is the winner) or DRAW
FINAL SCORE
Computer Player
Also click play button every time for 26 deals