0% found this document useful (0 votes)
40 views

Assignment#02 (C#-116)

The document describes a Hangman game program written in C#. [1] It initializes variables like chances (starting at 7), current_index, and the word "PAKISTAN". [2] It checks each letter entered against the word, decreasing chances if incorrect. [3] Pictures of the hangman are displayed as chances decrease. If the full word is guessed correctly with chances remaining, a "You win" label appears, and if guesses are exhausted, a "You lose" label appears instead.

Uploaded by

Ali Hassan
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as DOCX, PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
40 views

Assignment#02 (C#-116)

The document describes a Hangman game program written in C#. [1] It initializes variables like chances (starting at 7), current_index, and the word "PAKISTAN". [2] It checks each letter entered against the word, decreasing chances if incorrect. [3] Pictures of the hangman are displayed as chances decrease. If the full word is guessed correctly with chances remaining, a "You win" label appears, and if guesses are exhausted, a "You lose" label appears instead.

Uploaded by

Ali Hassan
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as DOCX, PDF, TXT or read online on Scribd
You are on page 1/ 7

Ad Programming C#

Assignment#02

11/17/2022
BSCS 5th A
Ali Hassan

Reg: uw-20m-cs-bs-116

Submitted To: Ma’am Isra Naaz


University of Wah
Department of Computer Science

HANGMAN GAME
Code:
namespace Assignment2
{
public partial class Form1 : Form
{
int chances = 7;
int current_index = 0;

public Form1()
{
InitializeComponent();
}

private void textBox1_TextChanged(object sender, EventArgs e)


{
string word = "PAKISTAN";

for (int i = 0; i < 8; i++)

{
if (current_index > textBox1.Text.Length - 1)
break;
if (textBox1.Text[current_index] == word[current_index])

}
else
{
chances--;
switch (chances)
{
case 6:
{
pictureBox1.Visible = true;
break;

}
case 5:
{
pictureBox3.Visible = true;
break;
}
case 4:
{
pictureBox4.Visible = true;
break;
}
case 3:
{
pictureBox2.Visible = true;
break;
}
case 2:
{
pictureBox6.Visible = true;
break;
}
case 1:
{
pictureBox5.Visible = true;
break;
}

}
current_index++;

int length = textBox1.TextLength;


if (length == 8)
{

if (textBox1.Text == word && chances > 0)


{
label5.Visible = true;
}
else if (textBox1.Text != word || chances <= 0)
{
label6.Visible = true;
}

private void label5_Click(object sender, EventArgs e)


{

private void label6_Click(object sender, EventArgs e)


{

private void Form1_Load(object sender, EventArgs e)


{
pictureBox1.Visible = false; pictureBox2.Visible = false;
pictureBox3.Visible = false; pictureBox4.Visible = false;
pictureBox5.Visible = false; pictureBox6.Visible = false;
label5.Visible = false;
label6.Visible = false;
}
private void pictureBox1_Click_1(object sender, EventArgs e)
{

private void pictureBox2_Click_1(object sender, EventArgs e)


{

private void pictureBox3_Click_1(object sender, EventArgs e)


{

private void pictureBox4_Click_1(object sender, EventArgs e)


{

private void pictureBox5_Click_1(object sender, EventArgs e)


{

private void pictureBox6_Click_1(object sender, EventArgs e)


{

}
}
}
Screenshot:

Firstly run:

Entering wrong alpha one by one:


2.

3.Putt 8 Attempt show Lose Option:


4.Correct Guessing show WIN:

THANK YOU…..!!!
University of Wah
Department of Computer Science

You might also like