using System;
using System.Collections.Generic;
using System.Text;
//---------------------------------------------------------------------------------------------------------------------------------------------------
//
// Copyright (C)2007 DarkWynter Studios. All rights reserved.
//
//---------------------------------------------------------------------------------------------------------------------------------------------------
// {Contact : darkwynter.com for licensing information
//---------------------------------------------------------------------------------------------------------------------------------------------------
namespace DarkWynter.App.ChallengeSet
{
#region Using Statements
using DarkWynter.Engine.Globals;
using System.Xml;
using Microsoft.Xna.Framework;
using DarkWynter.Engine.Utilities;
#endregion
///
///
///
public class Challenge4 : ChallengeAbstract
{
string noForLoops = "for";
string whileCheck = "while (isBubble && bubbleCounter >= 0)";
string whileCheck2 = "while (step < 11)";
string stepCounter1 = "step ++";
string stepCounter2 = "step = step + 1";
string bombCounter1 = "bubbleCounter --";
string bombCounter2 = "bubbleCounter = bubbleCounter - 1";
string outCheckBridge1 = "You built step 1 of the bridge.";
string outCheckBridge2 = "You built step 10 of the bridge.";
string outCheckBomb3 = "You poppped bubble 3.";
string outCheckBomb2 = "You poppped bubble 2.";
string outCheckBomb1 = "You poppped bubble 1.";
string outCheckBomb0 = "You poppped bubble 0.";
///
/// Constructor
///
/// XML Node
public Challenge4(XmlNode problemNode)
: base(problemNode)
{
this.id = 4;
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()
{
// insert three variables here
// bool isBubble
// int bubbleCounter
// int step
// insert first while loop logic here
// use two checks and && (ampersand) them together
{
// insert second while loop logic here
{
// Call the CompilerMethods.buildBridge(int)
// increment step
}
// Call the CompilerMethods.burstBubble(int, bool)
// decrement bubbleCounter
}
// set bool to false
// Write the result of the bool using Console.WriteLine();
}
}
";
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)) // no for loops
{
if (studentCode.Contains(whileCheck)) // first while
{
if (studentCode.Contains(whileCheck2)) // nested while
{
if (studentCode.Contains(stepCounter1) || studentCode.Contains(stepCounter2)) // bridge counter incremented?
{
if (studentCode.Contains(bombCounter1) || studentCode.Contains(bombCounter2)) // bomb counter incremented?
{
// Check output
if (studentOutput.StartsWith(outCheckBridge1)) // does it begin with 1?
{
if (studentOutput.Contains(outCheckBridge2)) // does it end with 10?
{
if (studentOutput.Contains(outCheckBomb3) && studentOutput.Contains(outCheckBomb2)
&& studentOutput.Contains(outCheckBomb1) && studentOutput.Contains(outCheckBomb0)) // is the bomboutput correct?
{
if (studentCode.Contains("false")) // did the bool get flipped to false?
{
Statics_Engine.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 did not change boolean [End Error Message]");
App.CompilerControl.customErrorMessage = "Print out the results of the boolean in the Console.WriteLine statement.";
Statics_Engine.GameSettings.triesNumber++;
return false;
}
else Logging.G2LLogList.Add(DateTime.Now.ToString() + " - [Error Message] - Student bomb output incorrect [End Error Message]");
App.CompilerControl.customErrorMessage = "Check your bomb counter - make sure you are decrementing the number and that you end at 0. Try again.";
Statics_Engine.GameSettings.triesNumber++;
return false;
}
else Logging.G2LLogList.Add(DateTime.Now.ToString() + " - [Error Message] - Student bridge 2 output 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++;
return false;
}
else Logging.G2LLogList.Add(DateTime.Now.ToString() + " - [Error Message] - Student bridge 1 output 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 used bridge counter correctly [End Error Message]");
App.CompilerControl.customErrorMessage = "Check your bomb counter - make sure you are decrementing the number. Try again.";
Statics_Engine.GameSettings.triesNumber++;
return false;
}
else Logging.G2LLogList.Add(DateTime.Now.ToString() + " - [Error Message] - Student used bomb counter correctly [End Error Message]");
App.CompilerControl.customErrorMessage = "Check your bridge counter - make sure you are incrementing the number. Try again.";
Statics_Engine.GameSettings.triesNumber++;
return false;
}
else Logging.G2LLogList.Add(DateTime.Now.ToString() + " - [Error Message] - Student used a second while loop correctly [End Error Message]");
App.CompilerControl.customErrorMessage = "Check your second while loop - make sure you are counting it ten times and that the equality is correct. Try again.";
Statics_Engine.GameSettings.triesNumber++;
return false;
}
else Logging.G2LLogList.Add(DateTime.Now.ToString() + " - [Error Message] - Student used a first while loop correctly [End Error Message]");
App.CompilerControl.customErrorMessage = "Check your while loop - isBombArmed is first and the bombCounter is second. Ampersands are &&. 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(0.0f, 0.0f, 20.0f);
// to get from island 4 to island 1, start at 82, 0, 20 and end up at 35, 0, 20
// Set start and endpoints of line
Vector3 StartPosition = new Vector3(85, 0, 20);
Vector3 EndPosition = new Vector3(35, 0, 20);
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;
}
}
}