public static void AddRollPlace(ListBox box, string name, int roll = -1) { Dice roller = new Dice(); if (roll > 12) { roll = 12; } else if (roll < 2) { roll = roller.Roll(6, 2); } InitiativeListNode node = new InitiativeListNode { Roll = roll, Name = name, Location = GetLocationRoll(box, roll) }; box.Items.Insert(node.Location, node.ListItem); UpdatePositions(box); }
public static void AddListPlace(ListBox box, string name, int position = -1) { if (position > box.Items.Count || position < 0) { position = box.Items.Count; } InitiativeListNode node = new InitiativeListNode { Location = GetLocationList(box, position), Name = name }; int positionBelow = ((position + 1) < box.Items.Count) ? position + 1 : 0; int positionAbove = ((position - 1) >= 0) ? position - 1 : box.Items.Count - 1; if (!box.Items[positionBelow].ToString().Contains(TOP_OF_ROUND)) { node.Roll = Convert.ToInt32(box.Items[positionBelow].ToString().Split(' ')[2]); } else if (!box.Items[positionAbove].ToString().Contains(TOP_OF_ROUND)) { node.Roll = Convert.ToInt32(box.Items[positionAbove].ToString().Split(' ')[2]); } else { //No other roll exists, so give this one the average roll. node.Roll = 7; } box.Items.Insert(node.Location, node.ListItem); UpdatePositions(box); }
private static int GetLocationRoll(ListBox box, int roll) { for (int position = 0; position < box.Items.Count; position++) { if (!box.Items[position].ToString().Contains(TOP_OF_ROUND)) { InitiativeListNode tmp = new InitiativeListNode(box.Items[position].ToString()); if (roll >= tmp.Roll) { return(position); } } } return(box.Items.Count); }
public static void UpdatePositions(ListBox box) { int locOfTopOfRound = -1; while (!box.Items[++locOfTopOfRound].ToString().Contains(TOP_OF_ROUND)) { ; } InitiativeListNode node = new InitiativeListNode(); int position = 0; do { if (box.Items[locOfTopOfRound].ToString().Contains(TOP_OF_ROUND)) { string[] contents = box.Items[locOfTopOfRound].ToString().Split(' '); contents[0] = "0"; string pushVal = string.Join(" ", contents); box.Items.RemoveAt(locOfTopOfRound); box.Items.Insert(locOfTopOfRound, pushVal); } else { node.ListItem = box.Items[locOfTopOfRound].ToString(); node.Location = position; box.Items.RemoveAt(locOfTopOfRound); box.Items.Insert(locOfTopOfRound, node.ListItem); } position++; locOfTopOfRound++; if (locOfTopOfRound == box.Items.Count) { locOfTopOfRound = 0; } } while (!box.Items[locOfTopOfRound].ToString().Contains(TOP_OF_ROUND) && box.Items.Count > 1); }
//Moves the current item to another place in the list. //If it were the Rat's turn and I put 3 in movelist, it would move rat to index 3. private void MoveList_Click(object sender, EventArgs e) { if (InitiativeTextBox.Text != "") { string[] contents = InitiativeTextBox.Text.Split(' '); InitiativeTextBox.Text = ""; try { if (Convert.ToInt32(contents[1]) > InitiativeListBox.Items.Count) { contents[1] = Convert.ToString(InitiativeListBox.Items.Count); } for (int index = 0; index < InitiativeListBox.Items.Count; index++) { if (!InitiativeListBox.Items[index].ToString().Contains(InitiativeManager.TOP_OF_ROUND)) { InitiativeListNode tmp = new InitiativeListNode(InitiativeListBox.Items[index].ToString()); if (tmp.Name.Contains(contents[0])) { string tmpStr = InitiativeListBox.Items[index].ToString(); InitiativeListBox.Items.Insert(Convert.ToInt32(contents[1]), tmpStr); InitiativeListBox.Items.RemoveAt(index); } } } undoRedoTracker = InitiativeManager.UpdateUndoBox(InitiativeListBox, undoInitiativeListBox, undoRedoTracker); PlayerTurnLabel.Text = InitiativeManager.UpdatePlayerTurnLabel(InitiativeListBox); InitiativeManager.UpdatePositions(InitiativeListBox); } catch (IndexOutOfRangeException) { } catch (FormatException) { } } }