Code Confusion

Please support our C# advertiser: Intel Parallel Studio Home
Reply

Join Date: Jul 2005
Posts: 1,542
Reputation: tayspen is on a distinguished road 
Solved Threads: 98
Team Colleague
tayspen's Avatar
tayspen tayspen is offline Offline
<Insert title here>

Code Confusion

 
0
  #1
Aug 3rd, 2005
ok, after i got thelp with keypresses it is time to go one step further. i am ,making a very simple hangman game. the user will guess letters like you mormally do in hangman. what i want to be able to do is if he cant remember what he has guessed he can press a button. with that presss of the buttion all the letters/ keys that were captured would show up in a text box. but they would only show up when he pressed them.

i dont know if this is possible so any help would be great

Tayspen
Reply With Quote Quick reply to this message  
Join Date: Jul 2005
Posts: 483
Reputation: campkev is an unknown quantity at this point 
Solved Threads: 19
campkev campkev is offline Offline
Posting Pro in Training

Re: Code Confusion

 
0
  #2
Aug 3rd, 2005
couple of different ways you can handle it
I would probably do something like the following.
When the game starts instantiate a string called lettersUsed to be an empty string
  1. string lettersUsed = "";

then, when someone hits a letter, add it to the string if it isn't already there. (adding to the code from your previous post)
  1. case(Keys.A):
  2. if(lettersUsed.IndexOf("a") = -1) lettersUsed+= "a";
  3. break;

then when they hit space
  1. case(Keys.Space):
  2. MessageBox.Show("Letters used: " + lettersUsed);
  3. break;
Reply With Quote Quick reply to this message  
Join Date: Jul 2005
Posts: 1,542
Reputation: tayspen is on a distinguished road 
Solved Threads: 98
Team Colleague
tayspen's Avatar
tayspen tayspen is offline Offline
<Insert title here>

Re: Code Confusion

 
0
  #3
Aug 3rd, 2005
great thank you. you guys are very helpful on this forum
Reply With Quote Quick reply to this message  
Join Date: Jul 2005
Posts: 1,542
Reputation: tayspen is on a distinguished road 
Solved Threads: 98
Team Colleague
tayspen's Avatar
tayspen tayspen is offline Offline
<Insert title here>

Re: Code Confusion

 
0
  #4
Aug 3rd, 2005
ug im still consused though it always says lettersUsed is not defined. would any body mind giving sample code.
Reply With Quote Quick reply to this message  
Join Date: Jul 2005
Posts: 483
Reputation: campkev is an unknown quantity at this point 
Solved Threads: 19
campkev campkev is offline Offline
Posting Pro in Training

Re: Code Confusion

 
0
  #5
Aug 3rd, 2005
you probably need to do something like. This is all pseudocode

class Hangman{
string usedLetters= "";;
...
function startGame{
usedLetters = "";
}

}
Reply With Quote Quick reply to this message  
Join Date: Jul 2005
Posts: 1,542
Reputation: tayspen is on a distinguished road 
Solved Threads: 98
Team Colleague
tayspen's Avatar
tayspen tayspen is offline Offline
<Insert title here>

Re: Code Confusion

 
0
  #6
Aug 3rd, 2005
call me stupid but i cant get it it always gives me erros index of... does not exist
Reply With Quote Quick reply to this message  
Join Date: Jul 2005
Posts: 483
Reputation: campkev is an unknown quantity at this point 
Solved Threads: 19
campkev campkev is offline Offline
Posting Pro in Training

Re: Code Confusion

 
0
  #7
Aug 3rd, 2005
send me your code
Reply With Quote Quick reply to this message  
Join Date: Jul 2005
Posts: 1,542
Reputation: tayspen is on a distinguished road 
Solved Threads: 98
Team Colleague
tayspen's Avatar
tayspen tayspen is offline Offline
<Insert title here>

Re: Code Confusion

 
0
  #8
Aug 3rd, 2005
heres that part of it keep in mind im new




using System;
using System.Drawing;
using System.Windows.Forms;
using System.Runtime.InteropServices;


namespace WindowsApplication1
{
public partial class Form1 : Form
{
string keyData = "";

public Form1()
{
InitializeComponent();
string keyData = "";

}

protected override bool ProcessCmdKey(ref Message msg, Keys keyData)
{
bool result = false;
switch (keyData)
{
case(Keys.A):
if(lettersUsed.IndexOf("a") = -1) lettersUsed+= "a";
break;

case(Keys.Space):
MessageBox.Show("Letters used: " + lettersUsed);
break;
break;





}
return result;
}


[DllImport("winmm.dll")]
private static extern bool PlaySound(string lpszName, int hModule, int dwFlags);


}
}
Reply With Quote Quick reply to this message  
Join Date: Jul 2005
Posts: 1,542
Reputation: tayspen is on a distinguished road 
Solved Threads: 98
Team Colleague
tayspen's Avatar
tayspen tayspen is offline Offline
<Insert title here>

Re: Code Confusion

 
0
  #9
Aug 3rd, 2005
not sure y that play sound dll import is in there lol
Reply With Quote Quick reply to this message  
Join Date: Jul 2005
Posts: 1,542
Reputation: tayspen is on a distinguished road 
Solved Threads: 98
Team Colleague
tayspen's Avatar
tayspen tayspen is offline Offline
<Insert title here>

Re: Code Confusion

 
0
  #10
Aug 3rd, 2005
here it is closer i think





using System;
using System.Drawing;
using System.Windows.Forms;
using System.Runtime.InteropServices;


namespace WindowsApplication1
{
public partial class Form1 : Form{
string lettersUsed = "";


public Form1()
{
InitializeComponent();


}

protected override bool ProcessCmdKey(ref Message msg, Keys lettersUsed)
{
bool result = false;
switch (lettersUsed)
{
case(Keys.A):
if(lettersUsed.IndexOf("a") = -1) lettersUsed+= "a";
break;

case(Keys.Space):
MessageBox.Show("Letters used: " + lettersUsed);
break;
break;





}
return result;
}


[DllImport("winmm.dll")]
private static extern bool PlaySound(string lpszName, int hModule, int dwFlags);


}
}
Reply With Quote Quick reply to this message  
Reply

This thread is more than three months old.
Perhaps start a new thread instead?
Message:



Similar Threads
Other Threads in the C# Forum


Views: 4281 | Replies: 16
Thread Tools Search this Thread



Tag cloud for C#
About Us | Contact Us | Advertise | DaniWeb | Acceptable Use Policy | RSS Feed

©2003 - 2009 DaniWeb® LLC