//globalVars Globals = new globalVars(); private void commandOptions(int a) { InputDialog dialog = new InputDialog(); InputCombo frmDir = new InputCombo(); speedSelect spdSel = new speedSelect(); // globalVars.robotName = txtRobotName.Text;//has to be replaced by something getting the robots name thru http request string nameIn = "abc"; switch (a) { case 0: { if (dialog.ShowDialog(this) == DialogResult.OK) { if (dialog.Value.Equals("")) { MessageBox.Show("Please enter a valid name for the bot"); } else { nameIn = dialog.Value.ToString(); globalVars.robotCommand = globalVars.robotName + " rename to " + nameIn; } } else if (dialog.DialogResult == DialogResult.Cancel) { RobotPie.ActiveForm.Activate(); } } break; case 1: { GoTo frmGoTo = new GoTo(); frmGoTo.Show(); } break; case 2: { if (frmDir.ShowDialog(this) == DialogResult.OK) { if (frmDir.Value.Equals("") || frmDir.Value.Equals("Please Select Direction to Face")) { MessageBox.Show("Please Choose a valid Direction to face"); } else { string faceDirection = frmDir.Value; globalVars.robotCommand = globalVars.robotName + " face " + faceDirection.ToLower(); MessageBox.Show(globalVars.robotCommand); } } else if (frmDir.DialogResult == DialogResult.Cancel) { RobotPie.ActiveForm.Activate(); } } break; case 3: { drop frmdropObj = new drop(); frmdropObj.Show(); } break; case 4: { if (spdSel.ShowDialog(this) == DialogResult.OK) { if (spdSel.Value.Equals("") || spdSel.Value.Equals("Please Select the speed")) { MessageBox.Show("Please Choose a valid speed to assign"); } else { string speedVal = spdSel.Value.ToString(); globalVars.robotCommand = globalVars.robotName + " speed " + speedVal.ToLower(); MessageBox.Show(globalVars.robotCommand); } } else if (spdSel.DialogResult == DialogResult.Cancel) { RobotPie.ActiveForm.Activate(); } } break; case 5: { grab frmGrab = new grab(); frmGrab.Show(); } break; } }
private void commandOptions(int a) //command central which houses all commands executed when a button is clicked on the pie! { InputDialog dialog = new InputDialog(); InputCombo frmDir = new InputCombo(); speedSelect spdSel = new speedSelect(); string nameIn = "abc"; switch (a) { case 0: //rename { if (dialog.ShowDialog(this) == DialogResult.OK) { if (dialog.Value.Equals("")) { MessageBox.Show("Please enter a valid name for the bot"); } else { nameIn = dialog.Value.ToString(); globalVars.robotCommand = globalVars.robotName + " rename to " + nameIn; } } else if (dialog.DialogResult == DialogResult.Cancel) { RobotPie.ActiveForm.Activate(); } } break; case 1: //Go to location { GoTo frmGoTo = new GoTo(); frmGoTo.Show(); } break; case 2: //Change facing direction { if (frmDir.ShowDialog(this) == DialogResult.OK) { if (frmDir.Value.Equals("") || frmDir.Value.Equals("Please Select Direction to Face")) { MessageBox.Show("Please Choose a valid Direction to face"); } else { string faceDirection = frmDir.Value; globalVars.robotCommand = globalVars.robotName + " face " + faceDirection.ToLower(); MessageBox.Show(globalVars.robotCommand); } } else if (frmDir.DialogResult == DialogResult.Cancel) { RobotPie.ActiveForm.Activate(); } } break; case 3: //Drop { drop frmdropObj = new drop(); frmdropObj.Show(); } break; case 4: //Select Speed { if (spdSel.ShowDialog(this) == DialogResult.OK) { if (spdSel.Value.Equals("") || spdSel.Value.Equals("Please Select the speed")) { MessageBox.Show("Please Choose a valid speed to assign"); } else { string speedVal = spdSel.Value.ToString(); globalVars.robotCommand = globalVars.robotName + " speed " + speedVal.ToLower(); MessageBox.Show(globalVars.robotCommand); } } else if (spdSel.DialogResult == DialogResult.Cancel) { RobotPie.ActiveForm.Activate(); } } break; case 5: //grab object { grab frmGrab = new grab(); frmGrab.Show(); } break; } }
private bool StateContainsFlag(InputCombo state, InputCombo flag) { if ((state &= flag) == flag) { return true; } return false; }
public bool AddMove(InputCombo[] move) { MoveNode currentNode = root; int currentInput = 0; int childIndex = currentNode.findChild(move[currentInput]); //traverse tree until end while(childIndex >= 0) { currentNode = currentNode.children[childIndex]; if((currentInput + 1) == move.Length) { break; } currentInput++; childIndex = currentNode.findChild(move[currentInput]); } //add missing new nodes to tree up until final node for(; currentInput < (move.Length - 1); currentInput++) { currentNode.addChild(move[currentInput]); childIndex = 0;//currentNode.findChild(); currentNode = currentNode.children[childIndex]; } //for the final node if move doesn't exist assign new attackCombo value and return true if(currentInput == (move.Length - 1)) { currentNode.addChild(move[currentInput], this); return true; } //else return false; return false; }
public void addChild(InputCombo inputInstance, MovesTree tree = null) { children.Insert(0, new MoveNode(inputInstance)); if(tree != null) { tree.lastAttackCombo++; children[0].attackCombo = tree.lastAttackCombo; } return; }
public int findChild(InputCombo inputInstance) { for(int index = 0; index < children.Count; index++) { if(children[index].inputCombo == inputInstance) { return index; } } return -1; }
public MoveNode(InputCombo inputInstance = InputCombo.None) { attackCombo = -1; inputCombo = inputInstance; children = new List<MoveNode>(); return; }
public int findAttackComboNumber(InputCombo [] inputBuffer) { MoveNode currentNode = root; int i; int j; int start = (inputBuffer.Length - 1); bool reset = false; while(start > 0) { //read buffer backwards for(i = start; i >= 0; i--) { if(reset){ currentNode = root; } else { reset = true; } //focus on each child in order for(j = 0; j < currentNode.children.Count; j++) { //compare child against buffer if(inputBuffer[i] == currentNode.children[j].inputCombo) { currentNode = currentNode.children[j]; Debug.Log("[" + inputBuffer[i] + "]"); if(i == 0) { Debug.Log("FOUND COMBO #" + currentNode.attackCombo); return currentNode.attackCombo; } reset = false; } } } start--; } return -1; }