| @@ -0,0 +1,26 @@ | ||
|
|
||
| Microsoft Visual Studio Solution File, Format Version 12.00 | ||
| # Visual Studio 14 | ||
| VisualStudioVersion = 14.0.24720.0 | ||
| MinimumVisualStudioVersion = 10.0.40219.1 | ||
| Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "AssignmentComplete", "AssignmentComplete\AssignmentComplete.csproj", "{71BA39BA-984E-4CCE-A80C-1AADCA36927B}" | ||
| EndProject | ||
| Global | ||
| GlobalSection(SolutionConfigurationPlatforms) = preSolution | ||
| Debug|Any CPU = Debug|Any CPU | ||
| Debug|x86 = Debug|x86 | ||
| Release|Any CPU = Release|Any CPU | ||
| Release|x86 = Release|x86 | ||
| EndGlobalSection | ||
| GlobalSection(ProjectConfigurationPlatforms) = postSolution | ||
| {71BA39BA-984E-4CCE-A80C-1AADCA36927B}.Debug|Any CPU.ActiveCfg = Debug|x86 | ||
| {71BA39BA-984E-4CCE-A80C-1AADCA36927B}.Debug|x86.ActiveCfg = Debug|x86 | ||
| {71BA39BA-984E-4CCE-A80C-1AADCA36927B}.Debug|x86.Build.0 = Debug|x86 | ||
| {71BA39BA-984E-4CCE-A80C-1AADCA36927B}.Release|Any CPU.ActiveCfg = Release|x86 | ||
| {71BA39BA-984E-4CCE-A80C-1AADCA36927B}.Release|x86.ActiveCfg = Release|x86 | ||
| {71BA39BA-984E-4CCE-A80C-1AADCA36927B}.Release|x86.Build.0 = Release|x86 | ||
| EndGlobalSection | ||
| GlobalSection(SolutionProperties) = preSolution | ||
| HideSolutionNode = FALSE | ||
| EndGlobalSection | ||
| EndGlobal |
| @@ -0,0 +1,104 @@ | ||
| <?xml version="1.0" encoding="utf-8"?> | ||
| <Project ToolsVersion="4.0" DefaultTargets="Build" xmlns="http://schemas.microsoft.com/developer/msbuild/2003"> | ||
| <PropertyGroup> | ||
| <Configuration Condition=" '$(Configuration)' == '' ">Debug</Configuration> | ||
| <Platform Condition=" '$(Platform)' == '' ">x86</Platform> | ||
| <ProductVersion>8.0.30703</ProductVersion> | ||
| <SchemaVersion>2.0</SchemaVersion> | ||
| <ProjectGuid>{71BA39BA-984E-4CCE-A80C-1AADCA36927B}</ProjectGuid> | ||
| <OutputType>Exe</OutputType> | ||
| <AppDesignerFolder>Properties</AppDesignerFolder> | ||
| <RootNamespace>AssignmentComplete</RootNamespace> | ||
| <AssemblyName>AssignmentComplete</AssemblyName> | ||
| <FileAlignment>512</FileAlignment> | ||
| <MonoGamePlatform>Windows</MonoGamePlatform> | ||
| <MonoGameContentBuilderExe> | ||
| </MonoGameContentBuilderExe> | ||
| </PropertyGroup> | ||
| <PropertyGroup Condition=" '$(Configuration)|$(Platform)' == 'Debug|x86' "> | ||
| <PlatformTarget>x86</PlatformTarget> | ||
| <DebugSymbols>true</DebugSymbols> | ||
| <DebugType>full</DebugType> | ||
| <Optimize>false</Optimize> | ||
| <OutputPath>bin\Windows\Debug\</OutputPath> | ||
| <DefineConstants>DEBUG;TRACE;WINDOWS</DefineConstants> | ||
| <ErrorReport>prompt</ErrorReport> | ||
| <WarningLevel>4</WarningLevel> | ||
| </PropertyGroup> | ||
| <PropertyGroup Condition=" '$(Configuration)|$(Platform)' == 'Release|x86' "> | ||
| <PlatformTarget>x86</PlatformTarget> | ||
| <DebugType>pdbonly</DebugType> | ||
| <Optimize>true</Optimize> | ||
| <OutputPath>bin\Windows\Release\</OutputPath> | ||
| <DefineConstants>TRACE;WINDOWS</DefineConstants> | ||
| <ErrorReport>prompt</ErrorReport> | ||
| <WarningLevel>4</WarningLevel> | ||
| </PropertyGroup> | ||
| <PropertyGroup> | ||
| <ApplicationIcon>Icon.ico</ApplicationIcon> | ||
| </PropertyGroup> | ||
| <PropertyGroup> | ||
| <StartupObject /> | ||
| </PropertyGroup> | ||
| <ItemGroup> | ||
| <Compile Include="Factory.cs" /> | ||
| <Compile Include="Game1.cs" /> | ||
| <Compile Include="GameState.cs" /> | ||
| <Compile Include="IComponent.cs" /> | ||
| <Compile Include="IFactory.cs" /> | ||
| <Compile Include="IContainer.cs" /> | ||
| <Compile Include="ITruck.cs" /> | ||
| <Compile Include="Program.cs" /> | ||
| <Compile Include="Properties\AssemblyInfo.cs" /> | ||
| <Compile Include="StateMachine.cs" /> | ||
| <Compile Include="Container.cs" /> | ||
| <Compile Include="Truck.cs" /> | ||
| </ItemGroup> | ||
| <ItemGroup> | ||
| <Reference Include="MonoGame.Framework"> | ||
| <HintPath>$(MSBuildProgramFiles32)\MonoGame\v3.0\Assemblies\Windows\MonoGame.Framework.dll</HintPath> | ||
| </Reference> | ||
| <Reference Include="System" /> | ||
| <Reference Include="System.Xml" /> | ||
| </ItemGroup> | ||
| <ItemGroup> | ||
| <Content Include="Content\background.png"> | ||
| <CopyToOutputDirectory>Always</CopyToOutputDirectory> | ||
| </Content> | ||
| <Content Include="Content\ikea.png"> | ||
| <CopyToOutputDirectory>Always</CopyToOutputDirectory> | ||
| </Content> | ||
| <Content Include="Content\mine.png"> | ||
| <CopyToOutputDirectory>Always</CopyToOutputDirectory> | ||
| </Content> | ||
| <Content Include="Content\mine_cart.png"> | ||
| <CopyToOutputDirectory>Always</CopyToOutputDirectory> | ||
| </Content> | ||
| <Content Include="Content\ore_container.png"> | ||
| <CopyToOutputDirectory>Always</CopyToOutputDirectory> | ||
| </Content> | ||
| <Content Include="Content\product_box.png"> | ||
| <CopyToOutputDirectory>Always</CopyToOutputDirectory> | ||
| </Content> | ||
| <Content Include="Content\product_container.png"> | ||
| <CopyToOutputDirectory>Always</CopyToOutputDirectory> | ||
| </Content> | ||
| <Content Include="Content\volvo.png"> | ||
| <CopyToOutputDirectory>Always</CopyToOutputDirectory> | ||
| </Content> | ||
| <Content Include="Icon.ico" /> | ||
| <Compile Include="IStateMachine.cs" /> | ||
| </ItemGroup> | ||
| <ItemGroup> | ||
| <MonoGameContentReference Include="Content\Content.mgcb" /> | ||
| </ItemGroup> | ||
| <Import Project="$(MSBuildToolsPath)\Microsoft.CSharp.targets" /> | ||
| <Import Project="$(MSBuildExtensionsPath)\MonoGame\v3.0\MonoGame.Content.Builder.targets" /> | ||
| <!-- To modify your build process, add your task inside one of the targets below and uncomment it. | ||
| Other similar extension points exist, see Microsoft.Common.targets. | ||
| <Target Name="BeforeBuild"> | ||
| </Target> | ||
| <Target Name="AfterBuild"> | ||
| </Target> | ||
| --> | ||
| </Project> |
| @@ -0,0 +1,62 @@ | ||
| using System; | ||
| using System.Collections.Generic; | ||
| using System.Linq; | ||
| using System.Text; | ||
| using Microsoft.Xna.Framework; | ||
| using Microsoft.Xna.Framework.Graphics; | ||
|
|
||
| namespace AssignmentComplete | ||
| { | ||
|
|
||
| public class Ore : IContainer | ||
| { | ||
| Texture2D texture; | ||
| Vector2 position = Vector2.One * -100; | ||
| int currentAmount; | ||
|
|
||
| public Ore(int amount, Texture2D texture) | ||
| { | ||
| this.texture = texture; | ||
| AddContent(amount); | ||
| } | ||
|
|
||
| public void Draw(SpriteBatch spriteBatch) | ||
| { | ||
| spriteBatch.Draw(texture, Position, Color.White); | ||
| } | ||
|
|
||
| public Vector2 Position | ||
| { | ||
| get | ||
| { | ||
| return position; | ||
| } | ||
|
|
||
| set | ||
| { | ||
| position = value; | ||
| } | ||
| } | ||
| public int CurrentAmount | ||
| { | ||
| get | ||
| { | ||
| return currentAmount; | ||
| } | ||
| } | ||
|
|
||
| public int MaxCapacity => 1000; | ||
|
|
||
|
|
||
| public bool AddContent(int amount) | ||
| { | ||
| if (CurrentAmount + amount > MaxCapacity) | ||
| { | ||
| Console.WriteLine("Too many..."); | ||
| return false; | ||
| } | ||
| currentAmount += amount; | ||
| return true; | ||
| } | ||
| } | ||
| } |
| @@ -0,0 +1,15 @@ | ||
|
|
||
| #----------------------------- Global Properties ----------------------------# | ||
|
|
||
| /outputDir:bin/Windows | ||
| /intermediateDir:obj/Windows | ||
| /platform:Windows | ||
| /config: | ||
| /profile:Reach | ||
| /compress:False | ||
|
|
||
| #-------------------------------- References --------------------------------# | ||
|
|
||
|
|
||
| #---------------------------------- Content ---------------------------------# | ||
|
|
| @@ -0,0 +1,106 @@ | ||
| using System; | ||
| using System.Collections.Generic; | ||
| using System.Linq; | ||
| using System.Text; | ||
| using Microsoft.Xna.Framework; | ||
| using Microsoft.Xna.Framework.Graphics; | ||
|
|
||
| namespace AssignmentComplete | ||
| { | ||
| class Mine : IFactory | ||
| { | ||
|
|
||
| class AddOreBoxToMine : IAction | ||
| { | ||
| Mine mine; | ||
| public AddOreBoxToMine(Mine mine) | ||
| { | ||
| this.mine = mine; | ||
| } | ||
| public void Run() | ||
| { | ||
| mine.ProductsToShip.Add(CreateOreBox(mine.Position + new Vector2(-80, 40 + -30 * mine.ProductsToShip.Count))); | ||
| } | ||
| Ore CreateOreBox(Vector2 position) | ||
| { | ||
| var box = new Ore(100, mine.oreBox); | ||
| box.Position = position; | ||
| return box; | ||
| } | ||
| } | ||
| class Test : IAction | ||
| { | ||
| public void Run() | ||
| { | ||
| Console.WriteLine("running?"); | ||
| } | ||
| } | ||
|
|
||
| Texture2D mine, oreContainer, oreBox, truckTexture; | ||
| List<IStateMachine> processes; | ||
| ITruck waitingTruck; | ||
| bool isTruckReady = false; | ||
| Vector2 position; | ||
| List<IContainer> productsToShip; | ||
|
|
||
| public Mine(Vector2 position, Texture2D truck_texture, Texture2D mine, Texture2D ore_box, Texture2D ore_container) | ||
| { | ||
| processes = new List<IStateMachine>(); | ||
| ProductsToShip = new List<IContainer>(); | ||
| this.mine = mine; | ||
| this.truckTexture = truck_texture; | ||
| this.oreContainer = ore_container; | ||
| this.oreBox = ore_box; | ||
| this.position = position; | ||
|
|
||
|
|
||
| processes.Add( | ||
| new Repeat(new Seq(new Timer(1.0f), | ||
| new Call(new AddOreBoxToMine(this))))); | ||
| processes.Add(new Repeat(new Seq(new Timer(1.0f), new Call(new Test())))); | ||
| } | ||
|
|
||
|
|
||
| public ITruck GetReadyTruck() | ||
| { | ||
| //not implemented yet | ||
| return null; | ||
| } | ||
|
|
||
| public Vector2 Position | ||
| { | ||
| get | ||
| { | ||
| return position; | ||
| } | ||
| } | ||
| public List<IContainer> ProductsToShip | ||
| { | ||
| get | ||
| { | ||
| return productsToShip; | ||
| } | ||
| set | ||
| { | ||
| productsToShip = value; | ||
| } | ||
| } | ||
| public void Draw(SpriteBatch spriteBatch) | ||
| { | ||
| foreach (var cart in ProductsToShip) | ||
| { | ||
| cart.Draw(spriteBatch); | ||
| } | ||
| spriteBatch.Draw(mine, Position, Color.White); | ||
| } | ||
| public void Update(float dt) | ||
| { | ||
| foreach (var process in processes) | ||
| { | ||
| process.Update(dt); | ||
| } | ||
| } | ||
|
|
||
| } | ||
|
|
||
| } |
| @@ -0,0 +1,66 @@ | ||
| using Microsoft.Xna.Framework; | ||
| using Microsoft.Xna.Framework.Graphics; | ||
| using Microsoft.Xna.Framework.Input; | ||
|
|
||
| namespace AssignmentComplete | ||
| { | ||
| /// <summary> | ||
| /// This is the main type for your game. | ||
| /// </summary> | ||
| public class Game1 : Game | ||
| { | ||
| GraphicsDeviceManager graphics; | ||
| SpriteBatch spriteBatch; | ||
|
|
||
| IStateMachine sm; | ||
| public Game1() | ||
| { | ||
| graphics = new GraphicsDeviceManager(this); | ||
| Content.RootDirectory = "Content"; | ||
| } | ||
|
|
||
| protected override void Initialize() | ||
| { | ||
| base.Initialize(); | ||
| } | ||
|
|
||
|
|
||
| GameState gameState; | ||
| protected override void LoadContent() | ||
| { | ||
| spriteBatch = new SpriteBatch(graphics.GraphicsDevice); | ||
| Texture2D volvo = Content.Load<Texture2D>("volvo.png"); | ||
| Texture2D mine = Content.Load<Texture2D>("mine.png"); | ||
| Texture2D ore_container = Content.Load<Texture2D>("ore_container.png"); | ||
| Texture2D product_container = Content.Load<Texture2D>("product_container.png"); | ||
| Texture2D ikea = Content.Load<Texture2D>("ikea.png"); | ||
| Texture2D background = Content.Load<Texture2D>("background.png"); | ||
| Texture2D mine_cart = Content.Load<Texture2D>("mine_cart.png"); | ||
| Texture2D product_box = Content.Load<Texture2D>("product_box.png"); | ||
| gameState = new GameState(background, mine_cart, product_box, volvo, mine, ikea, ore_container, product_container); | ||
| } | ||
|
|
||
| protected override void Update(GameTime gameTime) | ||
| { | ||
| if (GamePad.GetState(PlayerIndex.One).Buttons.Back == ButtonState.Pressed || Keyboard.GetState().IsKeyDown(Keys.Escape)) | ||
| Exit(); | ||
|
|
||
| gameState.Update((float)gameTime.ElapsedGameTime.TotalSeconds); | ||
| base.Update(gameTime); | ||
| } | ||
|
|
||
| /// <summary> | ||
| /// This is called when the game should draw itself. | ||
| /// </summary> | ||
| /// <param name="gameTime">Provides a snapshot of timing values.</param> | ||
| protected override void Draw(GameTime gameTime) | ||
| { | ||
| GraphicsDevice.Clear(Color.LightGreen); | ||
| spriteBatch.Begin(); | ||
| gameState.Draw(spriteBatch); | ||
| spriteBatch.End(); | ||
|
|
||
| base.Draw(gameTime); | ||
| } | ||
| } | ||
| } |
| @@ -0,0 +1,85 @@ | ||
| using System; | ||
| using System.Collections.Generic; | ||
| using System.Linq; | ||
| using System.Text; | ||
| using Microsoft.Xna.Framework; | ||
| using Microsoft.Xna.Framework.Graphics; | ||
|
|
||
| namespace AssignmentComplete | ||
| { | ||
| public class GameState : IComponent | ||
| { | ||
| List<ITruck> trucks; | ||
| IFactory factory1; | ||
| IFactory factory2; | ||
| List<IStateMachine> processes; | ||
| Texture2D background; | ||
|
|
||
|
|
||
| public GameState(Texture2D background, Texture2D mine_cart, Texture2D product_box, Texture2D volvo, Texture2D mine, Texture2D ikea, Texture2D ore_container, Texture2D product_container) | ||
| { | ||
| this.background = background; | ||
| factory1 = new Mine(new Vector2(100, 70), volvo, mine, mine_cart, ore_container); | ||
| factory2 = null;//new Ikea(new Vector2(600, 340), volvo, ikea, product_box, product_container); | ||
| processes = new List<IStateMachine>(); | ||
| trucks = new List<ITruck>(); | ||
|
|
||
| //this.processes = new List<IStateMachine>(); | ||
| //this.processes.Add(new Repeat(new Call(new AddTruckFromFactory(factory1, trucks)))); | ||
| //this.processes.Add(new Repeat(new Call(new AddTruckFromFactory(factory2, trucks)))); | ||
|
|
||
|
|
||
| } | ||
| public void Update(float dt) | ||
| { | ||
| trucks.RemoveAll(truck => truck.Position.X < -50 || truck.Position.X > 1000); | ||
| foreach (var process in processes) | ||
| { | ||
| process.Update(dt); | ||
| } | ||
| foreach (var truck in trucks) | ||
| { | ||
| truck.Update(dt); | ||
| } | ||
| if(factory1 != null) | ||
| factory1.Update(dt); | ||
| if(factory2 != null) | ||
| factory2.Update(dt); | ||
| } | ||
| public void Draw(SpriteBatch spriteBatch) | ||
| { | ||
| spriteBatch.Draw(background, Vector2.Zero, Color.White); | ||
|
|
||
| foreach (var truck in trucks) | ||
| { | ||
| truck.Draw(spriteBatch); | ||
| } | ||
| if(factory1 != null) | ||
| factory1.Draw(spriteBatch); | ||
| if(factory2 != null) | ||
| factory2.Draw(spriteBatch); | ||
| } | ||
| } | ||
|
|
||
| class AddTruckFromFactory : IAction | ||
| { | ||
| IFactory factory; | ||
| List<ITruck> trucks; | ||
|
|
||
| public AddTruckFromFactory(IFactory factory, List<ITruck> trucks) | ||
| { | ||
| this.factory = factory; | ||
| this.trucks = trucks; | ||
|
|
||
| } | ||
| public void Run() | ||
| { | ||
| var maybe_truck = factory.GetReadyTruck(); | ||
| if (maybe_truck != null) | ||
| { | ||
| maybe_truck.StartEngine(); | ||
| trucks.Add(maybe_truck); | ||
| } | ||
| } | ||
| } | ||
| } |
| @@ -0,0 +1,18 @@ | ||
| using System; | ||
| using System.Collections.Generic; | ||
| using System.Linq; | ||
| using System.Text; | ||
| using Microsoft.Xna.Framework.Graphics; | ||
|
|
||
| namespace AssignmentComplete | ||
| { | ||
| public interface IDrawable | ||
| { | ||
| void Draw(SpriteBatch spriteBatch); | ||
| } | ||
| public interface IUpdateable | ||
| { | ||
| void Update(float dt); | ||
| } | ||
| public interface IComponent : IDrawable, IUpdateable { } | ||
| } |
| @@ -0,0 +1,17 @@ | ||
| using System; | ||
| using System.Collections.Generic; | ||
| using System.Linq; | ||
| using System.Text; | ||
| using Microsoft.Xna.Framework.Graphics; | ||
| using Microsoft.Xna.Framework; | ||
|
|
||
| namespace AssignmentComplete | ||
| { | ||
| public interface IContainer : IDrawable | ||
| { | ||
| int CurrentAmount { get; } | ||
| int MaxCapacity { get; } | ||
| bool AddContent(int amount); | ||
| Vector2 Position { get; set; } | ||
| } | ||
| } |
| @@ -0,0 +1,19 @@ | ||
| using System; | ||
| using System.Collections.Generic; | ||
| using System.Linq; | ||
| using System.Text; | ||
| using Microsoft.Xna.Framework; | ||
| using Microsoft.Xna.Framework.Graphics; | ||
|
|
||
| namespace AssignmentComplete | ||
| { | ||
|
|
||
| public interface IFactory : IComponent | ||
| { | ||
| Vector2 Position { get; } | ||
| List<IContainer> ProductsToShip { get; } | ||
| ITruck GetReadyTruck(); | ||
|
|
||
|
|
||
| } | ||
| } |
| @@ -0,0 +1,17 @@ | ||
| using System; | ||
| using System.Collections.Generic; | ||
| using System.Linq; | ||
| using System.Text; | ||
|
|
||
| namespace AssignmentComplete | ||
| { | ||
| public interface IStateMachine : IUpdateable | ||
| { | ||
| bool Busy { get; } | ||
| void Reset(); | ||
| } | ||
|
|
||
| public interface IAction { | ||
| void Run(); | ||
| } | ||
| } |
| @@ -0,0 +1,18 @@ | ||
| using System; | ||
| using System.Collections.Generic; | ||
| using System.Linq; | ||
| using System.Text; | ||
| using Microsoft.Xna.Framework; | ||
| using Microsoft.Xna.Framework.Graphics; | ||
|
|
||
| namespace AssignmentComplete | ||
| { | ||
| public interface ITruck : IComponent | ||
| { | ||
| IContainer Container { get; } | ||
| Vector2 Position { get; } | ||
| Vector2 Velocity { get; } | ||
| void StartEngine(); | ||
| void AddContainer(IContainer container); | ||
| } | ||
| } |
| @@ -0,0 +1,22 @@ | ||
| using System; | ||
|
|
||
| namespace AssignmentComplete | ||
| { | ||
| #if WINDOWS || LINUX | ||
| /// <summary> | ||
| /// The main class. | ||
| /// </summary> | ||
| public static class Program | ||
| { | ||
| /// <summary> | ||
| /// The main entry point for the application. | ||
| /// </summary> | ||
| [STAThread] | ||
| static void Main() | ||
| { | ||
| using (var game = new Game1()) | ||
| game.Run(); | ||
| } | ||
| } | ||
| #endif | ||
| } |
| @@ -0,0 +1,253 @@ | ||
| using System; | ||
| using System.Collections.Generic; | ||
| using System.Linq; | ||
| using System.Text; | ||
|
|
||
| namespace AssignmentComplete | ||
| { | ||
| public class Done : IStateMachine | ||
| { | ||
| public Done(string message) | ||
| { | ||
| this.message = message; | ||
| } | ||
| string message; | ||
| bool busy = true; | ||
| public bool Busy | ||
| { | ||
| get | ||
| { | ||
| return busy; | ||
| } | ||
|
|
||
| set | ||
| { | ||
| busy = value; | ||
| } | ||
| } | ||
|
|
||
| public void Update(float dt) | ||
| { | ||
| Busy = false; | ||
| } | ||
|
|
||
| public void Reset() | ||
| { | ||
| Busy = true; | ||
| } | ||
| } | ||
| public class Print : IStateMachine | ||
| { | ||
| public Print(string message) | ||
| { | ||
| this.message = message; | ||
| } | ||
| string message; | ||
| bool busy = true; | ||
| public bool Busy | ||
| { | ||
| get | ||
| { | ||
| return busy; | ||
| } | ||
|
|
||
| set | ||
| { | ||
| busy = value; | ||
| } | ||
| } | ||
|
|
||
| public void Update(float dt) | ||
| { | ||
| Console.WriteLine(message); | ||
| Busy = false; | ||
| } | ||
|
|
||
| public void Reset() | ||
| { | ||
| Busy = true; | ||
| } | ||
| } | ||
| public class Timer : IStateMachine | ||
| { | ||
| float initial_time; | ||
| public Timer(float time) | ||
| { | ||
| this.time = time; | ||
| initial_time = time; | ||
| } | ||
| float time; | ||
| bool busy = true; | ||
| public bool Busy | ||
| { | ||
| get | ||
| { | ||
| return busy; | ||
| } | ||
|
|
||
| set | ||
| { | ||
| busy = value; | ||
| } | ||
| } | ||
|
|
||
| public void Update(float dt) | ||
| { | ||
| time -= dt; | ||
| if (time <= 0) | ||
| Busy = false; | ||
| } | ||
|
|
||
| public void Reset() | ||
| { | ||
| time = initial_time; | ||
| Busy = true; | ||
| } | ||
| } | ||
|
|
||
| public class Wait : IStateMachine | ||
| { | ||
| public Wait(Func<bool> condition) | ||
| { | ||
| this.condition = condition; | ||
| } | ||
| Func<bool> condition; | ||
| bool busy = true; | ||
| public bool Busy | ||
| { | ||
| get | ||
| { | ||
| return busy; | ||
| } | ||
|
|
||
| set | ||
| { | ||
| busy = value; | ||
| } | ||
| } | ||
|
|
||
| public void Update(float dt) | ||
| { | ||
| if (condition.Invoke()) | ||
| Busy = false; | ||
| } | ||
|
|
||
| public void Reset() | ||
| { | ||
| Busy = true; | ||
| } | ||
| } | ||
|
|
||
| public class Seq : IStateMachine | ||
| { | ||
| IStateMachine current, next; | ||
| IStateMachine s1, s2; | ||
|
|
||
| public Seq(IStateMachine s1, IStateMachine s2) | ||
| { | ||
| current = s1; | ||
| next = s2; | ||
| this.s1 = s1; | ||
| this.s2 = s2; | ||
| } | ||
| bool busy = true; | ||
| public bool Busy | ||
| { | ||
| get | ||
| { | ||
| return busy; | ||
| } | ||
|
|
||
| set | ||
| { | ||
| busy = value; | ||
| } | ||
| } | ||
|
|
||
| public void Update(float dt) | ||
| { | ||
| if (Busy == true) | ||
| { | ||
| current.Update(dt); | ||
| if (current.Busy == false) | ||
| current = next; | ||
| if (next.Busy == false) | ||
| Busy = false; | ||
| } | ||
| } | ||
|
|
||
| public void Reset() | ||
| { | ||
| s1.Reset(); | ||
| s2.Reset(); | ||
| current = s1; | ||
| Busy = true; | ||
| } | ||
| } | ||
| public class Repeat : IStateMachine | ||
| { | ||
| IStateMachine action; | ||
| public Repeat(IStateMachine action) | ||
| { | ||
| this.action = action; | ||
| } | ||
| public bool Busy | ||
| { | ||
| get | ||
| { | ||
| return true; | ||
| } | ||
|
|
||
| } | ||
|
|
||
| public void Reset() | ||
| { | ||
| action.Reset(); | ||
| } | ||
|
|
||
| public void Update(float dt) | ||
| { | ||
| if (action.Busy == false) | ||
| { | ||
| Reset(); | ||
| } | ||
| action.Update(dt); | ||
| } | ||
| } | ||
|
|
||
|
|
||
|
|
||
| public class Call : IStateMachine | ||
| { | ||
| public Call(IAction action) | ||
| { | ||
| this.action = action; | ||
| } | ||
| IAction action; | ||
| bool busy = true; | ||
| public bool Busy | ||
| { | ||
| get | ||
| { | ||
| return busy; | ||
| } | ||
|
|
||
| set | ||
| { | ||
| busy = value; | ||
| } | ||
| } | ||
|
|
||
| public void Update(float dt) | ||
| { | ||
| action.Run(); | ||
| Busy = false; | ||
| } | ||
|
|
||
| public void Reset() | ||
| { | ||
| Busy = true; | ||
| } | ||
| } | ||
|
|
||
| } |
| @@ -0,0 +1,11 @@ | ||
| using System; | ||
| using System.Collections.Generic; | ||
| using System.Linq; | ||
| using System.Text; | ||
| using Microsoft.Xna.Framework; | ||
| using Microsoft.Xna.Framework.Graphics; | ||
|
|
||
| namespace AssignmentComplete | ||
| { | ||
|
|
||
| } |
| @@ -0,0 +1,10 @@ | ||
|
|
||
| Microsoft Visual Studio Solution File, Format Version 12.00 | ||
| # Visual Studio 14 | ||
| VisualStudioVersion = 14.0.23107.0 | ||
| MinimumVisualStudioVersion = 10.0.40219.1 | ||
| Global | ||
| GlobalSection(SolutionProperties) = preSolution | ||
| HideSolutionNode = FALSE | ||
| EndGlobalSection | ||
| EndGlobal |