So, working on a hangman's game, it's almost done.
The images need to be displayed via code. And that's my problem.
For example: I want the error to be equal to 1, the head appears, and so on. Can you help me?
So, working on a hangman's game, it's almost done.
The images need to be displayed via code. And that's my problem.
For example: I want the error to be equal to 1, the head appears, and so on. Can you help me?
Your question is very broad / open. It's hard to say assertively (probably because of this you're getting negative feedback).
Simply put, you can use the PictureBox
component of WinForms.
It's very easy to use. You can choose the image by the VisualStudio editor (properties window) and set the Visible
property to true
or false
.
I'd make a PictureBox
for each body part and leave its Visible
properties as false
. Throughout the game, with each error, I would "set" the property Visibile
to true
.
Some useful links: PictureBox by DotNetPerls and #
I would make a list, stack, or image queue in just one PictureBox, and when an error occurred, it would move to the next image.
I made a very simple code, where the error happens at the click of the button:
public partial class FormForca : Form
{
List<Image> imagens;
int erros = 0;
public FormForca()
{
InitializeComponent();
imagens = new List<Image>();
imagens.Add(global::LotoFacil.Properties.Resources._1);
imagens.Add(global::LotoFacil.Properties.Resources._2);
imagens.Add(global::LotoFacil.Properties.Resources._3);
imagens.Add(global::LotoFacil.Properties.Resources._4);
imagens.Add(global::LotoFacil.Properties.Resources._5);
imagens.Add(global::LotoFacil.Properties.Resources._6);
imagens.Add(global::LotoFacil.Properties.Resources._7);
}
private void button1_Click(object sender, EventArgs e)
{
erros++;
pictureBox1.Image = imagens[erros];
//Se chegou na ultima imagem, volta a primeira.
if (erros== imagens.Count-1)
{
erros = -1;
}
}
}
aftertheerrorshappen:
where:
global::LotoFacil.Properties.Resources._1
is the blank image, e:
global::LotoFacil.Properties.Resources._7
is the final image of the game (hanged doll).