Created
January 26, 2021 15:54
-
-
Save t-tutiya/7aee66f1d3e63f5a553f363399ba16c9 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// zlib/libpng License | |
// | |
// Copyright (c) 2021 TSUCHIYA Tsukasa | |
// | |
// This software is provided 'as-is', without any express or implied warranty. | |
// In no event will the authors be held liable for any damages arising from the use of this software. | |
// Permission is granted to anyone to use this software for any purpose, | |
// including commercial applications, and to alter it and redistribute it freely, | |
// subject to the following restrictions: | |
// | |
// 1. The origin of this software must not be misrepresented; you must not claim that you wrote the original software. | |
// If you use this software in a product, an acknowledgment in the product documentation would be appreciated but is not required. | |
// 2. Altered source versions must be plainly marked as such, and must not be misrepresented as being the original software. | |
// 3. This notice may not be removed or altered from any source distribution. | |
using System; | |
using Tsukasa.Core; | |
namespace Sample | |
{ | |
class Knight //: MonoBehaviour | |
{ | |
public StateMachine<Knight> StateMachine; | |
private string EquipWepon = "Hnad"; | |
public Knight() | |
{ | |
StateMachine = new StateMachine<Knight>(this); | |
} | |
public class Attack : StateMachine<Knight>.State | |
{ | |
protected internal override void Update() | |
{ | |
Console.WriteLine($"Attack-[{Context.EquipWepon}]!"); | |
} | |
} | |
public class SetWepon : StateMachine<Knight>.State | |
{ | |
public string WeponName; | |
protected internal override void Update() | |
{ | |
Context.EquipWepon = WeponName; | |
} | |
} | |
public class Guard : StateMachine<Knight>.State | |
{ | |
protected internal override void Update() | |
{ | |
Console.WriteLine("Guard!"); | |
} | |
} | |
public class DubleAttackAndGurad : StateMachine<Knight>.State | |
{ | |
protected internal override void Update() | |
{ | |
StateMachine.PushStateList( | |
new StateMachine<Knight>.State[] { | |
new Attack { }, | |
new Attack { }, | |
new Guard { }, | |
new Wait { } | |
}); | |
} | |
} | |
public class MultiAttack : StateMachine<Knight>.State | |
{ | |
private int count; | |
public MultiAttack(int count) | |
{ | |
//Console.WriteLine($"{StateMachine.Context.EquipWepon}"); | |
//Console.WriteLine($"{Context.EquipWepon}"); | |
this.count = count; | |
} | |
protected internal override void Update() | |
{ | |
if (count == 0) return; | |
Console.WriteLine($"MultiAttack-{count}!"); | |
count--; | |
StateMachine.PushState(this); | |
StateMachine.PushState(new Wait { }); | |
} | |
} | |
public class Wait : StateMachine<Knight>.State | |
{ | |
protected internal override void Update() | |
{ | |
Console.WriteLine("Wait"); | |
StateMachine.PushState(new StateMachine<Knight>.Suspend { }); | |
} | |
} | |
} | |
class Program | |
{ | |
static void Main() | |
{ | |
var knight = new Knight(); | |
knight.StateMachine.PushStateList( | |
new StateMachine<Knight>.State[] { | |
new Knight.Attack { }, | |
new Knight.SetWepon{WeponName = "Sword"}, | |
new Knight.Attack { }, | |
new Knight.Guard { }, | |
new Knight.Wait { }, | |
new Knight.DubleAttackAndGurad { }, | |
new Knight.MultiAttack(3) { }, | |
} | |
); | |
knight.StateMachine.Update(); | |
Console.WriteLine("===="); | |
knight.StateMachine.Update(); | |
Console.WriteLine("===="); | |
knight.StateMachine.Update(); | |
Console.WriteLine("===="); | |
knight.StateMachine.Update(); | |
Console.WriteLine("===="); | |
knight.StateMachine.Update(); | |
Console.WriteLine("end"); | |
} | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment