string generateCommand(ButtonBase b) { if (b is sliderButton) { sliderButton temp = (sliderButton)b; return(temp.getNewCommand()); } else if (b is switchButton) { switchButton temp = (switchButton)b; return(temp.getNewCommand()); } else { pressButton temp = (pressButton)b; return(temp.getNewCommand()); } }
bool checkCommandSatisfied(ButtonBase b) { // needs to cast into correct button if (b is sliderButton) { sliderButton temp = (sliderButton)b; return(command == temp.getAssociatedCommand()); } else if (b is switchButton) { switchButton temp = (switchButton)b; return(command == temp.getAssociatedCommand()); } else { pressButton temp = (pressButton)b; return(command == temp.getAssociatedCommand()); } }
public void parseString(string parse) { // Example String First Parse Format: "PlayerNumber&RestofString" string[] firstArray; string[] separators = { "&" }; firstArray = parse.Split(separators, StringSplitOptions.RemoveEmptyEntries); string playerNum = firstArray[0]; // now has the number of player which will be used to distinguish between clients string restOfString = firstArray[1]; // gets the rest of the string that will be parsed below // RestofString Format: "GridNumber%GridButtons" string[] secondArray; string[] secondSeparators = { "%" }; secondArray = restOfString.Split(secondSeparators, StringSplitOptions.RemoveEmptyEntries); string gridNumber = secondArray[0]; // now has the grid number if (playerNumber == playerNum) { myGridBoard.updateGridNum(gridNumber); } string stringToParse = secondArray[1]; // has rest of buttons and names // GridButtons Format: "button:name?button:name?button:name?" string[] buttonlist; char[] thirdSeparators = { '?' }; // returns 4 strings with button information buttonlist = stringToParse.Split(thirdSeparators, StringSplitOptions.RemoveEmptyEntries); // Info Format: "button:name" char[] fourthSeparators = { ':' }; string[] info; // Fill array of GridButtons based off string of button info for (int i = 0; i < buttonNum; i++) { info = buttonlist[i].Split(fourthSeparators, StringSplitOptions.RemoveEmptyEntries); // TODO: match string type to proper value switchButton tempSwitch = new switchButton(switchNames[info[1]]); pressButton tempPress = new pressButton(pressNames[info[1]]); sliderButton tempSlider = new sliderButton(sliderNames[info[1]]); if (playerNumber == playerNum) // only populates its own buttons { //GridButton newGridButton = new GridButton(info[0], info[1]); //gridButtonList.Add(newGridButton); myGridBoard.addButton(new GridButton(info[0], info[1], i, gridNumber, sliderNames, switchNames, pressNames)); if (info[0] == "f") { // buttonList.Add(new pressButton(pressNames[info[1]])); myGameBoard.addmyButtons(tempPress); } else if (info[0] == "t" || info[0] == "s") { // buttonList.Add(new switchButton(switchNames[info[1]])); myGameBoard.addmyButtons(tempSwitch); } else { // buttonList.Add(new sliderButton(sliderNames[info[1]])); myGameBoard.addmyButtons(tempSlider); } } Debug.Log(info[0] + " " + info[1]); if (info[0] == "f") { // buttonList.Add(new pressButton(pressNames[info[1]])); myGameBoard.addButtontoGameboard(tempPress); } else if (info[0] == "t" || info[0] == "s") { // buttonList.Add(new switchButton(switchNames[info[1]])); myGameBoard.addButtontoGameboard(tempSwitch); } else { // buttonList.Add(new sliderButton(sliderNames[info[1]])); myGameBoard.addButtontoGameboard(tempSlider); } } }