Lily P.

asked • 11/24/20

Rewrite code C#

Hi!


I am trying to program my own Pac Man game. I have this code:

foreach (Control x in this.Controls)

{

if (x is PictureBox)

{

if (Convert.ToString(x.Tag) == "coins")

{

if (pacman.Bounds.IntersectsWith(x.Bounds) && x.Enabled == true)

{

score++;

x.Enabled = false;

x.Visible = false;

}

}


if (Convert.ToString(x.Tag) == "barrier")

{

if (pacman.Bounds.IntersectsWith(x.Bounds))

{

gameisover();

}

}


if(Convert.ToString(x.Tag) == "ghosts")

{

if(pacman.Bounds.IntersectsWith(x.Bounds))

{

gameisover();

}

}

}

}


But can I rewrite it in a shorter and simpler way?


Thanks in advance!

1 Expert Answer

By:

Benjamin B. answered • 12/08/20

Tutor
New to Wyzant

Designing Better Grades

Lily P.

Cool, thanks!!
Report

12/10/20

Still looking for help? Get the right answer, fast.

Ask a question for free

Get a free answer to a quick problem.
Most questions answered within 4 hours.

OR

Find an Online Tutor Now

Choose an expert and meet online. No packages or subscriptions, pay only for the time you need.