//--------------------------------------------------------------------------------------------------------------------------------------------------- // // Copyright (C)2007 DarkWynter Studios. All rights reserved. // //--------------------------------------------------------------------------------------------------------------------------------------------------- // {Contact : darkwynter.com for licensing information //--------------------------------------------------------------------------------------------------------------------------------------------------- namespace DarkWynter.App.ChallengeSet { #region Using Statements using System; using System.Collections.Generic; using System.Text; using DarkWynter.Engine.Globals; using System.Xml; using Microsoft.Xna.Framework; using DarkWynter.Engine.Utilities; #endregion /// /// /// public class Challenge3 : ChallengeAbstract { string noForLoops = "for"; string whileChecks = "while"; string checkCounter = "buildBridge(step)"; string outCheckBridge1 = "You built step 1 of the bridge."; string outCheckBridge2 = "You built step 10 of the bridge."; /// /// Constructor /// /// XML Node public Challenge3(XmlNode problemNode) : base(problemNode) { this.id = 3; foreach (XmlNode instrNode in problemNode) { challengeDialogue.Add(instrNode.Attributes["text"].Value); } } /// /// Scaffolding for the challenge /// /// challengeSource public override string GetScaffolding() { challengeSource = @"using System; using DarkWynter.Engine.Compiler; public class Test { public static void MyFunction() { // Method to build the bridges // You need to give the method an int int step = 1; CompilerMethods.buildBridge(); step ++; } } "; return challengeSource; } /// /// Parses the student code for validity /// /// Student's Code /// Output from the compiler /// bool public override bool ValidateStudentCode(string studentCode, string studentOutput) { // If base fails, return if (!base.ValidateStudentCode(studentCode, studentOutput)) { return false; } //return true; // Check input if (!studentCode.Contains(noForLoops)) // did they use a for loop? { if (studentCode.Contains(whileChecks)) // did they use a while loop? { if (studentCode.Contains(checkCounter)) // is the counter in the right place? { // Check output if (studentOutput.StartsWith(outCheckBridge1)) // start with one? { if (studentOutput.Contains(outCheckBridge2)) // end with 10? { Statics_Engine.GameSettings.triesNumber++; Logging.G2LLogList.Add(DateTime.Now.ToString() + " - [Success Message] Student input and output correct [End Success Message]"); base.setExpPoints(); return true; } else Logging.G2LLogList.Add(DateTime.Now.ToString() + " - [Error Message] Output 2 incorrect [End Error Message]"); App.CompilerControl.customErrorMessage = "The final int you pass into the bridgeBuilder method must be 10. Try again."; Statics_Engine.GameSettings.triesNumber++; App.CompilerControl.customErrorMessage = null; return false; } else Logging.G2LLogList.Add(DateTime.Now.ToString() + " - [Error Message] Output 1 incorrect [End Error Message]"); App.CompilerControl.customErrorMessage = "The first int you pass into the bridgeBuilder method must be 1. Try again."; Statics_Engine.GameSettings.triesNumber++; return false; } else Logging.G2LLogList.Add(DateTime.Now.ToString() + " - [Error Message] Student did not place the counter correctly for the method[End Error Message]"); App.CompilerControl.customErrorMessage = "You need to pass the variable step into the buildBridge method."; Statics_Engine.GameSettings.triesNumber++; return false; } else Logging.G2LLogList.Add(DateTime.Now.ToString() + " - [Error Message] Student used a while loop correctly [End Error Message]"); App.CompilerControl.customErrorMessage = "Use a while loop. Try again."; Statics_Engine.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 a while loop instead. Try again."; Statics_Engine.GameSettings.triesNumber++; return false; } /// /// Run the set visualization /// /// bool public override bool RunVizualization() { float amount = 6.0f; int radius = 2; Vector3 position = new Vector3(95.0f, 0.0f, 0.0f); // to get from island 3 to island 4, start at 95, 0, 79 and end up at 95, 0, 28 // Set start and endpoints of line Vector3 StartPosition = new Vector3(95, 0, 82); Vector3 EndPosition = new Vector3(95, 0, 28); TerrainModRequest request = new TerrainModRequest(terrainTimer, amount, StartPosition, EndPosition, radius, Enums_Engine.TerrainModType.EQUALTO); // Mod the terrain base.NonControllerBasedTerrainMod(request); Statics_Engine.GameSettings.isProblemFinished = true; return true; } } }