public override bool Perguntar() { string text = string.Format(PRATO_QUE_PENSOU, PratoNome); DialogResult dr = MessageBox.Show(text, JogoGourmet.TITULO, MessageBoxButtons.YesNo, MessageBoxIcon.Question); //se é um nó folha e a resposta é sim, acertou. //caso contrário pergunta qual o novo prato e reorganiza os nós if (dr == DialogResult.Yes) { return(true); } else { string value = string.Empty; dr = InputBox.Show(JogoGourmet.TITULO, QUAL_PRATO_QUE_PENSOU, ref value); if (dr == DialogResult.OK) { BaseNode novaLeafPositiva = new PratoLeafNode(value); text = string.Format(PRATO_EH_MAS_ESTE_NAO, value, this.PratoNome); dr = InputBox.Show(JogoGourmet.TITULO, text, ref value); PratoNode grandParentNode = (PratoNode)this.PratoParentNode; BaseNode novoParent = new PratoNode(value, novaLeafPositiva, this); if (grandParentNode.PratoNodeNegativo == this) { grandParentNode.PratoNodeNegativo = novoParent; } else { grandParentNode.PratoNodePositivo = novoParent; } } return(false); } }
public void Start() { BaseNode positivoNove = new PratoLeafNode("Lasanha"); BaseNode negativoNove = new PratoLeafNode("Bolo de Chocolate"); root = new PratoNode("massa", positivoNove, negativoNove); while (true) { DialogResult dr = MessageBox.Show(TEXTO, TITULO, MessageBoxButtons.OKCancel, MessageBoxIcon.Information, MessageBoxDefaultButton.Button2); if (dr == DialogResult.OK) { bool acertou = root.Perguntar(); if (acertou) { dr = MessageBox.Show(ACERTOU, TITULO, MessageBoxButtons.OK, MessageBoxIcon.Exclamation); } } else { break; } } }