// Method for Challenge 3 public static void ChallengeThree() { Console.WriteLine("You are now entering Challenge 3!\r\n"); // Varibales used for name and age double age; string newName; // Prompt user for full name, validate, store, and create new name object with SwapInfo Console.Write("Please type in your full name: "); newName = Validate.Input(Console.ReadLine()); var newUserName = new SwapInfo(newName); // Give user feedback Console.WriteLine("The name your entered is: " + newUserName.FullName); // Promt user for age, validate, store, and create new age object Console.Write("Please enter your age: "); age = Validate.Age(Console.ReadLine()); var newAge = new AgeConvert(age); // Give user feedback and convert age to other usable numbers Console.WriteLine("{0} has been alive for {1:n0} days!", newUserName.FullName, newAge.AgeDays()); Console.WriteLine("{0} has been alive for {1:n0} hours!", newUserName.FullName, newAge.AgeHours()); Console.WriteLine("{0} has been alive for {1:n0} minutes!", newUserName.FullName, newAge.AgeMin()); Console.WriteLine("{0} has been alive for {1:n0} seconds!\r\n", newUserName.FullName, newAge.AgeSec()); }
/// <summary> /// Resets flags. /// </summary> private void ResetSwapInfoFlags() { var swapInfo = ThisSwap; swapInfo.NewVertexColors = false; swapInfo.NewVertexPositions = false; swapInfo.DidBecomeVisible = false; swapInfo.DidBecomeInvisible = false; ThisSwap = swapInfo; }
/* * Name: Christopher Westman * Date(YYMM): 1801 * Course: Project & Portfolio 1 * Synopsis: This is a code challenge for Development. This challenge contains five sub-challenges. * Every Challenge will be contained within its own class file. * Each challenge solves a unique problem that must be solved. All challenges use the Validate class which * contains several different types of validations. The validations can validate for word counts, single string inputs, * and numbers within a certain range or above -1. This main program file is simplified to only show the calling of * each challenge. To see the challenge code, simply open the class file with the name that mirrors the method call, * for example, ChallengeOne can be found in the SwapInfo class file. */ static void Main(string[] args) { // Challenge 1 SwapInfo.ChallengeOne(); // Challenge 2 Backwards.ChallengeTwo(); // Challenge 3 AgeConvert.ChallengeThree(); // Challenge 4 TempConvert.ChallengeFour(); // Challenge 5 MainMenu.ChallengeFive(); }
// Method for Challenge 5 public static void ChallengeFive() { Console.WriteLine("You are now entering Challenge 5!\r\n"); // Use while loop to allow menu prompt while (true) { // Variable for user entry double entry; // Prompt user to select from menu Console.WriteLine("Which challenge would you like to try again?\r\n" + "Enter 1 for SwapInfo\r\n" + "Enter 2 for Backwards\r\n" + "Enter 3 for AgeConvert\r\n" + "Enter 4 for TempConvert\r\n" + "Or enter 0 to quit"); // Validate and store user entry entry = Validate.Menu(Console.ReadLine()); // Cycle through if statement to start user menu option if (entry == 1) { SwapInfo.ChallengeOne(); } else if (entry == 2) { Backwards.ChallengeTwo(); } else if (entry == 3) { AgeConvert.ChallengeThree(); } else if (entry == 4) { TempConvert.ChallengeFour(); } else if (entry == 0) { // Break out of while loop if user doesn't want to run program Console.WriteLine("Exiting now! Thanks for using the program!"); break; } } }
private void UpdateBySwap(SwapInfo e) { if (e is null) { throw new ArgumentNullException(nameof(e)); } Update(); var dic = _prevFoldings.Where(p => p.IsFolded) .Where(p => e.X.ConrainsRange(p.Start, p.End) || (e.Y.ConrainsRange(p.Start, p.End))) .Select(p => e.GetNewOffset(p.Start, true)) .ToHashSet(); foreach (var item in _foldingManager.AllFoldings) { if (dic.Contains(item.StartOffset)) { item.IsFolded = true; } } }
public CharacterControlGump( Account first, Account second, string ErrorMessage, SwapInfo s ) : base( 50, 50 ) { Closable=true; Disposable=false; Dragable=true; Resizable=false; a1=first; a2=second; swap = s; AddPage(0); #region Gump Prettification AddBackground(16, 12, 350, 450, 9270); AddImage(190, 22, 9273); AddImage(128, 385, 9271); AddImage(180, 22, 9275); AddImage(190, 100, 9273); AddImage(180, 100, 9275); AddImage(233, 385, 9271); AddImage(26, 385, 9271); AddAlphaRegion(15, 10, 352, 454); #endregion if( !InSwapMode ) { AddButton(176, 49, 4023, 4025, 1, GumpButtonType.Reply, 0); //Okay for acct names button AddHtml( 30, 395, 325, 56, Color( Center( ErrorMessage ), 0xFF0000 ) , false, false); AddImageTiled( 33, 50, 140, 20, 0xBBC ); AddImageTiled( 209, 50, 140, 20, 0xBBC ); AddTextEntry(33, 50, 140, 20, 1152, 2, ""); AddTextEntry(209, 50, 140, 20, 1152, 3, ""); } AddLabel(58, 28, 1152, (first == null) ? "1st Acct Name" : first.ToString() ); AddLabel(232, 28, 1152, (second == null) ? "2nd Acct Name" : second.ToString()); #region Create Character Buttons int x = 50; //x is 225 for 2nd... for( int h = 0; h < 2; h++ ) { if( first != null ) { int y = 87; for( int i = 0; i < 6; i++ ) //6 because of 6th char slot and we can handle nulls & out of bounds fine { Mobile m = first[i]; if( m == null ) continue; if( !(InSwapMode && swap.AlreadyChose( first )) ) AddButton( x-20, y+3, 5601, 5605, 10*i + h*100 + 5, GumpButtonType.Reply, 0); //The Swap Select button AddLabel( x, y, 1152, String.Format( "{0} (0x{1:X})", m.Name, m.Serial.Value ) ); int labelY = y+23; int buttonY = y+27; AddLabel( x+1, labelY, 1152, "Swap" ); if( second != null && !InSwapMode && HasSpace( second ) != 0 ) AddButton( x-15, buttonY, 11400, 11402, 10*i + h*100 + 6, GumpButtonType.Reply, 0 ); else AddImage( x-15, buttonY, 11412 ); AddLabel( x+54, labelY, 1152, "Del" ); if( !InSwapMode ) AddButton( x+36, buttonY, 11400, 11402, 10*i + h*100 + 7, GumpButtonType.Reply, 0 ); else AddImage( x+36, buttonY, 11412 ); AddLabel( x+95, labelY, 1152, "Move"); if( !InSwapMode && second != null && HasSpace( second ) >=0 ) AddButton( x+78, buttonY, 11400, 11402, 10*i + h*100 + 8, GumpButtonType.Reply, 0 ); else AddImage( x+78, buttonY, 11412 ); y += 48; } } x+=175; Account temp = first; first = second; second = temp; } #endregion }
public override void OnResponse( NetState state, RelayInfo info ) { bool SendGumpAgain = true; Mobile m = state.Mobile; if( m.AccessLevel < AccessLevel.Administrator ) return; #region Sanity if( IsDeleted( a1 ) ) a1 = null; if( IsDeleted( a2 ) ) a2 = null; #endregion int id = info.ButtonID; if( id == 0 ) { if( InSwapMode ) m.SendGump( new CharacterControlGump( a1, a2, "Character swap canceled" ) ); } if( id == 1 ) { #region Find Acct from Input string firstStr = info.GetTextEntry( 2 ).Text; string secondStr = info.GetTextEntry( 3 ).Text; Account first = Accounts.GetAccount( firstStr ); Account second = Accounts.GetAccount( secondStr ); string ErrorMessage = ""; if( first == null || second == null ) { if( first == null && firstStr != "" && secondStr == "" ) ErrorMessage = String.Format( "Account: '{0}' NOT found", firstStr ); else if( second == null && secondStr != "" && firstStr == "" ) ErrorMessage = String.Format( "Account: '{0}' NOT found", secondStr ); else if( firstStr == "" && secondStr == "" ) ErrorMessage = "Please enter in an Account name"; else if( second == null && first == null ) ErrorMessage = String.Format( "Accounts: '{0}' and '{1}' NOT found", firstStr, secondStr ); } if( a1 != null && first == null ) first = a1; if( a2 != null && second == null ) second = a2; m.SendGump( new CharacterControlGump( first, second, ErrorMessage) ); #endregion } else if( id > 4 ) //left side { #region Sanity & Declarations int button = id % 10; int charIndex =(( id < 100 )? id : (id-100)) / 10; string error = "Invalid Button"; Account acct; Account secondAcct; acct = ( id >= 100 ) ? a2 : a1; secondAcct = ( id < 100 ) ? a2 : a1; if( IsDeleted( acct ) ) error = "Selected Account is null or Deleted"; else if( acct[charIndex] == null ) error = "That character is not found"; #endregion else { Mobile mob = acct[charIndex]; switch( button ) { #region Swap case 5: //Swap Selection And/Or Props { if( InSwapMode ) { if( !swap.AlreadyChose( acct ) && !swap.AlreadyChose( secondAcct )) { //Both Empty, even though this should NEVER happen. Just a sanity check swap.a1 = acct; swap.a1CharIndex = charIndex; error = "Please choose a character from the Other acct to swap with"; } else if( (swap.AlreadyChose( swap.a1 ) && !swap.AlreadyChose( swap.a2 )) || (swap.AlreadyChose( swap.a2 ) && !swap.AlreadyChose( swap.a1 )) ) { //First is filled, second is empty if( swap.AlreadyChose( swap.a1 ) ) { swap.a2 = acct; swap.a2CharIndex = charIndex; } else { swap.a1 = acct; swap.a1CharIndex = charIndex; } if( swap.SwapEm() ) { error = String.Format( "Mobile {0} (0x{1:X}) and Mobile {2} (0x{3:X}) sucessfully swapped between Accounts {4} and {5}", swap.a1[swap.a1CharIndex], ((Mobile)swap.a1[swap.a1CharIndex]).Serial.Value, swap.a2[swap.a2CharIndex], ((Mobile)swap.a2[swap.a2CharIndex]).Serial.Value, swap.a2.ToString(), swap.a1.ToString() ); CommandLogging.WriteLine( m, error ); } else error = "Swap unsucessful"; swap = null; } } else { m.SendGump( new PropertiesGump( m, mob ) ); error = "Properties gump sent"; } break; } case 6: //Swap { if( IsDeleted( secondAcct ) ) { error = "Both accounts must exist to swap characters"; } else if( HasSpace( acct ) == 0 || HasSpace( secondAcct ) == 0 ) { error = "Both accounts must have at least one character to swap."; } else { error = "Please Choose the other character to swap."; swap = new SwapInfo( a1, a2 ); if( acct == a1 ) swap.a1CharIndex = charIndex; else swap.a2CharIndex = charIndex; } break; } #endregion #region Delete Character case 7: //Del { object[] o = new object[]{acct, mob, this }; m.SendGump( new WarningGump( 1060635, 30720, String.Format( "You are about to delete Mobile {0} (0x{1:X}) of Acct {2}. This can not be reversed without a complete server revert. Please note that this'll delete any items on that Character, but it'll still leave their house standing. Do you wish to continue?", mob.Name, mob.Serial.Value, acct.ToString() ), 0xFFC000, 360, 260, new WarningGumpCallback( CharacterDelete_Callback ), o ) ); SendGumpAgain = false; break; } #endregion #region Move Character case 8: //Move { if( secondAcct == null ) { error = String.Format( "Can't move Mobile {0} (0x{1:X} because the other account is null", mob.Name, mob.Serial.Value ); break; } int newCharLocation = HasSpace( secondAcct ); if( newCharLocation < 0 ) { error = String.Format( "Can't move Mobile {0} (0x{1:X}) to account {2} because that account is full", mob.Name, mob.Serial.Value, secondAcct.ToString() ); break; } acct[charIndex] = null; secondAcct[newCharLocation] = mob; mob.Say( "I've been moved to another Account!" ); if( mob.NetState != null ) mob.NetState.Dispose(); error = String.Format( "Mobile {0} (0x{1:X}) of Account {2} moved to Account {3}.", mob.Name, mob.Serial.Value, acct.ToString(), secondAcct.ToString() ); CommandLogging.WriteLine( m, error ); break; } #endregion } } if( SendGumpAgain ) m.SendGump( new CharacterControlGump( a1, a2, error, swap ) ); } }
public CharacterControlGump(Account first, Account second, string ErrorMessage, SwapInfo si) : base(50, 50) { Closable = true; Disposable = false; Dragable = true; Resizable = false; _firstAccount = first; _secondAccount = second; _swapInfo = si; AddPage(0); AddBackground(16, 12, 350, 450, 9270); AddAlphaRegion(15, 10, 352, 454); AddImage(190, 22, 9273); AddImage(128, 385, 9271); AddImage(180, 22, 9275); AddImage(190, 100, 9273); AddImage(180, 100, 9275); AddImage(233, 385, 9271); AddImage(26, 385, 9271); if (!InSwapMode) { AddButton(176, 49, 4023, 4025, 1, GumpButtonType.Reply, 0); //Okay for acct names button AddHtml(30, 395, 325, 56, Color(Center(ErrorMessage), 0xFF0000), false, false); AddImageTiled(33, 50, 140, 20, 0xBBC); AddImageTiled(209, 50, 140, 20, 0xBBC); AddTextEntry(33, 50, 140, 20, 1152, 2, ""); AddTextEntry(209, 50, 140, 20, 1152, 3, ""); } AddLabel(58, 28, 1152, (first == null) ? "1st Acct Name" : first.ToString()); AddLabel(232, 28, 1152, (second == null) ? "2nd Acct Name" : second.ToString()); #region Create Character Buttons int x = 50; //x is 225 for 2nd... for (int h = 0; h < 2; h++) { if (first != null) { int y = 87; for (int i = 0; i < 6; i++) //6 because of 6th char slot and we can handle nulls & out of bounds fine { Mobile m = first[i]; if (m == null) { continue; } if (!(InSwapMode && _swapInfo.AlreadyChose(first))) { AddButton(x - 20, y + 3, 5601, 5605, 10 * i + h * 100 + 5, GumpButtonType.Reply, 0); //The Swap Select button } AddLabel(x, y, 1152, String.Format("{0} (0x{1:X})", m.Name, m.Serial.Value)); int labelY = y + 23; int buttonY = y + 27; AddLabel(x + 1, labelY, 1152, "Swap"); if (second != null && !InSwapMode && HasSpace(second) != 0) { AddButton(x - 15, buttonY, 1210, 1209, 10 * i + h * 100 + 6, GumpButtonType.Reply, 0); } else { AddImage(x - 15, buttonY, 11412); } AddLabel(x + 54, labelY, 1152, "Del"); if (!InSwapMode) { AddButton(x + 36, buttonY, 1210, 1209, 10 * i + h * 100 + 7, GumpButtonType.Reply, 0); } else { AddImage(x + 36, buttonY, 11412); } AddLabel(x + 95, labelY, 1152, "Move"); if (!InSwapMode && second != null && HasSpace(second) >= 0) { AddButton(x + 78, buttonY, 1210, 1209, 10 * i + h * 100 + 8, GumpButtonType.Reply, 0); } else { AddImage(x + 78, buttonY, 11412); } y += 48; } } x += 175; Account temp = first; first = second; second = temp; } #endregion }
public override void OnResponse(NetState state, RelayInfo info) { bool SendGumpAgain = true; Mobile m = state.Mobile; if (m.AccessLevel < AccessLevel.Administrator) { return; } #region Sanity if (IsDeleted(_firstAccount)) { _firstAccount = null; } if (IsDeleted(_secondAccount)) { _secondAccount = null; } #endregion int id = info.ButtonID; if (id == 0) { if (InSwapMode) { m.SendGump(new CharacterControlGump(_firstAccount, _secondAccount, "Character _swapInfo canceled")); } } if (id == 1) { #region Find Acct from Input string firstStr = info.GetTextEntry(2).Text; string secondStr = info.GetTextEntry(3).Text; Account first = Accounts.GetAccount(firstStr) as Account; Account second = Accounts.GetAccount(secondStr) as Account; string ErrorMessage = ""; if (first == null || second == null) { if (first == null && firstStr != "" && secondStr == "") { ErrorMessage = String.Format("Account: '{0}' NOT found", firstStr); } else if (second == null && secondStr != "" && firstStr == "") { ErrorMessage = String.Format("Account: '{0}' NOT found", secondStr); } else if (firstStr == "" && secondStr == "") { ErrorMessage = "Please enter in an Account name"; } else if (second == null && first == null) { ErrorMessage = String.Format("Accounts: '{0}' and '{1}' NOT found", firstStr, secondStr); } } if (_firstAccount != null && first == null) { first = _firstAccount; } if (_secondAccount != null && second == null) { second = _secondAccount; } m.SendGump(new CharacterControlGump(first, second, ErrorMessage)); #endregion } else if (id > 4) //left side { #region Sanity & Declarations int button = id % 10; int charIndex = ((id < 100) ? id : (id - 100)) / 10; string error = "Invalid Button"; Account acct; Account secondAcct; acct = (id >= 100) ? _secondAccount : _firstAccount; secondAcct = (id < 100) ? _secondAccount : _firstAccount; if (IsDeleted(acct)) { error = "Selected Account is null or Deleted"; } else if (acct[charIndex] == null) { error = "That character is not found"; } #endregion else { Mobile mob = acct[charIndex]; switch (button) { #region Swap case 5: //Swap Selection And/Or Props { if (InSwapMode) { if (!_swapInfo.AlreadyChose(acct) && !_swapInfo.AlreadyChose(secondAcct)) { //Both Empty, even though this should NEVER happen. Just a sanity check _swapInfo.a1 = acct; _swapInfo.a1CharIndex = charIndex; error = "Please choose a character from the other acct to _swapInfo with"; } else if ((_swapInfo.AlreadyChose(_swapInfo.a1) && !_swapInfo.AlreadyChose(_swapInfo._secondAccount)) || (_swapInfo.AlreadyChose(_swapInfo._secondAccount) && !_swapInfo.AlreadyChose(_swapInfo.a1))) { //First is filled, second is empty if (_swapInfo.AlreadyChose(_swapInfo.a1)) { _swapInfo._secondAccount = acct; _swapInfo._secondAccountCharIndex = charIndex; } else { _swapInfo.a1 = acct; _swapInfo.a1CharIndex = charIndex; } if (_swapInfo.SwapEm()) { error = String.Format("Mobile {0} (0x{1:X}) and Mobile {2} (0x{3:X}) sucessfully _swapInfoped between Accounts {4} and {5}", _swapInfo.a1[_swapInfo.a1CharIndex], ((Mobile)_swapInfo.a1[_swapInfo.a1CharIndex]).Serial.Value, _swapInfo._secondAccount[_swapInfo._secondAccountCharIndex], ((Mobile)_swapInfo._secondAccount[_swapInfo._secondAccountCharIndex]).Serial.Value, _swapInfo._secondAccount.ToString(), _swapInfo.a1.ToString()); CommandLogging.WriteLine(m, error); } else { error = "Swap unsucessful"; } _swapInfo = null; } } else { m.SendGump(new PropertiesGump(m, mob)); error = "Properties gump sent"; } break; } case 6: //Swap { if (IsDeleted(secondAcct)) { error = "Both accounts must exist to _swapInfo characters"; } else if (HasSpace(acct) == 0 || HasSpace(secondAcct) == 0) { error = "Both accounts must have at least one character to _swapInfo."; } else { error = "Please Choose the other character to _swapInfo."; _swapInfo = new SwapInfo(_firstAccount, _secondAccount); if (acct == _firstAccount) { _swapInfo.a1CharIndex = charIndex; } else { _swapInfo._secondAccountCharIndex = charIndex; } } break; } #endregion #region Delete Character case 7: //Del { object[] o = new object[] { acct, mob, this }; m.SendGump( new WarningGump(1060635, 30720, String.Format("You are about to delete Mobile {0} (0x{1:X}) of Acct {2}. This can not be reversed without a complete server revert. Please note that this'll delete any items on that Character, but it'll still leave their house standing. Do you wish to continue?", mob.Name, mob.Serial.Value, acct.ToString()), 0xFFC000, 360, 260, new WarningGumpCallback(CharacterDelete_Callback), o)); SendGumpAgain = false; break; } #endregion #region Move Character case 8: //Move { if (secondAcct == null) { error = String.Format("Can't move Mobile {0} (0x{1:X} because the other account is null", mob.Name, mob.Serial.Value); break; } int newCharLocation = HasSpace(secondAcct); if (newCharLocation < 0) { error = String.Format("Can't move Mobile {0} (0x{1:X}) to account {2} because that account is full", mob.Name, mob.Serial.Value, secondAcct.ToString()); break; } acct[charIndex] = null; secondAcct[newCharLocation] = mob; if (mob.NetState != null) { mob.NetState.Dispose(); } error = String.Format("Mobile {0} (0x{1:X}) of Account {2} moved to Account {3}.", mob.Name, mob.Serial.Value, acct.ToString(), secondAcct.ToString()); CommandLogging.WriteLine(m, error); break; } #endregion } } if (SendGumpAgain) { m.SendGump(new CharacterControlGump(_firstAccount, _secondAccount, error, _swapInfo)); } } }
/// <summary> /// Sets <see cref="SetNewRenderOrder"/>. /// </summary> private void SetNewRenderOrder() { var swapInfo = ThisSwap; swapInfo.NewRenderOrder = true; ThisSwap = swapInfo; }
/// <summary> /// Sets <see cref="DidBecomeInvisible"/> on invisible. /// </summary> private void BecomeInvisible() { var swapInfo = ThisSwap; swapInfo.DidBecomeInvisible = true; ThisSwap = swapInfo; }
/// <summary> /// Sets <see cref="NewVertexColors"/>. /// </summary> private void SetNewVertexColors() { var swapInfo = ThisSwap; swapInfo.NewVertexColors = true; ThisSwap = swapInfo; }
/// <summary> /// Sets <see cref="NewVertexPositions"/>. /// </summary> private void SetNewVertexPositions() { var swapInfo = ThisSwap; swapInfo.NewVertexPositions = true; ThisSwap = swapInfo; }