I have the following code I am struggling with. I would like to extend each IF statement to set Null on a clonedGeneratedPegs.PegPosition depending on the outcome of the result and I have no concept on how to do this?
I have a series of pegs in positions 1 - 4. One series (clonedGeneratedPegs) is a set of randomly generated pegs (e.g. Red, Blue, Green, Green). The others are user generated clonedUserGuess (e.g. Yellow, Yellow, Blue, Blue)
The IF statements below work in so far as that if it returns true it adds white pegs to my list, however using the colour examples above the results would be in accurate as far as my task is concerned in that I should only return on white peg to the pegResultContainer. Not as it currently does (add 2) as my 3 and 4 statements would both add white pegs to my list
So using IF blocks 3 and 4 as my examples IF: clonedGeneratedPegs.PegPosition.PegPositon2 was Blue and the user clonedUserGuess.PegPosition3 was Blue add to list and set the clonedGeneratedPegs.PegPosition.PegPositon2 = Null
This should mean that if clonedUserGuess.PegPosition4 was also Blue it will not be added to the pegResultContainer and I will only return 1 white peg as I have already set the clonedGeneratedPegs.PegPosition.PegPositon2 to NULL.
if (clonedUserGuess.PegPosition1 != null && clonedGeneratedPegs.Contains(clonedUserGuess.PegPosition1.Colour))
pegResultContainer.ResultPegs.Add(new Peg { Colour = PegColour.White });
if (clonedUserGuess.PegPosition2 != null && clonedGeneratedPegs.Contains(clonedUserGuess.PegPosition2.Colour))
pegResultContainer.ResultPegs.Add(new Peg { Colour = PegColour.White });
if (clonedUserGuess.PegPosition3 != null && clonedGeneratedPegs.Contains(clonedUserGuess.PegPosition3.Colour))
pegResultContainer.ResultPegs.Add(new Peg { Colour = PegColour.White });
if (clonedUserGuess.PegPosition4 != null && clonedGeneratedPegs.Contains(clonedUserGuess.PegPosition4.Colour))
pegResultContainer.ResultPegs.Add(new Peg { Colour = PegColour.White });
return pegResultContainer;
I really can’t see how to tell each IF block to set its corresponding clonedGeneratedPegs Position to NULL
Thanks for any guidance
Aucun commentaire:
Enregistrer un commentaire