using System; using System.Collections.Generic; using System.Text; using DarkWynter.Game.Globals; using DarkWynter.Engine.Globals; using System.Xml; using Microsoft.Xna.Framework; using DarkWynter.Engine.Utilities; namespace DarkWynter.App.ChallengeSet { public class Challenge2 : ChallengeAbstract { string noForLoops = "for"; string whileChecks = "while"; string outCheckBridge1 = "You built step 1 of the bridge."; string outCheckBridge2 = "You built step 10 of the bridge."; public Challenge2(XmlNode problemNode) : base(problemNode) { this.id = 2; foreach (XmlNode instrNode in problemNode) { challengeDialogue.Add(instrNode.Attributes["text"].Value); } } public override string GetScaffolding() { challengeSource = @"using System; using DarkWynter.Engine.Compiler; public class Test { public static void MyFunction() { // This is the Method to build the bridges // You need to give the method an int CompilerMethods.buildBridge(); } } "; return challengeSource; } public override bool ValidateStudentCode(string studentCode, string studentOutput) { // If base fails, return if (!base.ValidateStudentCode(studentCode, studentOutput)) { return false; } // return true; string test = studentOutput.Normalize(); // Check input if (!studentCode.Contains(noForLoops)) // is there a for loop? { if (!studentCode.Contains(whileChecks)) // is there a while loop? { // Check output if (studentOutput.StartsWith(outCheckBridge1)) // does it begin with 1? { if (studentOutput.Contains(outCheckBridge2)) // does it end with 10? { Statics_Game.GameSettings.triesNumber++; Logging.G2LLogList.Add(DateTime.Now.ToString() + " - [Success Message] Student input and output correct [End Success Message]"); App.CompilerControl.customErrorMessage = null; base.setExpPoints(); return true; } else Logging.G2LLogList.Add(DateTime.Now.ToString() + " - [Error Message] Student output is incorrect [End Error Message]"); App.CompilerControl.customErrorMessage = "The final int you pass into the bridgeBuilder method must be 10. Try again."; Statics_Game.GameSettings.triesNumber++; return false; } else Logging.G2LLogList.Add(DateTime.Now.ToString() + " - [Error Message] Student output is incorrect [End Error Message]"); App.CompilerControl.customErrorMessage = "The first int you pass into the bridgeBuilder method must be 1. Try again."; Statics_Game.GameSettings.triesNumber++; return false; } else Logging.G2LLogList.Add(DateTime.Now.ToString() + " - [Error Message] Student used a while loop [End Error Message]"); App.CompilerControl.customErrorMessage = "Do not use a while loop in your code. Use brute force instead. Try again."; Statics_Game.GameSettings.triesNumber++; return false; } else Logging.G2LLogList.Add(DateTime.Now.ToString() + " - [Error Message] Student used a for loop [End Error Message]"); App.CompilerControl.customErrorMessage = "Do not use a for loop in your code. Use brute force instead. Try again."; Statics_Game.GameSettings.triesNumber++; return false; } public override bool RunVizualization() { float amount = 6.0f; int radius = 2; // to get from island 2 to island 3, start at 26, 0, 103 and end up at 78, 0, 103 // Set start and endpoints of line Vector3 StartPosition = new Vector3(23, 0, 103); Vector3 EndPosition = new Vector3(81, 0, 103); TerrainModRequest request = new TerrainModRequest(amount, StartPosition, EndPosition, radius, Enums_Engine.TerrainModType.EQUALTO); // Mod the terrain base.NonControllerBasedTerrainMod(request); Statics_Game.GameSettings.isProblemFinished = true; return true; } } }