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

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

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)

case(Keys.A):
 if(lettersUsed.IndexOf("a") = -1)  lettersUsed+= "a";
 break;

then when they hit space

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

great thank you. you guys are very helpful on this forum

ug im still consused though it always says lettersUsed is not defined. would any body mind giving sample code.

you probably need to do something like. This is all pseudocode

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

}

call me stupid but i cant get it it always gives me erros index of... does not exist

send me your code

heres that part of it keep in mind im new :D

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);


    }
}

not sure y that play sound dll import is in there lol

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);


    }
}

i see the problem. you are using the same variable name twice.
you have it as the name of the string and as the name of the parameter in ProcessCmdKey(ref Message msg, Keys lettersUsed).


try this instead

ProcessCmdKey(ref Message msg, Keys pressedKey){
....
switch(pressedKey){...

so this

using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Text;
using System.Windows.Forms;

namespace WindowsApplication1
{
    public partial class Form1 : Form
    {

        string lettersUsed = "";

        public Form1()
        {
            InitializeComponent();
        }


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



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

        }


    }
}

if that is right i still get errors.... :(

what errors and when do you get them? compiling or running?

compiling

they are

cannot implicitly convert 'int' to 'bool'

and

the left hand side of an assigment must be a varible, propery, or idexer

do u no what the problem is?

made the most basic of mistakes while I was in a hurry to give you the first code that I gave you. in the if statements, change the = to ==

thank you hank you thank you thank you. i really aprciate your help

thank you

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.