pressing keys and Button click simultaneously...
Hi there Guys, I am new in c# and I am trying to learn the key and button functionalities. I created a Pacman-like game with a text twist. So far I can now move pacman and eat pellets. the next step is for him to eat 'letters' and form some words. I created a button TWIST on the form and when I tried moving pacman using the arrow keys he won't move anymore. But when I tried disabling the button TWIST, he moved.
So I think this is somewhat an easy question for you guys, and I don't think I need to provide the code. Just give me some hints on how I can make this right. Thanks in advance guys!
-------
sorry, okay here's the code
for the mouse click event:
private void twistButton_Click(object sender, EventArgs e)
{
//do the twisting
}
FOr the keydown event:
private void Form1_KeyDown(object sender, KeyEventArgs k)
{
string result = k.KeyData.ToString();
Invalidate(pacman.GetFrame());
switch (result)
{
case "Left":
pacman.MoveLeft(ClientRectangle);
Invalidate(pacman.GetFrame());
break;
case "Right":
pacman.MoveRight(ClientRectangle);
Invalidate(pacman.GetFrame());
break;
case "Up":
pacman.MoveUp(ClientRectangle);
Invalidate(pacman.GetFrame());
break;
case "Down":
pacman.MoveDown(ClientRectangle);
Invalidate(pacman.GetFrame());
break;
default:
break;
}
//if pacman eats the gold pellet
int hitGold = CheckInterSectionGoldPellet();
//incrementing the time
if (hitGold != -1)
{
score.Increment();
Invalidate(((GoldPellet)goldPellets[hitGold]).GetFrame());
goldPellets.RemoveAt(hitGold);
}
//if pacman eats the black pellet
int hitBlack = CheckInterSectionBlackPellet();
//incrementing the time
if (hitBlack != -1)
{
score.Increment();
Invalidate(((BlackPellet)blackPellets[hitBlack]).GetFrame());
blackPellets.RemoveAt(hitBlack);
}
}