Having a lot of trouble in my quest to complete my Hangman game.
I've made an alteration to the program though. Rather than having a text box and the user typing a letter in, I've decided to add command buttons from A-Z.
I can't seem to pass the letter to the method which has all the logic. Check CmdZ Click method and you'll see what I mean:
using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Windows.Forms;
namespace Hang
{
public partial class Form1 : Form
{
string word;
int length;
Random random = new Random();
string[] myArray = { "BLUE", "RED", "GOLD", "BLACK" };
string letter;
string tempString = null;
string sentLetter;
public Form1()
{
InitializeComponent();
}
private void Form1_Load(object sender, EventArgs e)
{
MakeLabel();
}
private void MakeLabel()
{
lblOne.Visible = false;
lblTwo.Visible = false;
lblThree.Visible = false;
lblFour.Visible = false;
word = myArray[random.Next(0, myArray.Length)];
length = word.Length;
for (int i = 0; i <= length; i++)
{
lblWord.Text += "_ ";
}
Controls.Add(lblWord);
lblWord.Visible = true;
}
public void Game(string letterz)
{
letter = letterz;
int index = word.IndexOf(letter);
if (index != -1)
{
tempString = lblWord.Text;
MessageBox.Show(letter);
}
}
private void cmdZ_Click(object sender, EventArgs e)
{
letter = "Z";
Game(letter);
}
private void cmdY_Click(object sender, EventArgs e)
{
}
private void cmdX_Click(object sender, EventArgs e)
{
}
private void cmdW_Click(object sender, EventArgs e)
{
}
private void cmdV_Click(object sender, EventArgs e)
{
}
private void cmdU_Click(object sender, EventArgs e)
{
}
private void cmdT_Click(object sender, EventArgs e)
{
}
private void cmdS_Click(object sender, EventArgs e)
{
}
private void cmdR_Click(object sender, EventArgs e)
{
}
private void cmdQ_Click(object sender, EventArgs e)
{
}
private void cmdO_Click(object sender, EventArgs e)
{
}
private void cmdP_Click(object sender, EventArgs e)
{
}
private void cmdN_Click(object sender, EventArgs e)
{
}
private void cmdM_Click(object sender, EventArgs e)
{
}
private void cmdL_Click(object sender, EventArgs e)
{
}
private void cmdK_Click(object sender, EventArgs e)
{
}
private void cmdJ_Click(object sender, EventArgs e)
{
}
private void cmdI_Click(object sender, EventArgs e)
{
}
private void cmdH_Click(object sender, EventArgs e)
{
}
private void cmdG_Click(object sender, EventArgs e)
{
}
private void cmdAF_Click(object sender, EventArgs e)
{
}
private void cmdE_Click(object sender, EventArgs e)
{
}
private void cmdD_Click(object sender, EventArgs e)
{
}
private void cmdC_Click(object sender, EventArgs e)
{
}
private void cmdB_Click(object sender, EventArgs e)
{
}
private void cmdA_Click(object sender, EventArgs e)
{
}
}
}
There's a pic added for illustrative purposes.