Working with C#; images

Asked

Viewed 121 times

-3

So, I’m working on a hangman game, it’s almost ready.

Still have to make the images appear via code. And that’s my problem.

For example: I want that if the error is 1, the head appears and etc. You can help me?

2 answers

3


Your question is very wide/open. It is difficult to answer assertively (probably why you are receiving negative votes).

Simply put, you can use the component PictureBox winforms.

It is very easy to use. You can choose the image by the Visualstudio editor (properties window) and set the property Visible for true or false.

I would make a PictureBox for each part of the body and would leave its properties Visible as false. Throughout the game, every mistake, would "set" the property Visibile for true.


Some useful links: Picturebox by Dotnetperls and Official documentation of the Picturebox class

1

I would make a List, Stack or Image Queue in just one Picturebox, and when an error occurs, advance 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;
        }
    }
 }

Inicio de jogo

after the mistakes happen:

Fim de jogo

where:

global::LotoFacil.Properties.Resources._1

is the blank image, and:

global::LotoFacil.Properties.Resources._7

is the final image of the game (hanging doll).

  • 1

    Good! There are several ways to implement a solution for this case. But with "so much" detail that we have in question it becomes difficult to be assertive rsrs. You can even draw in the form itself. You wouldn’t even need Picturebox :P

  • 2

    That’s right, but thanks. I always try to help =]

  • 3

    draw in hand a hangman, ta crazy, rsrs. Good to see that there is always someone negativing my posts, will know why right... rs

  • 1

    Wow! Now that I see there’s a -1.. Crazy...

Browser other questions tagged

You are not signed in. Login or sign up in order to post.