biohazardcore, v1.1
Posted on

The library that implements the business logic of the puzzle game inspired by Conway's Game of Life and various block games.
Support cell classification.
Change Log
- models:
- cell classification:
- storing:
- old cells (those that are presented in the primary field, but not presented in the movable field part);
- new cells (those that are presented in the movable field part, but not presented in the primary field);
- intersection between the primary field and the movable field part;
- storing:
- cell classification:
- classifying cells (see the cell classification model for details):
- adding an example for it.
Features
- models:
- field settings:
- storing:
- size;
- initial offset;
- filling;
- minimal count;
- maximal count;
- supporting of default values for some settings;
- storing:
- game settings:
- storing:
- primary field settings;
- movable field part settings;
- storing:
- cell classification:
- storing:
- old cells (those that are presented in the primary field, but not presented in the movable field part);
- new cells (those that are presented in the movable field part, but not presented in the primary field);
- intersection between the primary field and the movable field part;
- storing:
- field settings:
- creating a field by its settings:
- random filling of the generated field;
- game business logic:
- generating of random fields:
- primary field;
- movable field part;
- operations with the movable field part:
- moving;
- rotating;
- unioning with the primary field;
- classifying cells (see the cell classification model for details).
- generating of random fields:
Examples
biohazardcore.ClassifiedGame:
local types = require("lualife.types")
local Size = require("lualife.models.size")
local Point = require("lualife.models.point")
local PlacedField = require("lualife.models.placedfield")
local FieldSettings = require("biohazardcore.models.fieldsettings")
local GameSettings = require("biohazardcore.models.gamesettings")
local ClassifiedGame = require("biohazardcore.classifiedgame")
local function print_field(field)
assert(types.is_instance(field, PlacedField))
field:map(function(point, contains)
io.write(contains and "O" or ".")
if point.x - field.offset.x == field.size.width - 1 then
io.write("\n")
end
end)
io.write("\n")
end
local game = ClassifiedGame:new(GameSettings:new(
FieldSettings:new(Size:new(3, 3)),
FieldSettings:new(Size:new(3, 3))
))
game._field = PlacedField:new(Size:new(3, 3))
game._field:set(Point:new(0, 0))
game._field:set(Point:new(0, 1))
game._field:set(Point:new(0, 2))
game._field_part = PlacedField:new(Size:new(3, 3))
game._field_part:set(Point:new(1, 0))
game._field_part:set(Point:new(2, 1))
game._field_part:set(Point:new(0, 2))
game._field_part:set(Point:new(1, 2))
game._field_part:set(Point:new(2, 2))
local classification = game:classify_cells()
print_field(classification.old)
print_field(classification.new)
print_field(classification.intersection)
Repository
Link: https://github.com/thewizardplusplus/biohazardcore/tree/v1.1.
Content: code.
License: MIT.