I am creating a "rock paper scissors lizard spock" game for school. I am stuck on the part of the assignment where we need to tag the bitmap images with the corresponding names using the tag property. I have created an array of names, and an array of bitmap images.
I am unsure of how to use the tag property to do this. The exact instructions are:
Create an array of string objects, and initialize it to contain the string values "rock", "paper", "scissors", "lizard", "spock" Add code to each of the bitmaps with the corresponding string values. (ex. bitmap "properties.resources.rock" should be tagged with the string "rock".
private void Form1_Load(object sender, EventArgs e)
{
string[] names =
{
"rock",
"paper",
"scissors",
"lizard" ,
"spock"
};
Bitmap[] bitmaps =
{
Properties.Resources.rock,
Properties.Resources.paper,
Properties.Resources.scissors,
Properties.Resources.lizard,
Properties.Resources.spock,
};
}
I've tried adding rock.Tag = properties.resources.rock.
I've tried names[0].tag = properties.resources.rock.
I've also tried properties.resources.rock.Tag.
The professor hasn't shown us how to use the tag property yet, so I'm sure I'm just missing something obvious. I am new to coding and any help is appreciated.
My full code is here, though it is very incomplete.
using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using System.Windows.Forms;
namespace Lab5
{
public partial class Form1 : Form
{
public Form1()
{
InitializeComponent();
}
private void Form1_Load(object sender, EventArgs e)
{
string[] names =
{
"rock",
"paper",
"scissors",
"lizard" ,
"spock"
};
Bitmap[] bitmaps =
{
Properties.Resources.rock,
Properties.Resources.paper,
Properties.Resources.scissors,
Properties.Resources.lizard,
Properties.Resources.spock,
};
// Following array will not actually be used
// PictureBox[] pics = new PictureBox[bitmaps.Length];
for (int i = 0; i < bitmaps.Length; i++)
{
PictureBox pic = new PictureBox();
pic.Image = bitmaps[i];
pic.Location = new Point(20 + (i * 100), 20);
pic.SizeMode = PictureBoxSizeMode.AutoSize;
Controls.Add(pic);
pic.Click += clickHandler;
}
}
private void displayImages()
{
// Move code from form1_load to here
}
//click handler for every picture
private void clickHandler(object sender, EventArgs e)
{
MessageBox.Show("You clicked a picture box");
}
private void playAgainButton_Click(object sender, EventArgs e)
{
// call display images here
}
}
}