hey iv been given my end of year project to do in college its a typing game (how fun) i have all the code writen for most of teh poject but to start it of i have to write a program to read from file display it and highlight the letter when the player presses the correct key my only problem is now to i set it to check for a match if got a design document that i have worked out how to do this but i cant translte it into c#
int matched = 0;
This will compare the Key.Down value to any of the strings onscreen if there is a match then
Matched == matched + 1;
And the matched letter will be highlighted
for
(int matched= 0; matched< length ; matched++){
}
Inside the loop there will be a if statement to say if the word doesn’t have a match the break the loop and unhighlight the highlighted letters and set matched back to 0.
i know its not alot but its the only way i can figure out how to go about once i get this sorted ill be able to implement the rest of my code and would be extremely greatfull to anyone who wud be able to even give me a headstart on how to go about this
Rachel FinanPosted Apr 23, 2008, 12:32 PM
Thanks for the help now would any one be able to help me get the words i call from a file to display at dif y positions atm all its doing is calling all the words and writing them on teh same spot im trying to use a constructor methos to call a random number from the form and then set the ypos to the random number but not to sure how to do it this is my code so far
for the form i have:
Alien []enemyName; Random startposy = new Random(); Highscore highscore; StreamReader inputStream; string[] word; char latestValue; public Form1(){
InitializeComponent();
enemyName =
new Alien[10];highscore =
new Highscore();word =
new string[10];inputStream =
File.OpenText(@"...\File\Words.txt"); for (int i = 0; i < enemyName.Length; i++)enemyName[i] =
new Alien(startposy); for (int i = 0; i{
word[i] = inputStream.ReadLine();
enemyName[i].GetName = word[i];
}
inputStream.Close();
}
{
latestValue = e.KeyData.ToString()[0];
highscore.Display(label1);
}
private void Form1_Paint(object sender, PaintEventArgs e){
DoubleBuffered =
true; Graphics g = e.Graphics; Font aFont = new Font("Times",20); string redWord = latestValue.ToString(); SolidBrush red = new SolidBrush(Color.Red); for (int i = 0; i < enemyName.Length; i++){
enemyName[i].DrawAlien(g);
enemyName[i].MoveAlien();
}
and for the alien:
int enemyposx = 730; int enemyposy; int enemymovex = 1; bool AlienAlive = false; string name; public Alien(){
}
public void DrawAlien(Graphics g){
SolidBrush f = new SolidBrush(Color.Blue); SolidBrush f2 = new SolidBrush(Color.Red); Pen p = new Pen(Color.Black); Font bFont = new Font("Times", 20);g.FillRectangle(f, enemyposx, enemyposy, 20, 20);
g.DrawString(name, bFont, f2, enemyposx, enemyposy);
}
public void MoveAlien(){
enemyposx = enemyposx - enemymovex;
}
public string GetName{
get{
return name;}
set{
name =
value;}
}
any help or ideas shall be great as i am still unbeliveably oblivious to the language and it has takin me 4 days to get this far :D
Bechir BejaouiPosted Apr 12, 2008, 4:14 PM
string Content;
int Matched = 0;
private void Form1_KeyDown(object sender, KeyEventArgs e)
{
if (Content.Contains(e.KeyData.ToString()))
{
label1.Text = e.KeyData.ToString();
label2.Text = "It's position is : " + Convert.ToString(Content.IndexOf(e.KeyData.ToString()));
Matched++;
}
}
private void Form1_Paint(object sender, PaintEventArgs e)
{
string myString = "azerty";
myString = myString.ToUpper();
Content = myString;
Graphics Text = e.Graphics;
FontFamily fontFamily = new FontFamily("Arial");
Brush myBruch = Brushes.Black;
Text.DrawString(myString, new Font(fontFamily, 18), myBruch, new PointF(20, 20));
}