Move Memory Blocks game to CMM folder, update app to version 1.1. Use icons from icons32.png instead of build in. Better and more flexible code.

git-svn-id: svn://kolibrios.org@6954 a494cfbc-eb01-0410-851d-a64ba20cac60
This commit is contained in:
Kirill Lipatov (Leency) 2017-09-06 16:16:43 +00:00
parent 1a13dac7e1
commit 670acb8f9c
8 changed files with 217 additions and 2327 deletions

View File

@ -0,0 +1,6 @@
if tup.getconfig("NO_CMM") ~= "" then return end
if tup.getconfig("LANG") == "ru"
then C_LANG = "LANG_RUS"
else C_LANG = "LANG_ENG" -- this includes default case without config
end
tup.rule("mblocks.c", "c-- /D=AUTOBUILD /D=$(C_LANG) %f" .. tup.getconfig("KPACK_CMD"), "mblocks.com")

View File

@ -0,0 +1,9 @@
@del lang.h--
@echo #define LANG_ENG 1 >lang.h--
@c-- mblocks.c
@del mblocks.kex
@rename mblocks.com mblocks
@del warning.txt
@del lang.h--
pause

View File

@ -0,0 +1,202 @@
/*
Memory Blocks for KolibriOS v1.1
Leency&Veliant Edition
2008-2017
*/
#define MEMSIZE 4096 * 12
#include "..\lib\gui.h"
#include "..\lib\random.h"
#include "..\lib\obj\libio_lib.h"
#include "..\lib\obj\libimg_lib.h"
#include "..\lib\patterns\libimg_load_skin.h"
proc_info Form;
#ifndef AUTOBUILD
#include "lang.h--"
#endif
#define COLOR_CELL_BG 0xFFFfff
#define COLOR_CELL_BORDER 0x94AECE
#define CELL_SIZE 43
#define PANEL_Y CELL_SIZE+4*6 + 4
#define PANEL_H 36
#define strok 6 //cell count x
#define stolbcov 10 //cell count y
#ifdef LANG_RUS
#define LABEL_NEW_GAME "New game (F2)";
#else
#define LABEL_NEW_GAME "<22>®¢ ï ¨£à  (F2)";
#endif
int bitstat[60], bitpict[60];
dword butonsx[60], butonsy[60];
dword firstbit, secondbit;
int i, count, lang;
void main()
{
dword id;
load_dll(libio, #libio_init,1);
load_dll(libimg, #libimg_init,1);
Libimg_LoadImage(#skin, "/sys/icons32.png");
Libimg_FillTransparent(skin.image, skin.w, skin.h, COLOR_CELL_BG);
NewGame();
loop() switch(WaitEvent())
{
case evKey:
GetKeys();
if (key_scancode==60) NewGame();
break;
case evButton:
id = GetButtonID();
if (id==1) ExitProcess();
else if (id==5) NewGame();
else {
if (bitstat[id-100] == 0)
{
if (firstbit <> 0x0BAD)
{
if (secondbit <> 0x0BAD)
{
if (bitpict[firstbit-100] == bitpict[secondbit-100])
bitstat[firstbit-100] = bitstat[secondbit-100] = 2;
else
bitstat[firstbit-100] = bitstat[secondbit-100] = 0;
ReDraw_Game_Button(firstbit - 100);
ReDraw_Game_Button(secondbit - 100);
secondbit = 0x0BAD;
firstbit = id;
bitstat[id-100] = 1;
ReDraw_Game_Button(id - 100);
count++;
}
else if (firstbit<>id)
{
secondbit = id;
bitstat[id-100] = 1;
ReDraw_Game_Button(id - 100);
count++;
}
}
else
{
firstbit = id;
bitstat[id-100] = 1;
ReDraw_Game_Button(id - 100);
count++;
}
}
Draw_Count();
}
break;
case evReDraw:
system.color.get();
DefineAndDrawWindow(215,100,CELL_SIZE+4*10 + 4 + 9,PANEL_Y + 4 + PANEL_H +skin_height,0x34,0xC0C0C0,"Memory Blocks",0);
GetProcessInfo(#Form, SelfInfo);
Draw_Panel();
Draw_Game_Pole();
break;
}
}
void NewGame()
{
int off;
FOR (i = 0; i < 60; i++)
{
bitpict[i] = 0;
bitpict[i] = 0;
}
count = 0;
firstbit = secondbit = 0x0BAD;
FOR (i = 0; i < 30; i++)
{
do off = random(60); while (bitpict[off] != 0);
bitpict[off] = i;
do off = random(60); while (bitpict[off] != 0);
bitpict[off] = i;
}
}
void ReDraw_Game_Button(int id)
{
DefineButton(butonsx[id], butonsy[id], CELL_SIZE, CELL_SIZE, 100 + id + BT_HIDE, 0);
switch (bitstat[id])
{
case 0:
Draw_Block(butonsx[id], butonsy[id]);
break;
case 1:
Draw_Pressed_Block(butonsx[id], butonsy[id]);
img_draw stdcall(skin.image, butonsx[id]+6, butonsy[id]+6, 32, 32, 0, bitpict[id]*32);
BREAK;
case 2:
Draw_Open_Block(butonsx[id], butonsy[id]);
img_draw stdcall(skin.image, butonsx[id]+6, butonsy[id]+6, 32, 32, 0, bitpict[id]*32);
BREAK;
}
}
void Draw_Game_Pole()
{
byte j;
for (j = 0; j < stolbcov; j++) for (i = 0; i < strok; i++)
{
butonsx[j*strok+i] = CELL_SIZE+4 * j + 4; //save coordinates to avoid their recalculation after
butonsy[j*strok+i] = CELL_SIZE+4 * i + 4;
ReDraw_Game_Button(j*strok + i);
}
}
void Draw_Block(dword x, y)
{
DrawRectangle(x, y, CELL_SIZE, CELL_SIZE, COLOR_CELL_BORDER);//border
DrawRectangle3D(x + 1, y + 1, CELL_SIZE-2, CELL_SIZE-2, 0xFFFFFF, 0xDEDEDE);//bump
DrawBar(x + 2, y + 2, CELL_SIZE-3, CELL_SIZE-3, 0xBDC7D6);//background
}
void Draw_Open_Block(dword x, y)
{
DrawRectangle(x, y, CELL_SIZE, CELL_SIZE, COLOR_CELL_BORDER);//border
DrawBar(x + 1, y + 1, CELL_SIZE-1, CELL_SIZE-1, COLOR_CELL_BG);//background
}
void Draw_Pressed_Block(dword x, y)
{
DrawRectangle(x, y, CELL_SIZE, CELL_SIZE, COLOR_CELL_BORDER);//border
DrawWideRectangle(x + 1, y + 1, CELL_SIZE-1, CELL_SIZE-1, 2, 0x94DB00);//border green
DrawBar(x + 3, y + 3, CELL_SIZE-5, CELL_SIZE-5, COLOR_CELL_BG);//background
}
void Draw_Panel()
{
DrawBar(0, PANEL_Y, Form.cwidth, 1, system.color.work_dark);
DrawBar(0, PANEL_Y+1, Form.cwidth, 1, system.color.work_light);
DrawBar(0, PANEL_Y+2, Form.cwidth, PANEL_H-2, system.color.work);
DrawStandartCaptButton(9, PANEL_Y+5, 5, LABEL_NEW_GAME);
Draw_Count();
}
void Draw_Count()
{
DrawBar(Form.cwidth-32,PANEL_Y + 12,30,12,system.color.work);
WriteNumber(Form.cwidth-32, PANEL_Y + 12, 0x90, system.color.work_text, 3, count);
}
stop:

Binary file not shown.

Before

Width:  |  Height:  |  Size: 11 KiB

View File

@ -1,4 +0,0 @@
..\..\c--\c-- mblocks.c--
del mblocks.kex
rename mblocks.com mblocks.kex
pause

File diff suppressed because it is too large Load Diff

View File

@ -1,162 +0,0 @@
#startaddress 0
#code32 TRUE
char os_name[8] = {'M','E','N','U','E','T','0','1'};
dword os_version = 0x00000001;
dword start_addr = #main;
dword final_addr = #stop+32;
dword alloc_mem = 0x00100000;
dword x86esp_reg = 0x0007fff0;
dword I_Param = 0x0;
dword I_Icon = 0x0;
//Events
#define evButton 3
#define evKey 2
#define evReDraw 1
//Button options
#define BT_DEL 0x80000000
#define BT_HIDE 0x40000000
#define BT_NOFRAME 0x20000000
//------------------------------------------------------------------------------
inline fastcall dword WaitEvent(){
EAX = 10;
$int 0x40
}
inline fastcall void ExitProcess(){
EAX = -1;
$int 0x40
}
inline fastcall word GetKey(){
EAX = 2;
$int 0x40
EAX = EAX >> 8;
}
inline fastcall word GetButtonID(){
EAX = 17;
$int 0x40
EAX = EAX >> 8;
}
//------------------------------------------------------------------------------
void DefineAndDrawWindow(dword x,y,sizeX,sizeY,byte mainAreaType,dword
mainAreaColor,byte headerType,dword headerColor,EDI)
{
EBX = x << 16 + sizeX;
ECX = y << 16 + sizeY;
EDX = mainAreaType << 24 | mainAreaColor;
ESI = headerType << 24 | headerColor;
$xor eax,eax
$int 0x40
}
void WindowRedrawStatus(dword EBX)
{
EAX = 12;
$int 0x40
}
inline fastcall dword GetSkinWidth(){
EAX = 48;
EBX = 4;
$int 0x40
}
void DefineButton(dword x,y,w,h,EDX,ESI){
EAX = 8;
EBX = x<<16+w;
ECX = y<<16+h;
$int 0x40
}
void WriteText(dword x,y,byte fontType, dword color, EDX, ESI)
{
EAX = 4;
EBX = x<<16+y;
ECX = fontType<<24+color;
$int 0x40;
}
void DrawBar(dword x,y,w,h,EDX)
{
EAX = 13;
EBX = x<<16+w;
ECX = y<<16+h;
$int 0x40
}
void DrawRegion(dword x,y,width,height,color1)
{
DrawBar(x,y,width,1,color1); //ïîëîñà ãîð ñâåðõó
DrawBar(x,y+height,width,1,color1); //ïîëîñà ãîð ñíèçó
DrawBar(x,y,1,height,color1); //ïîëîñà âåðò ñëåâà
DrawBar(x+width,y,1,height+1,color1); //ïîëîñà âåðò ñïðàâà
}
void DrawFlatButton(dword x,y,width,height,id,color)
{
DrawRegion(x,y,width,height,0x94AECE);
DrawBar(x+1,y+1,width-1,1,0xFFFFFF); //ïîëîñà ãîð áåëàÿ
DrawBar(x+1,y+height-1,width-2,1,0xC7C7C7); //òåíü âåðò
DrawBar(x+1,y+1,1,height-1,0xFFFFFF); //ïîëîñà âåðò áåëàÿ
DrawBar(x+width-1,y+2,1,height-2,0xC7C7C7); //òåíü âåðò
DrawBar(x+2,y+2,width-3,height-3,color); //çàëèâêà
DefineButton(x,y,width,height,id+BT_HIDE,0xEFEBEF); //îïðåäåëÿåì êíîïêó
}
void PutImage(dword EBX,w,h,x,y, EDI)
{
EAX = 65;
ECX = w<<16+h;
EDX = x<<16+y;
ESI = 8;
EBP = 0;
$int 0x40
}
void WriteNumber(dword x,y,byte fontType, dword color, count, ECX)
{
EAX = 47;
EBX = count<<16;
EDX = x<<16+y;
ESI = fontType<<24+color;
$int 0x40;
}
dword generator; // random number generator - äëÿ ãåíåðàöèè ñëó÷àéíûõ ÷èñåë
:int random(int max)
// get pseudo-random number - ïîëó÷èòü ïñåâäîñëó÷àéíîå ÷èñëî
{
$rdtsc // eax & edx
$xor eax,edx
$not eax
EBX = generator;
$ror ebx,3
$xor ebx,0xdeadbeef
EBX += EAX;
generator = EBX;
EAX += EBX;
EAX = EAX % max;
}

View File

@ -1,209 +0,0 @@
/*
Memory Blocks for KolibriOS v1.02
L&V Edition
Èäåÿ è äèçàéí: Leency
Ðåàëèçîâàíî: Veliant è Leency
Compile with C--
2008
*/
#codesize
#include "kolibri.h--"
#include "icons.txt"
#define strok 6 //êîëè÷åñòâî áëîêîâ ïî âåðòèêàëè
#define stolbcov 10 //êîëè÷åñòâî áëîêîâ ïî ãîðèçîíòàëè
char button_r[20] = "<22>®¢ ï ¨£à (F2) ‘ç¥â:"; //íîâàÿ èãðà
char button_e[20] = "New game (F2)Count:";
byte bitstat[60], bitpict[60];
dword butonsx[60], butonsy[60];
dword firstbit, secondbit;
int i, count, lang;
void main()
{
byte id;
init();
loop()
{
switch (WaitEvent())
{
CASE evButton:
id = GetButtonID();
SWITCH (id)
{
CASE 1:
ExitProcess();
CASE 5:
init();
break;
CASE 6:
FOR (i=0;i<20;i++) button_r[i]><button_e[i];
IF (!lang) lang=1; ELSE lang=0;
Draw_Panel();
break;
default:
if (bitstat[id-100] == 0)
{
if (firstbit <> 0x0BAD)
{
if (secondbit <> 0x0BAD)
{
IF (bitpict[firstbit-100] == bitpict[secondbit-100])
bitstat[firstbit-100] = bitstat[secondbit-100] = 2;
ELSE
bitstat[firstbit-100] = bitstat[secondbit-100] = 0;
ReDraw_Game_Button(firstbit - 100);
ReDraw_Game_Button(secondbit - 100);
secondbit = 0x0BAD;
firstbit = id;
bitstat[id-100] = 1;
ReDraw_Game_Button(id - 100);
count++;
}
ELSE IF (firstbit<>id)
{
secondbit = id;
bitstat[id-100] = 1;
ReDraw_Game_Button(id - 100);
count++;
}
}
ELSE
{
firstbit = id;
bitstat[id-100] = 1;
ReDraw_Game_Button(id - 100);
count++;
}
}
Draw_Count();
}
break;
case evKey:
IF (GetKey()==51) init();
BREAK;
case evReDraw:
WindowRedrawStatus(1);
DefineAndDrawWindow(100, 100, 434, 291 + GetSkinWidth(), 0x34, 0x10C0C0C0, 0, 0, "Memory Blocks L&V Edition");
Draw_Panel();
Draw_Game_Pole();
WindowRedrawStatus(2);
}
}
}
void init()
{
byte off;
$mov edi, #bitstat
$mov ecx, 60
$xor al, al
$rep $stosb //ñòèðàåì ñòàðûå äàíívå î íàæàòûõ êíîïêàõ
$mov edi, #bitpict
$mov ecx, 60
$xor al, al
$rep $stosb //ñòèðàåì ñòàðûå äàííûå î êàðòèíêàõ
count = 0;
firstbit = secondbit = 0x0BAD;
FOR (i = 0; i < 30; i++)
{
do off = random(60); while (bitpict[off] != 0);
bitpict[off] = i;
do off = random(60); while (bitpict[off] != 0);
bitpict[off] = i;
}
Draw_Game_Pole();
Draw_Panel();
}
void ReDraw_Game_Button(int id)
{
DefineButton(butonsx[id], butonsy[id], 38, 38, 100 + id + BT_HIDE, 0xEFEBEF); //äåëàåì íîâóþ
switch (bitstat[id])
{
CASE 0:
Draw_Block(butonsx[id], butonsy[id]);
break;
CASE 1:
Draw_Pressed_Block(butonsx[id], butonsy[id]);
PutImage(bitpict[id]*32*32+#data,32,32,butonsx[id]+3,butonsy[id]+3, #palitra);
BREAK;
CASE 2:
Draw_Open_Block(butonsx[id], butonsy[id]);
PutImage(bitpict[id]*32*32+#data,32,32,butonsx[id]+3,butonsy[id]+3, #palitra);
BREAK;
}
}
void Draw_Game_Pole()
{
byte j;
FOR (j = 0; j < stolbcov; j++) FOR (i = 0; i < strok; i++)
{
butonsx[j*strok+i] = j * 42 + 4; //ñîõðàíÿåì êîîðäèíàòû ÷òîá íå ñ÷èòàòü â äàëüíåéøåì
butonsy[j*strok+i] = i * 42 + 4;
ReDraw_Game_Button(j*strok + i); //ðèñóåì ïîëå
}
}
void Draw_Block(dword x, y)
{
DrawRegion(x, y, 38, 38, 0x0094AECE);//ðàìêà
DrawBar(x+1, y+1, 37, 1, 0xFFFFFF); //áåëûå ëèíèè
DrawBar(x+1, y+2, 1, 35, 0xFFFFFF);
DrawBar(x+1, y+37, 37, 1, 0xDEDEDE); //ñåðûå ëèíèè
DrawBar(x+37, y+2, 1, 35, 0xDEDEDE);
DrawBar(x + 2, y + 2, 35, 35, 0x00BDC7D6);//ôîí
}
void Draw_Open_Block(dword x, y)
{
DrawRegion(x, y, 38, 38, 0x0094AECE);//ðàìêà
DrawBar(x + 1, y + 1, 37, 37, 0x00EFEBEF);//ôîí
}
void Draw_Pressed_Block(dword x, y)
{
DrawRegion(x, y, 38, 38, 0x0094AECE);//ðàìêà
DrawRegion(x + 1, y + 1, 36, 36, 0x0094DB00);//ðàìêà çåëåíàÿ
DrawRegion(x + 2, y + 2, 34, 34, 0x0094DB00);//ðàìêà çåëåíàÿ
DrawBar(x + 3, y + 3, 33, 33, 0x00EFEBEF);//ôîí
}
void Draw_Panel()
{
DrawBar(0, 255, 425, 32, 0xEBE7DB);//ôîí ïàíåëè
DrawBar(0, 255, 425, 1, 0x94AECE); //ëèíèè
DrawBar(0, 256, 425, 1, 0xFFFFFF); //ëèíèè
//êíîïêè
DrawFlatButton(9, 260, 107, 23, 5, 0xEFEBEF);//íîâàÿ èãðà
WriteText(22,268,0x00,0,#button_r,14);
WriteText(150, 268, 0x80, 0x00, #button_r+14, 0); //íàäïèñü "Ñ÷åò"
DrawFlatButton(215, 260, 23, 23, 6, 0xEFEBEF); //ÿçûê
IF (!lang)
WriteText(221,268,0x80,0,"EN",0);
ELSE
WriteText(221,268,0x80,0,"RU",0);
Draw_Count();
//ïðÿìîóãîëüíèêè ñïðàâà
DrawBar(400 , 265, 2, 2, 0xBDCBDE);
DrawBar(398 , 270, 6, 6, 0xBDCBDE);
DrawBar(406 , 275, 6, 6, 0xBDCBDE);
DrawBar(407 , 262, 9, 8, 0xD6D7CE);
}
void Draw_Count()
{
DrawBar(190,268,18,7,0xEBE7DB); //öâåò ïàíåëè
WriteNumber(190, 268, 0x80, 0x00, 3, count);
}
stop: