-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathminitile.cs
153 lines (152 loc) · 4 KB
/
minitile.cs
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
using System;
using System.Collections.Generic;
using System.IO;
using System.Linq;
using System.Text.RegularExpressions;
// color
using Microsoft.Xna.Framework;
namespace Mini {
static class Core {
public static readonly char blockChar = (char)0xdb;
public static void ParseData(){
IEnumerable<string> raw = File.ReadAllLines("data/material.dat")
.Select(line =>
Regex.Replace(line.ToLower(), @"^\s+|\s+$", "") // set lowercase; remove leading/trailing whitespace
);
string type = "";
// MAKE SURE TO COPY THESE TO RESET
string name = "";
Color color = Color.Black;
ushort density = 1000;
Action Reset = () => {
name = "";
color = Color.Black;
density = 1000;
};
int materials = 0;
foreach (string line in raw){
string[] split = line.Split(" ");
string kw = split[0];
switch (kw){
case "material":
type = kw;
continue;
case "name":
name = split[1];
continue;
case "color":
color = Program.ColorFromHex(split[1]);
continue;
case "density":
density = ushort.Parse(split[1]);
continue;
case "end":
break; // handled below
default: // just a comment!
continue;
}
// handle end
if (type == "material"){
new Material(name, color, density);
materials++;
}
else
throw new NotImplementedException();
// reset
Reset();
}
Program.Log(String.Format("{0} materials loaded", materials));
}
}
class Map {
/*
This will be where the game is played out.
Todo: elevation, rivers, flora, resource placement.
*/
static readonly int mapsize = 100; // tiles; each is 1m^2
readonly Tile[,] tiles = new Tile[mapsize, mapsize];
readonly WorldTile worldtile; // used to determine climate
public Map(WorldTile w){
worldtile = w;
Generate();
// todo: change view to Mini.Map!
}
void Generate(){
// generate "hilly" parts...
// generate APPROPRIATE flora
// for now just generate a dirt floor and nothing else...
Material dirt = Material.FromString("dirt");
int percent = 1;
for (int x = 0; x < mapsize; x++){
for (int y = 0; y < mapsize; y++)
tiles[x, y] = new Tile(null, dirt.floor);
if (percent*100.0 <= (double)x/mapsize){
Program.LogProgress(percent, 100);
percent++;
}
}
Program.Log("Generated MiniMap");
}
}
class Tile {
/*
This is a 1m^2 "block"
floor, wall, furniture
*/
Block block;
Floor floor;
Tuple<char, Color, Color> charForeBack {
get { return block == null ? floor.charForeBack : block.charForeBack; }
}
public Tile(Block b, Floor f){
this.block = b;
this.floor = f;
}
}
class Material {
// each material has a block and floor form. each block/floor has a material.
static readonly List<Material> materials = new List<Material>();
readonly Block block;
public readonly Floor floor;
readonly string name;
public readonly Color color;
readonly ushort density; // kg/m^3
// readonly short melt, boil; // "degrees centicelsius", ie. C*100
// todo: standardize temperature (make a class for it?) across ALL files
public Material (string name, Color color, ushort density){
this.name = name;
this.color = color;
this.density = density;
// create block and floor
block = new Block(this);
floor = new Floor(this);
// push to list
materials.Add(this);
}
public static Material FromString(string s){
return materials.Find(m => m.name == s);
}
}
abstract class MadeFromMaterial {
readonly Material material;
public MadeFromMaterial(Material m){
this.material = m;
}
public Tuple<char, Color, Color> charForeBack {
get { return new Tuple<char, Color, Color>(Core.blockChar, material.color, material.color); }
}
}
class Block : MadeFromMaterial {
public Block(Material m) : base(m){}
}
class Floor : MadeFromMaterial {
public Floor(Material m) : base(m){}
}
class Building : Block {
// incl. furniture
readonly byte size;
Building(Material m, byte size) : base(m){
this.size = size;
}
}
}