-
Notifications
You must be signed in to change notification settings - Fork 28
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
"Deal or No Deal" Game #203
base: master
Are you sure you want to change the base?
Changes from all commits
8bf88ce
597a149
930af06
8dc398d
3aacc74
c54d81b
3ce9409
84f83b8
309b3ea
01a69d1
4c53053
c44cc2d
8956b9f
aeab4d3
0b769fa
42ea13a
bca22a4
70e0a15
af8dfbb
7e7bfa1
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,44 @@ | ||
using System; | ||
using System.Collections.Generic; | ||
using System.Text; | ||
using DevChatter.Bot.Core.Games.DealNoDeal; | ||
using DevChatter.Bot.Core.Systems.Chat; | ||
using DevChatter.Bot.Core.Util; | ||
|
||
namespace DevChatter.Bot.Core.Automation | ||
{ | ||
public class AutomatedActionFactory : IAutomatedActionFactory | ||
{ | ||
private readonly DealNoDealGame _dealNoDealGame; | ||
private readonly IChatClient _chatClient; | ||
|
||
public AutomatedActionFactory(DealNoDealGame dealNoDealGame, IChatClient chatClient) | ||
{ | ||
_dealNoDealGame = dealNoDealGame; | ||
_chatClient = chatClient; | ||
} | ||
|
||
public IIntervalAction GetIntervalAction(DealNoDealGameState gameState) | ||
{ | ||
switch (gameState) | ||
{ | ||
case DealNoDealGameState.ChosingStartingBoxes: | ||
{ | ||
return new ChoseStartingBoxesAction(_dealNoDealGame, _chatClient); | ||
} | ||
case DealNoDealGameState.PickingBoxes: | ||
{ | ||
return new PickBoxesAction(_dealNoDealGame, _chatClient); | ||
} | ||
case DealNoDealGameState.MakingADeal: | ||
{ | ||
return new OfferDealAction(_dealNoDealGame, _chatClient); | ||
} | ||
default: | ||
{ | ||
return null; | ||
} | ||
} | ||
} | ||
} | ||
} |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,49 @@ | ||
using System; | ||
using System.Collections.Generic; | ||
using System.Text; | ||
using DevChatter.Bot.Core.Data.Model; | ||
using DevChatter.Bot.Core.Games.DealNoDeal; | ||
using DevChatter.Bot.Core.Systems.Chat; | ||
using DevChatter.Bot.Core.Util; | ||
|
||
|
||
namespace DevChatter.Bot.Core.Automation | ||
{ | ||
public class ChoseStartingBoxesAction : IIntervalAction | ||
{ | ||
private readonly IClock _clock; | ||
private DateTime _nextRunTime; | ||
private IChatClient _chatClient; | ||
private DealNoDealGame _dealNoDealGame; | ||
|
||
|
||
public ChoseStartingBoxesAction(DealNoDealGame dealNoDealGame, IChatClient chatClient) | ||
{ | ||
_dealNoDealGame = dealNoDealGame; | ||
_chatClient = chatClient; | ||
_clock = new SystemClock(); | ||
_chatClient.SendMessage($"everyone has {DealNoDealGame.SECONDS_TO_CHOOSE_BOXES} seconds to choose a box!"); | ||
SetNextRunTime(); | ||
} | ||
|
||
public string Name { get; } = nameof(ChoseStartingBoxesAction); | ||
public bool IsTimeToRun() => _clock.Now >= _nextRunTime; | ||
|
||
public void Invoke() | ||
{ | ||
_nextRunTime = _clock.Now.AddYears(1); | ||
_chatClient.SendMessage("Finished picking starting boxes"); | ||
|
||
|
||
_dealNoDealGame.EnsureMinPlayableBoxes(); | ||
_chatClient.SendMessage("Game Started!"); | ||
_dealNoDealGame.GameState = DealNoDealGameState.PickingBoxes; | ||
_dealNoDealGame.SetActionForGameState(DealNoDealGameState.PickingBoxes); | ||
} | ||
|
||
private void SetNextRunTime() | ||
{ | ||
_nextRunTime = _clock.Now.AddSeconds(DealNoDealGame.SECONDS_TO_CHOOSE_BOXES); | ||
} | ||
} | ||
} |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,13 @@ | ||
using System; | ||
using System.Collections.Generic; | ||
using System.Text; | ||
using DevChatter.Bot.Core.Games.DealNoDeal; | ||
using DevChatter.Bot.Core.Systems.Chat; | ||
|
||
namespace DevChatter.Bot.Core.Automation | ||
{ | ||
public interface IAutomatedActionFactory | ||
{ | ||
IIntervalAction GetIntervalAction(DealNoDealGameState gameState); | ||
} | ||
} |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,45 @@ | ||
using System; | ||
using System.Collections.Generic; | ||
using System.Text; | ||
using DevChatter.Bot.Core.Games.DealNoDeal; | ||
using DevChatter.Bot.Core.Systems.Chat; | ||
using DevChatter.Bot.Core.Util; | ||
|
||
namespace DevChatter.Bot.Core.Automation | ||
{ | ||
public class OfferDealAction : IIntervalAction | ||
{ | ||
private readonly IClock _clock; | ||
private DateTime _nextRunTime; | ||
private IChatClient _chatClient; | ||
private DealNoDealGame _dealNoDealGame; | ||
|
||
|
||
public OfferDealAction(DealNoDealGame dealNoDealGame, IChatClient chatClient) | ||
{ | ||
_dealNoDealGame = dealNoDealGame; | ||
_chatClient = chatClient; | ||
_clock = new SystemClock(); | ||
_dealNoDealGame.PrintBoxesRemaining(); | ||
_chatClient.SendMessage($"***DEAL OFFER: {dealNoDealGame.DealOffer} TOKENS!"); | ||
_chatClient.SendMessage(" type \"!dnd accept\" or \"!dnd decline\" to accept or decline offer "); | ||
_chatClient.SendMessage($"You have {DealNoDealGame.SECONDS_TO_CHOOSE_BOXES} seconds or the deal will be automatically accepted"); | ||
SetNextRunTime(); | ||
} | ||
|
||
public string Name { get; } = nameof(OfferDealAction); | ||
public bool IsTimeToRun() => _clock.Now >= _nextRunTime; | ||
|
||
|
||
public void Invoke() | ||
{ | ||
_chatClient.SendMessage($"Automatically accepting deal! {DealNoDealGame.SECONDS_TO_CHOOSE_BOXES} seconds passed"); | ||
_dealNoDealGame.AcceptDeal(_chatClient); | ||
} | ||
|
||
private void SetNextRunTime() | ||
{ | ||
_nextRunTime = _clock.Now.AddSeconds(DealNoDealGame.SECONDS_TO_CHOOSE_BOXES); | ||
} | ||
} | ||
} |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,41 @@ | ||
using System; | ||
using System.Collections.Generic; | ||
using System.Text; | ||
using DevChatter.Bot.Core.Games.DealNoDeal; | ||
using DevChatter.Bot.Core.Systems.Chat; | ||
using DevChatter.Bot.Core.Util; | ||
|
||
namespace DevChatter.Bot.Core.Automation | ||
{ | ||
public class PickBoxesAction : IIntervalAction | ||
{ | ||
private readonly IClock _clock; | ||
private DateTime _nextRunTime; | ||
private IChatClient _chatClient; | ||
private DealNoDealGame _dealNoDealGame; | ||
|
||
|
||
public PickBoxesAction(DealNoDealGame dealNoDealGame, IChatClient chatClient) | ||
{ | ||
_dealNoDealGame = dealNoDealGame; | ||
_chatClient = chatClient; | ||
_clock = new SystemClock(); | ||
_dealNoDealGame.PrintBoxesRemaining(); | ||
SetNextRunTime(); | ||
} | ||
|
||
public string Name { get; } = nameof(PickBoxesAction); | ||
public bool IsTimeToRun() => _clock.Now >= _nextRunTime; | ||
|
||
public void Invoke() | ||
{ | ||
_chatClient.SendMessage("Picking a random Box. User did not respond"); | ||
_dealNoDealGame.PickRandomBox(_dealNoDealGame.MainPlayer.DisplayName); | ||
} | ||
|
||
private void SetNextRunTime() | ||
{ | ||
_nextRunTime = _clock.Now.AddSeconds(DealNoDealGame.SECONDS_TO_CHOOSE_BOXES); | ||
} | ||
} | ||
} |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,33 @@ | ||
namespace DevChatter.Bot.Core.Games.DealNoDeal | ||
{ | ||
public class Box | ||
{ | ||
public Box(int id, int value, string owner) | ||
{ | ||
Id = id; | ||
TokenValue = value; | ||
Owner = owner; | ||
} | ||
|
||
public Box(int id, int value) | ||
{ | ||
Id = id; | ||
TokenValue = value; | ||
} | ||
|
||
public int Id { get; set; } | ||
public int TokenValue { get; set; } | ||
public string Owner { get; set; } | ||
|
||
public bool SetOwner(string ownerName) | ||
{ | ||
if (Owner != null) | ||
{ | ||
return false; | ||
} | ||
|
||
Owner = ownerName; | ||
return true; | ||
} | ||
} | ||
} |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,54 @@ | ||
using DevChatter.Bot.Core.Commands; | ||
using DevChatter.Bot.Core.Commands.Operations; | ||
using DevChatter.Bot.Core.Data; | ||
using DevChatter.Bot.Core.Data.Model; | ||
using DevChatter.Bot.Core.Events.Args; | ||
using DevChatter.Bot.Core.Systems.Chat; | ||
using System.Collections.Generic; | ||
using System.Linq; | ||
|
||
namespace DevChatter.Bot.Core.Games.DealNoDeal | ||
{ | ||
public class DNDCommand : BaseCommand, IGameCommand | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. This breaks the C# convention for capitalization, see https://docs.microsoft.com/en-us/dotnet/standard/design-guidelines/capitalization-conventions#capitalization-rules-for-identifiers Maybe even call it |
||
{ | ||
private readonly DealNoDealGame _dealNoDealGame; | ||
public IGame Game => _dealNoDealGame; | ||
|
||
public DNDCommand(IRepository repository, DealNoDealGame dealNoDealGame, IChatClient chatClient) : base(repository, UserRole.Everyone) | ||
{ | ||
_dealNoDealGame = dealNoDealGame; | ||
_chatClient = chatClient; | ||
HelpText = | ||
"Use \"!dnd\" to start a game. Use \"!dnd pick x\" to pick/guess a box. Use \"!dnd accept\" or \"!dnd decline\" to accept or decline offers ."; | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. This line is quite long, split up into two lines? |
||
} | ||
private List<ICommandOperation> _operations; | ||
private readonly IChatClient _chatClient; | ||
|
||
public List<ICommandOperation> Operations => _operations ?? (_operations = new List<ICommandOperation> | ||
{ | ||
new PickABoxOperation(_dealNoDealGame,_chatClient), | ||
new MakeADealOperation(_dealNoDealGame,_chatClient) | ||
}); | ||
|
||
protected override void HandleCommand(IChatClient chatClient, CommandReceivedEventArgs eventArgs) | ||
{ | ||
string argumentOne = eventArgs?.Arguments?.FirstOrDefault(); | ||
ChatUser chatUser = eventArgs?.ChatUser; | ||
//dnd start dnd pick | ||
var operationToUse = Operations.SingleOrDefault(x => x.ShouldExecute(argumentOne)); | ||
if (operationToUse != null) | ||
{ | ||
string resultMessage = operationToUse.TryToExecute(eventArgs); | ||
} | ||
else | ||
{ | ||
if (string.IsNullOrWhiteSpace(argumentOne)) | ||
{ | ||
// attempting to start a game | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Would we lose anything by removing this comment? |
||
_dealNoDealGame.AttemptToStartGame(chatUser); | ||
} | ||
} | ||
} | ||
|
||
} | ||
} |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
The indenting seems to be off here