Ajoutez des fichiers projet.

This commit is contained in:
taywon18
2024-12-24 07:18:26 +01:00
commit f7793993bf
57 changed files with 4706 additions and 0 deletions

View File

@@ -0,0 +1,4 @@
public class InstalledObject
{
}

View File

@@ -0,0 +1,11 @@
fileFormatVersion: 2
guid: 4bf42d98475ac304790de92020f88828
MonoImporter:
externalObjects: {}
serializedVersion: 2
defaultReferences: []
executionOrder: 0
icon: {instanceID: 0}
userData:
assetBundleName:
assetBundleVariant:

170
Assets/Model/Stage.cs Normal file
View File

@@ -0,0 +1,170 @@
using System;
using UnityEngine;
public class Stage
{
Tile[,] Tiles { get; set; }
Wall[,] HorizontalWalls { get; set; }
Wall[,] VerticalWalls { get; set; }
public int Width { get; private set; }
public int Height { get; private set; }
public Action<Tile> OnTileChanged { get; set; }
public Action<Wall> OnWallChanged { get; set; }
public Stage(int width = 20, int height = 8)
{
Resize(width, height);
Debug.Log($"Stage created with {Tiles.Length} tiles.");
}
public void Resize(int width, int heigh)
{
if (Tiles != null)
throw new NotImplementedException();
Width = width;
Height = heigh;
Tiles = new Tile[Width, Height];
for(int x = 0; x < Width; x++)
for(int y = 0; y < Height; y++)
Tiles[x, y] = new Tile(this, x, y);
HorizontalWalls = new Wall[Width, Height+1];
for (int x = 0; x < Width; x++)
for (int y = 0; y <= Height; y++)
HorizontalWalls[x, y] = new Wall(this, x, y, WallOrientation.Horizontal);
VerticalWalls = new Wall[Width + 1, Height];
for (int x = 0; x <= Width; x++)
for (int y = 0; y < Height; y++)
VerticalWalls[x, y] = new Wall(this, x, y, WallOrientation.Vertical);
}
public bool HasTile(int x, int y)
{
return !(x < 0 || y < 0 || x >= Width || y >= Height); //TODO: implement better
}
public bool HasWall(WallOrientation orientation, int x, int y)
{
if(orientation == WallOrientation.Horizontal)
return (x >= 0 && y >= 0 && x < Width && y <= Height);
if(orientation == WallOrientation.Vertical)
return (x >= 0 && y >= 0 && x <= Width && y < Height);
throw new NotImplementedException($"Unknown orientation {orientation}.");
}
public bool IsBorderWall(WallOrientation orientation, int x, int y)
{
if(!HasWall(orientation, x, y))
return false;
if (orientation == WallOrientation.Horizontal)
return (y == 0 || y == Height);
if (orientation == WallOrientation.Vertical)
return (x == 0 || x == Width);
throw new NotImplementedException($"Unknown orientation {orientation}.");
}
public Tile GetTileAt(int x, int y)
{
if (!HasTile(x, y))
throw new Exception($"Trying to get tile {x},{y} from world({Width},{Height}).");
var tile = Tiles[x, y];
return tile;
}
public Wall GetWallAt(WallOrientation orientation, int x, int y)
{
if (!HasWall(orientation, x, y))
throw new Exception($"Trying to get wall {x},{y} from world({Width},{Height}).");
if(orientation == WallOrientation.Horizontal)
return HorizontalWalls[x, y];
if (orientation == WallOrientation.Vertical)
return VerticalWalls[x, y];
throw new System.NotImplementedException();
}
/*public void SetTile(int x, int y, Tile tile)
{
if(tile == null) throw new ArgumentNullException(tile.GetType().Name);
if (!HasTile(x, y))
throw new Exception($"Trying to get tile {x},{y} from world({Width},{Height}).");
Tiles[x, y] = tile;
}*/
public Tile this[int x, int y]
{
get { return GetTileAt(x, y); }
//set { SetTile(x, y, value); }
}
public Wall this[WallOrientation orientation, int x, int y]
{
get { return GetWallAt(orientation, x, y); }
}
public void Randomize()
{
for (int x = 0; x <= Width; x++)
for (int y = 0; y <= Height; y++)
{
if(HasTile(x, y))
{
if (UnityEngine.Random.Range(0, 2) == 0)
this[x, y].Type = TileType.Floor;
else
this[x, y].Type = TileType.Empty;
}
if (HasWall(WallOrientation.Horizontal, x, y))
{
if (UnityEngine.Random.Range(0, 2) == 1)
this[WallOrientation.Horizontal, x, y].Type = WallType.Full;
else
this[WallOrientation.Horizontal, x, y].Type = WallType.Empty;
}
if (HasWall(WallOrientation.Vertical, x, y))
{
if (UnityEngine.Random.Range(0, 2) == 1)
this[WallOrientation.Vertical, x, y].Type = WallType.Full;
else
this[WallOrientation.Vertical, x, y].Type = WallType.Empty;
}
}
Debug.Log($"Randomizing a stage...");
}
public void Populate()
{
for (int x = 0; x < Width; x++)
for (int y = 0; y < Height; y++)
this[x, y].Type = TileType.Floor;
for (int x = 0; x <= Width; x++)
for (int y = 0; y <= Height; y++)
{
if(IsBorderWall(WallOrientation.Horizontal, x, y))
this[WallOrientation.Horizontal, x, y].Type = WallType.Full;
if (IsBorderWall(WallOrientation.Vertical, x, y))
this[WallOrientation.Vertical, x, y].Type = WallType.Full;
}
}
}

