Пример #1
0
		} /*checkAnswerAndGiveFeedbackFor*/

		private bool answerIsAllowed(ColorSequence guess) {
			for (byte i = 0; i < guess.Length; i++)
				for (byte j = 0; j < guess.Length; j++)
					if (i != j && guess.getColorOnPlace(i) == guess.getColorOnPlace(j))
						return false;

			return true;
		} /*answerAllowed*/
		} /*giveControlsproperties*/

		public void drawFrm() {
			Main.toolStripSave.Enabled = true;

			NrOfPins = Main.Mastermind.GameState.NrOfPins;
			NrOfTries = Main.Mastermind.GameState.NrOfTries;
			NrOfAvailableColors = Main.Mastermind.GameState.NrOfAvailableColors;

			showPlayerLabels();
			showFbLabels();
			showSecretLabels();
			showAvailableLabels();

			resizeFrmMain();
			Main.CenterThisScreen();

			highlightAccesiblePlayerLabels();

			if (Main.Mastermind.GameState.ComputerIsPlaying && Main.Mastermind.GameState.TurnHistory.Count == 0) {
				ColorSequence firstGuess = Main.Mastermind.MSolver.makeGuess();
				for (byte i = 0; i < NrOfPins; i++)
					LblArrayPlayer[0, i].BackColor = Color.FromName(firstGuess.getColorOnPlace(i).ToString());
			}

			btnShow();
		} /*drawFrm*/
Пример #3
0
		} /*btnHint_Click*/

		public void btnGiveFeedBack_Click(object sender, EventArgs e) {
			if (!Mastermind.gameIsOver()) {
				try {
					Button btn = sender as Button;
					byte correcPlaceAndCol = 0;
					byte correctCol = 0;
					for (int i = 0; i < Mastermind.GameState.NrOfPins; i++) {
						if (CtrlController.LblArrayFeedBackPins[Mastermind.GameState.TurnNumber - 1, i].BackColor == Color.Black) {
							correcPlaceAndCol++;
						}
						if (CtrlController.LblArrayFeedBackPins[Mastermind.GameState.TurnNumber - 1, i].BackColor == Color.White) {
							correctCol++;
						}
					}
					Feedback fb = new Feedback(correcPlaceAndCol, correctCol);
					ColorSequence newGuess = Mastermind.MSolver.makeGuess(fb);
					if (Mastermind.gameIsOver()) {
						MessageBox.Show(Mastermind.GameState.Won ? "Won" : "Lost");
					} else {
						for (byte i = 0; i < newGuess.Length; i++) {
							CtrlController.LblArrayPlayer[Mastermind.GameState.TurnNumber - 1, i].BackColor =
								Color.FromName(newGuess.getColorOnPlace(i).ToString());
						}
						if (btn != null) btn.Top += 50;
						pnlPlace.ScrollControlIntoView(CtrlController.LblArrayPlayer[Mastermind.GameState.TurnNumber - 1, 0]);
					}
				} catch (ArgumentOutOfRangeException) {
					MessageBox.Show(Mastermind.GameState.Won ? "Won" : "You must have made a mistake, I can't do anything anymore");
				}
			}
		} /*btnGiveFeedBack_Click*/
Пример #4
0
		} /*btnGuess_Click*/

		public void btnHint_Click(object sender, EventArgs e) {
			if (!Mastermind.gameIsOver()) {
				try {
					ColorSequence guess = Mastermind.MSolver.giveHint();
					for (byte i = 0; i < guess.Length; i++) {
						CtrlController.LblArrayPlayer[Mastermind.GameState.TurnNumber - 1, i].BackColor =
							Color.FromName(guess.getColorOnPlace(i).ToString());
					}
					passGuessAndGetFeedback(guess);
				} catch (IndexOutOfRangeException) {
					MessageBox.Show(
						string.Format("I can't seem to resolve the puzzel"), string.Format("Error"));
				}
			}
		} /*btnHint_Click*/