Skip to content

Commit e05d02f

Browse files
committed
Add levels
1 parent c291c23 commit e05d02f

19 files changed

Lines changed: 375 additions & 41 deletions

File tree

TurnBase.KaNoBu.Console/Program.cs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,7 @@ public class Program
66
{
77
public static async Task Main(string[] args)
88
{
9-
var rules = new KaNoBuRules(8, true);
9+
var rules = new KaNoBuRules(8);
1010
var game = new Game<KaNoBuInitModel, KaNoBuInitResponseModel, KaNoBuMoveModel, KaNoBuMoveResponseModel, KaNoBuMoveNotificationModel>(rules, "test");
1111
game.AddPlayer(new DelayedPlayer<KaNoBuInitModel, KaNoBuInitResponseModel, KaNoBuMoveModel, KaNoBuMoveResponseModel, KaNoBuMoveNotificationModel>(new KaNoBuPlayerEasy(), async (delay) => await Task.Delay(delay), 1, 500));
1212
game.AddPlayer(new DelayedPlayer<KaNoBuInitModel, KaNoBuInitResponseModel, KaNoBuMoveModel, KaNoBuMoveResponseModel, KaNoBuMoveNotificationModel>(new KaNoBuPlayerEasy(), async (delay) => await Task.Delay(delay), 1, 500));

TurnBase.KaNoBu.Godot/Presentation/GameField.cs

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -269,6 +269,13 @@ private void OnUnitClicked(Unit unit)
269269

270270
public override void _Ready()
271271
{
272+
base._Ready();
272273
this.FillMembers();
274+
this.AddToGroup(Groups.Field);
275+
}
276+
277+
public Vector2 WorldToMap(Vector2 position)
278+
{
279+
return this.water.WorldToMap(position);
273280
}
274281
}
Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,11 @@
1+
using Godot;
2+
3+
[SceneReference("Level1.tscn")]
4+
public partial class Level1
5+
{
6+
public override void _Ready()
7+
{
8+
base._Ready();
9+
this.FillMembers();
10+
}
11+
}
Lines changed: 27 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,27 @@
1+
[gd_scene load_steps=4 format=2]
2+
3+
[ext_resource path="res://Presentation/Levels/LevelBase.tscn" type="PackedScene" id=1]
4+
[ext_resource path="res://Presentation/Levels/Level1.cs" type="Script" id=2]
5+
[ext_resource path="res://Presentation/Unit.tscn" type="PackedScene" id=3]
6+
7+
[node name="Level1" instance=ExtResource( 1 )]
8+
script = ExtResource( 2 )
9+
10+
[node name="Beach" parent="." index="2"]
11+
tile_data = PoolIntArray( 65533, 2, 0, 65534, 2, 1, 65535, 2, 1, 0, 2, 1, 1, 2, 1, 2, 2, 1, 3, 2, 1, 4, 2, 1, 5, 2, 1, 6, 2, 1, 7, 2, 1, 8, 2, 1, 9, 2, 1, 10, 2, 2, 131069, 2, 65536, 131070, 2, 262147, 131071, 2, 3, 65536, 2, 131073, 65537, 2, 131073, 65538, 2, 131073, 65539, 2, 131073, 65540, 2, 131073, 65541, 2, 131073, 65542, 2, 131073, 65543, 2, 131073, 65544, 2, 4, 65545, 2, 262147, 65546, 2, 65538, 196605, 2, 65536, 196606, 2, 262147, 196607, 2, 65538, 131080, 2, 65536, 131081, 2, 262147, 131082, 2, 65538, 262141, 2, 65536, 262142, 2, 262147, 262143, 2, 65538, 196616, 2, 65536, 196617, 2, 262147, 196618, 2, 65538, 327677, 2, 65536, 327678, 2, 262147, 327679, 2, 65539, 262144, 2, 1, 262145, 2, 1, 262146, 2, 1, 262147, 2, 1, 262148, 2, 1, 262149, 2, 1, 262150, 2, 1, 262151, 2, 1, 262152, 2, 65540, 262153, 2, 262147, 262154, 2, 65538, 393213, 2, 65536, 393214, 2, 262147, 393215, 2, 3, 327680, 2, 131073, 327681, 2, 131073, 327682, 2, 131073, 327683, 2, 131073, 327684, 2, 131073, 327685, 2, 131073, 327686, 2, 131073, 327687, 2, 131073, 327688, 2, 4, 327689, 2, 262147, 327690, 2, 65538, 458749, 2, 65536, 458750, 2, 262147, 458751, 2, 65538, 393224, 2, 65536, 393225, 2, 262147, 393226, 2, 65538, 524285, 2, 65536, 524286, 2, 262147, 524287, 2, 65538, 458760, 2, 65536, 458761, 2, 262147, 458762, 2, 65538, 589821, 2, 65536, 589822, 2, 262147, 589823, 2, 65538, 524296, 2, 65536, 524297, 2, 262147, 524298, 2, 65538, 655357, 2, 65536, 655358, 2, 262147, 655359, 2, 65539, 589824, 2, 1, 589825, 2, 1, 589826, 2, 1, 589827, 2, 1, 589828, 2, 1, 589829, 2, 1, 589830, 2, 1, 589831, 2, 1, 589832, 2, 65540, 589833, 2, 262147, 589834, 2, 65538, 720893, 2, 65536, 720894, 2, 262147, 720895, 2, 262147, 655360, 2, 262147, 655361, 2, 262147, 655362, 2, 262147, 655363, 2, 262147, 655364, 2, 262147, 655365, 2, 262147, 655366, 2, 262147, 655367, 2, 262147, 655368, 2, 262147, 655369, 2, 262147, 655370, 2, 65538, 786429, 2, 65536, 786430, 2, 262147, 786431, 2, 262147, 720896, 2, 262147, 720897, 2, 262147, 720898, 2, 262147, 720899, 2, 262147, 720900, 2, 262147, 720901, 2, 262147, 720902, 2, 262147, 720903, 2, 262147, 720904, 2, 262147, 720905, 2, 262147, 720906, 2, 65538, 851965, 2, 65536, 851966, 2, 262147, 851967, 2, 262147, 786432, 2, 262147, 786433, 2, 262147, 786434, 2, 262147, 786435, 2, 262147, 786436, 2, 262147, 786437, 2, 262147, 786438, 2, 262147, 786439, 2, 262147, 786440, 2, 262147, 786441, 2, 262147, 786442, 2, 65538, 917501, 2, 131072, 917502, 2, 131073, 917503, 2, 131073, 851968, 2, 131073, 851969, 2, 131073, 851970, 2, 131073, 851971, 2, 131073, 851972, 2, 131073, 851973, 2, 131073, 851974, 2, 131073, 851975, 2, 131073, 851976, 2, 131073, 851977, 2, 131073, 851978, 2, 131074 )
12+
13+
[node name="Unit1" parent="Field" index="0" instance=ExtResource( 3 )]
14+
position = Vector2( 159, 185 )
15+
UnitType = 2
16+
17+
[node name="Unit2" parent="Field" index="1" instance=ExtResource( 3 )]
18+
position = Vector2( 325, 185 )
19+
UnitType = 4
20+
PlayerNumber = 1
21+
22+
[node name="Unit3" parent="Field" index="2" instance=ExtResource( 3 )]
23+
position = Vector2( 289, 474 )
24+
PlayerNumber = 1
25+
26+
[node name="Unit4" parent="Field" index="3" instance=ExtResource( 3 )]
27+
position = Vector2( 159, 466 )
Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,11 @@
1+
using Godot;
2+
3+
[SceneReference("Level2.tscn")]
4+
public partial class Level2
5+
{
6+
public override void _Ready()
7+
{
8+
base._Ready();
9+
this.FillMembers();
10+
}
11+
}
Lines changed: 30 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,30 @@
1+
[gd_scene load_steps=4 format=2]
2+
3+
[ext_resource path="res://Presentation/Levels/LevelBase.tscn" type="PackedScene" id=1]
4+
[ext_resource path="res://Presentation/Levels/Level2.cs" type="Script" id=2]
5+
[ext_resource path="res://Presentation/Unit.tscn" type="PackedScene" id=3]
6+
7+
[node name="Level2" instance=ExtResource( 1 )]
8+
script = ExtResource( 2 )
9+
10+
[node name="Unit" parent="Field" index="0" instance=ExtResource( 3 )]
11+
position = Vector2( 87.9999, 367 )
12+
13+
[node name="Unit2" parent="Field" index="1" instance=ExtResource( 3 )]
14+
position = Vector2( 88, 195 )
15+
16+
[node name="Unit1" parent="Field" index="2" instance=ExtResource( 3 )]
17+
position = Vector2( 89, 278 )
18+
UnitType = 2
19+
20+
[node name="Unit3" parent="Field" index="3" instance=ExtResource( 3 )]
21+
position = Vector2( 232, 184 )
22+
UnitType = 4
23+
PlayerNumber = 1
24+
25+
[node name="Unit4" parent="Field" index="4" instance=ExtResource( 3 )]
26+
position = Vector2( 227, 278 )
27+
PlayerNumber = 1
28+
29+
[node name="Unit5" parent="Field" index="5" instance=ExtResource( 3 )]
30+
position = Vector2( 234, 369 )
Lines changed: 38 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,38 @@
1+
using Godot;
2+
using TurnBase;
3+
using TurnBase.KaNoBu;
4+
5+
[SceneReference("LevelBase.tscn")]
6+
public partial class LevelBase
7+
{
8+
public override void _Ready()
9+
{
10+
base._Ready();
11+
this.FillMembers();
12+
this.AddToGroup(Groups.Level);
13+
}
14+
15+
public virtual IGame<KaNoBuInitModel, KaNoBuInitResponseModel, KaNoBuMoveModel, KaNoBuMoveResponseModel, KaNoBuMoveNotificationModel> Start()
16+
{
17+
var rules = new KaNoBuLevelRules(8, true);
18+
rules.SetInitialField(this.generateField());
19+
var game = new Game<KaNoBuInitModel, KaNoBuInitResponseModel, KaNoBuMoveModel, KaNoBuMoveResponseModel, KaNoBuMoveNotificationModel>(rules, "level");
20+
game.AddPlayer(this);
21+
game.AddPlayer(new PlayerLoose<KaNoBuInitModel, KaNoBuInitResponseModel, KaNoBuMoveModel, KaNoBuMoveResponseModel, KaNoBuMoveNotificationModel>());
22+
return game;
23+
}
24+
25+
public Field2D generateField()
26+
{
27+
var field2D = Field2D.Create(8, 8);
28+
var allUnits = this.field.GetChildren();
29+
foreach (Unit unit in allUnits)
30+
{
31+
var fig = new KaNoBuFigure(unit.PlayerNumber, unit.UnitType, true, 0);
32+
var pos = this.WorldToMap(unit.Position);
33+
field2D.trySet(new Point((int)pos.x, (int)pos.y), fig);
34+
}
35+
36+
return field2D;
37+
}
38+
}
Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,8 @@
1+
[gd_scene load_steps=3 format=2]
2+
3+
[ext_resource path="res://Presentation/GameField.tscn" type="PackedScene" id=1]
4+
[ext_resource path="res://Presentation/Levels/LevelBase.cs" type="Script" id=2]
5+
6+
[node name="LevelBase" instance=ExtResource( 1 )]
7+
script = ExtResource( 2 )
8+
UnitScene = null
Lines changed: 31 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,6 @@
1-
using System.Threading.Tasks;
21
using Godot;
2+
using TurnBase;
3+
using TurnBase.KaNoBu;
34

45
[SceneReference("Main.tscn")]
56
public partial class Main
@@ -9,20 +10,48 @@ public override void _Ready()
910
this.FillMembers();
1011

1112
this.uI.Connect(nameof(UI.StartGameEventhandler), this, nameof(OnStartGameAsync));
13+
StartInfinityGame();
14+
}
15+
16+
private async void StartInfinityGame()
17+
{
18+
while (true)
19+
{
20+
var rules = new KaNoBuRules(8);
21+
rules.AllFiguresVisible = true;
22+
var kanobu = new Game<KaNoBuInitModel, KaNoBuInitResponseModel, KaNoBuMoveModel, KaNoBuMoveResponseModel, KaNoBuMoveNotificationModel>(rules, "test");
23+
for (var i = 0; i < 4; i++)
24+
{
25+
var playerEasy = new KaNoBuPlayerEasy();
26+
var delayedPlayer = new DelayedPlayer<KaNoBuInitModel, KaNoBuInitResponseModel, KaNoBuMoveModel, KaNoBuMoveResponseModel, KaNoBuMoveNotificationModel>(
27+
playerEasy,
28+
async (delay) => await this.ToSignal(this.GetTree().CreateTimer(delay / 1000f), "timeout"),
29+
1,
30+
300);
31+
kanobu.AddPlayer(delayedPlayer);
32+
}
33+
kanobu.AddGameLogListener(this.infinityGameField);
34+
this.infinityGameField.RemoveFromGroup(Groups.Field);
35+
await kanobu.Play();
36+
}
1237
}
1338

1439
private async void OnStartGameAsync()
1540
{
16-
var game = this.uI.BuildGame(this.gameField);
41+
var game = this.uI.BuildGame();
1742
if (game == null)
1843
{
1944
return;
2045
}
2146

2247
this.uI.Visible = false;
48+
this.infinityGameField.Visible = false;
2349

2450
await game.Play();
2551

52+
this.GetTree().CallGroup(Groups.Field, "queue_free");
53+
54+
this.infinityGameField.Visible = true;
2655
this.uI.Visible = true;
2756
}
2857
}

TurnBase.KaNoBu.Godot/Presentation/Main.tscn

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,8 @@
77
[node name="Main" type="Node"]
88
script = ExtResource( 1 )
99

10-
[node name="GameField" parent="." instance=ExtResource( 3 )]
10+
[node name="InfinityGameField" parent="." instance=ExtResource( 3 )]
1111

1212
[node name="UI" parent="." instance=ExtResource( 4 )]
13+
GameField = ExtResource( 3 )
14+
Replay = ExtResource( 3 )

0 commit comments

Comments
 (0)