View File

@@ -0,0 +1,11 @@
fileFormatVersion: 2
guid: e032b1bb54c1269498e6063f38857908
MonoImporter:
externalObjects: {}
serializedVersion: 2
defaultReferences: []
executionOrder: 0
icon: {instanceID: 0}
userData:
assetBundleName:
assetBundleVariant:

34
Assets/Model/Tile.cs Normal file
View File

@@ -0,0 +1,34 @@
using System;
public enum TileType
{
Empty,
Floor
}
public class Tile
{
private TileType _type = TileType.Empty;
public TileType Type {
get => _type;
set
{
_type = value;
Stage.OnTileChanged?.Invoke(this);
}
}
public InstalledObject InstalledObject { get; set; } // for later use
public int X { get; }
public int Y { get; }
public Stage Stage { get; }
public Tile (Stage stage, int x, int y)
{
Stage = stage;
X = x;
Y = y;
}
}

11
Assets/Model/Tile.cs.meta Normal file
View File

@@ -0,0 +1,11 @@
fileFormatVersion: 2
guid: 6b2cc239e986ce842a20e1db28458c95
MonoImporter:
externalObjects: {}
serializedVersion: 2
defaultReferences: []
executionOrder: 0
icon: {instanceID: 0}
userData:
assetBundleName:
assetBundleVariant:

30
Assets/Model/Train.cs Normal file
View File

@@ -0,0 +1,30 @@
using System;
using System.Collections.Generic;
public class Train
{
const int DefaultWagonCount = 1001;
List<Wagon> Wagons { get; } = new List<Wagon>();
public Train()
{
}
public void Generate()
{
Wagons.Clear();
for(int i = 0; i < DefaultWagonCount; i++)
{
var wagon = new Wagon(this);
Wagons.Add(wagon);
wagon.Populate();
}
}
public Wagon GetWagon(int focusedWagon)
{
return Wagons[focusedWagon];
}
}

View File

@@ -0,0 +1,11 @@
fileFormatVersion: 2
guid: b1d28cb20cc7bde489c79fc097124a40
MonoImporter:
externalObjects: {}
serializedVersion: 2
defaultReferences: []
executionOrder: 0
icon: {instanceID: 0}
userData:
assetBundleName:
assetBundleVariant:

33
Assets/Model/Wagon.cs Normal file
View File

@@ -0,0 +1,33 @@
using System;
using System.Collections.Generic;
public class Wagon
{
Train Train { get; }
public Stage LogisticDeck { get; } = null;
public Stage MainDeck { get; private set; } = null;
List<Stage> UpperDecks { get; } = new List<Stage>();
public Wagon(Train train)
{
Train = train;
}
public Stage GetDeck(int level)
{
if (level < -1 || level > UpperDecks.Count)
throw new System.ArgumentOutOfRangeException(nameof(level));
if(level == -1)
return LogisticDeck;
if (level == 0)
return MainDeck;
return UpperDecks[level - 1];
}
public void Populate()
{
MainDeck = new Stage();
MainDeck.Populate();
}
}

View File

@@ -0,0 +1,11 @@
fileFormatVersion: 2
guid: fc033e0279c8b0248a235f5ada36b59a
MonoImporter:
externalObjects: {}
serializedVersion: 2
defaultReferences: []
executionOrder: 0
icon: {instanceID: 0}
userData:
assetBundleName:
assetBundleVariant:

39
Assets/Model/Wall.cs Normal file
View File

@@ -0,0 +1,39 @@
public enum WallOrientation
{
Horizontal,
Vertical
}
public enum WallType
{
Empty,
Full
}
public class Wall
{
public Stage Stage { get; }
public int X { get; }
public int Y { get; }
public WallOrientation Orientation { get; }
WallType _type;
public WallType Type
{
get => _type;
set
{
_type = value;
Stage.OnWallChanged?.Invoke(this);
}
}
public Wall(Stage stage, int x, int y, WallOrientation orientation)
{
Stage = stage;
X = x;
Y = y;
Orientation = orientation;
}
}

11
Assets/Model/Wall.cs.meta Normal file
View File

@@ -0,0 +1,11 @@
fileFormatVersion: 2
guid: bc1935c1ce7f0ac46bd59c5f394166ba
MonoImporter:
externalObjects: {}
serializedVersion: 2
defaultReferences: []
executionOrder: 0
icon: {instanceID: 0}
userData:
assetBundleName:
assetBundleVariant: