Skip to content

Commit

Permalink
[wip] some little changes
Browse files Browse the repository at this point in the history
  • Loading branch information
YogurtTheHorse committed Feb 1, 2020
1 parent 1642463 commit f54d118
Show file tree
Hide file tree
Showing 9 changed files with 61 additions and 17 deletions.
2 changes: 2 additions & 0 deletions StrategyBot.Game.Data/GameAnswer.cs
Expand Up @@ -7,5 +7,7 @@ public class GameAnswer
public ObjectId PlayerId { get; set; }

public string Text { get; set; }

public string[] Suggestions { get; set; }
}
}
4 changes: 4 additions & 0 deletions StrategyBot.Game.Interface/PlayerData.cs
Expand Up @@ -6,5 +6,9 @@ namespace StrategyBot.Game.Interface.Models
public class PlayerData : MongoModel
{
public Dictionary<string, object> TemporaryVariables { get; set; } = new Dictionary<string, object>();

public int AttackShips { get; set; } = 0;

public int DefenceShips { get; set; } = 0;
}
}
2 changes: 2 additions & 0 deletions StrategyBot.Game.Interface/PlayerState.cs
Expand Up @@ -8,6 +8,8 @@ public class PlayerState : MongoModel
public string ReplyQueueName { get; set; }

public string SocialId { get; set; }

public string Locale { get; set; }

public Stack<string> ScreensStack { get; set; } = new Stack<string>();
}
Expand Down
12 changes: 12 additions & 0 deletions StrategyBot.Game.Logic/Entities/Lobby.cs
@@ -0,0 +1,12 @@
using MongoDB.Bson;
using StrategyBot.Game.Data.Mongo;

namespace StrategyBot.Game.Entities
{
public class Lobby : MongoModel
{
public int Level { get; set; }

public ObjectId[] PlayersIds { get; set; }
}
}
29 changes: 23 additions & 6 deletions StrategyBot.Game.Logic/Screens/MainMenuScreen.cs
@@ -1,4 +1,6 @@
using System.Threading.Tasks;
using StrategyBot.Game.Data.Abstractions;
using StrategyBot.Game.Entities;
using StrategyBot.Game.Interface;
using StrategyBot.Game.Interface.Entities;
using StrategyBot.Game.Interface.Models;
Expand All @@ -9,13 +11,15 @@ namespace StrategyBot.Game.Logic.Screens
[MainScreen]
public class MainMenuScreen : IScreen
{
private readonly IGameCommunicator _gameCommunicator;
private readonly IGamePCommunicator _gameCommunicator;
private readonly ILocalizer _localizer;

public MainMenuScreen(IGameCommunicator gameCommunicator)
public MainMenuScreen(IGameCommunicator gameCommunicator, ILocalizer localizer)
{
_gameCommunicator = gameCommunicator;
_localizer = localizer;
}

public async Task ProcessMessage(IncomingMessage message, PlayerState playerState, PlayerData playerData)
{
await _gameCommunicator.Answer(new GameAnswer
Expand All @@ -27,10 +31,23 @@ public async Task ProcessMessage(IncomingMessage message, PlayerState playerStat
await Task.CompletedTask;
}

public Task OnOpen(PlayerState playerState, PlayerData playerData)
public async Task OnOpen(PlayerState playerState, PlayerData playerData)
{
//string.Format()
return Task.CompletedTask;
await _gameCommunicator.Answer(new GameAnswer
{
Text = _localizer.GetString(
"screens.main_menu.open_phrase",
playerState.Locale,
playerData.AttackShips,
playerData.DefenceShips
),
PlayerId = playerData.Key,
Suggestions = new[]
{
_localizer.GetString("screens.main_menu.attack", playerState.Locale),
_localizer.GetString("screens.main_menu.select_skills", playerState.Locale),
}
});
}
}
}
4 changes: 0 additions & 4 deletions StrategyBot.Game.Logic/StrategyBot.Game.Logic.csproj
Expand Up @@ -10,8 +10,4 @@
<ProjectReference Include="..\StrategyBot.Game.Interface\StrategyBot.Game.Interface.csproj" />
</ItemGroup>

<ItemGroup>
<Folder Include="Entities" />
</ItemGroup>

</Project>
14 changes: 10 additions & 4 deletions StrategyBot.Game.Server/Program.cs
Expand Up @@ -26,9 +26,11 @@ public static void Main(string[] args)
var rabbitMqSettings = configuration
.GetSection(nameof(RabbitMqSettings))
.Get<RabbitMqSettings>();

var mongoSettings = configuration
.GetSection(nameof(MongoSettings))
.Get<MongoSettings>();

var localizationOptions = configuration
.GetSection(nameof(LocalizationOptions))
.Get<LocalizationOptions>();
Expand Down Expand Up @@ -57,22 +59,25 @@ public static void Main(string[] args)
.RegisterType<MongoUnitOfWork>()
.As<IMongoUnitOfWork>()
.SingleInstance();

iocContainerBuilder
.RegisterType<GameContext>()
.SingleInstance();

iocContainerBuilder
.RegisterType<RabbitMqCommunicator>()
.As<IGameCommunicator>()
.SingleInstance();

iocContainerBuilder
.RegisterType<YamlLocalizer>()
.As<ILocalizer>();
.As<ILocalizer>()
.SingleInstance();

iocContainerBuilder
.RegisterGeneric(typeof(MongoRepository<>))
.As(typeof(IMongoRepository<>));

.As(typeof(IMongoRepository<>))
.SingleInstance();

iocContainerBuilder
.RegisterInstance(channel)
Expand All @@ -87,7 +92,8 @@ public static void Main(string[] args)

iocContainerBuilder
.RegisterType<StackScreenController>()
.As<IScreenController>();
.As<IScreenController>()
.SingleInstance();

IContainer container = iocContainerBuilder.Build();
var localizer = container.Resolve<ILocalizer>();
Expand Down
7 changes: 6 additions & 1 deletion StrategyBot.Game.Server/Text/screens/main_menu.yml
@@ -1 +1,6 @@
test: Test
open_phrase: Welcome to StrBot. It is a simple strategy where you have to control space colony. Build spaceships and
conquer neighbours to became larger. Currently you have {0} attack ships and {1} defence. You can attack or upgrade
your skills currently.

attack: Attack
select_skills: Choose skills
4 changes: 2 additions & 2 deletions StrategyBot.Game.Server/YamlLocalization/YamlLocalizer.cs
Expand Up @@ -35,8 +35,8 @@ private string GetFormat(string key, string locale)
Path.DirectorySeparatorChar,
keys.Take(keys.Length - 1)
);
string[] pathToLookUp = new[]
{

string[] pathToLookUp = {
prePath + $".{locale}.yml",
prePath + $".{_defaultLanguage}.yml",
prePath + ".yml"
Expand Down

0 comments on commit f54d118

Please sign in to comment.