1
0

MazezaM: maze line colors are now chosen randomly plus some speed improvements

This commit is contained in:
acn 2020-06-30 15:12:24 +02:00
parent 8e930e442b
commit ca01ada15c
2 changed files with 61 additions and 43 deletions

View File

@ -11,7 +11,7 @@
z88dk version by Stefano Bodrato (www.z88dk.org)
VT100 version with 42 levels by Anna Christina Naß <acn@acn.wtf>
Color VT100 version with 42 levels by Anna Christina Naß <acn@acn.wtf>
Build:
@ -21,20 +21,22 @@
the terms of the GNU General Public Licence.
*/
// the following assures that this games works when using Z3PLUS etc.
#pragma output REGISTER_SP = 0xa000
#pragma output hrgpage = 36096
#include <stdio.h> // We use printf(); putchar();
#include <string.h> // strlen for the Level name centering.
#include <stdlib.h> // We use rand(); srand();
#include <conio.h> // We use kbhit();
#define LEVELS 42 // Number of Levels
#define TRUE 1
#define FALSE 0
#define PLAYER "P" // player symbol
#define BRICK ":" // brick symbol
#define COLWAY 15 // color of entrance and exit
#define COLDOOR 15 // color of entrance door
#define COLDOOR 11 // color of entrance door
#define COLPLAYER 14 // color of player
#define COLBRICK 8 // color of bricks
@ -57,6 +59,9 @@ static char *ARGH[]={
"PUFF!"
};
/* we need 12 colors as the "biggest" maze has 12 lines */
static int LineColors[]={ 1, 2, 3, 4, 5, 6, 7, 9, 10, 11, 12, 13 };
/* We use escape control combinations for handling of the display */
ClearScreen()
@ -95,6 +100,18 @@ int color;
printf("\033[4%dm", color);
}
ShuffleColors()
{
int n = sizeof(LineColors) / sizeof(LineColors[0]);
for (int i = 0; i < n - 1; i++)
{
int j = i + (rand()%n) / (n / (n - i) + 1);
int t = LineColors[j];
LineColors[j] = LineColors[i];
LineColors[i] = t;
}
}
PrintPlayer()
{
FgCol(COLPLAYER);
@ -105,7 +122,7 @@ PrintPlayer()
ColorLine(line)
int line;
{
FgCol(line);
FgCol(LineColors[line-1]);
}
void PrintEnter()
@ -116,7 +133,7 @@ void PrintEnter()
void FillRow()
{
FgCol(COLBRICK);
for (Column=0;Column<80;Column++) printf(BRICK);
printf("::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::");
ResetAttr();
PrintEnter();
}
@ -124,13 +141,13 @@ void FillRow()
void FillWall()
{
FgCol(COLBRICK);
for (l=0;l<26;l++) printf(BRICK);
printf("::::::::::::::::::::::::::");
ResetAttr();
}
void FillSpace()
{
for (l=0;l<28;l++) printf(" ");
printf(" ");
}
void gotogxy(int x,int y)
@ -143,24 +160,26 @@ void Level(int MazeNumber)
int k;
char *LevelName; // Pointer to the Level name string.
ShuffleColors();
ClearScreen();
switch (MazeNumber)
{
case 1:
LevelName="Humble Origins";uWidth=7;uHeight=2;lx=1;rx=1;
LevelName="Humble Origins";uWidth=7;uHeight=2;lx=rx=1;
MazeLine[1]=" # # ";
MazeLine[2]=" # ## ";
break;
case 2:
LevelName="Easy Does It";uWidth=8;uHeight=3;lx=3;rx=2;
LevelName="Easy Does It";uWidth=8;uHeight=lx=3;rx=2;
MazeLine[1]=" # ###";
MazeLine[2]=" # # # ";
MazeLine[3]=" # # # ";
break;
case 3:
LevelName="Up, Up and Away";uWidth=5;uHeight=11;lx=11;rx=1;
LevelName="Up, Up and Away";uWidth=5;uHeight=lx=11;rx=1;
MazeLine[1]= " # ";
MazeLine[2]= " # ##";
MazeLine[3]= " ## ";
@ -183,7 +202,7 @@ void Level(int MazeNumber)
break;
case 5:
LevelName="To and Fro";uWidth=13;uHeight=6;lx=1;rx=1;
LevelName="To and Fro";uWidth=13;uHeight=6;lx=rx=1;
MazeLine[1]=" ##### ";
MazeLine[2]="# ##### ### ";
MazeLine[3]=" # ### #### ";
@ -218,7 +237,7 @@ void Level(int MazeNumber)
break;
case 9:
LevelName="Two Front Doors";uWidth=16;uHeight=7;lx=1;rx=7;
LevelName="Two Front Doors";uWidth=16;uHeight=rx=7;lx=1;
MazeLine[1]=" ####### ";
MazeLine[2]=" #### #### # # ";
MazeLine[3]="## ## ###### # #";
@ -237,7 +256,7 @@ void Level(int MazeNumber)
break;
case 11:
LevelName="Double Cross";uWidth=9;uHeight=7;lx=7;rx=3;
LevelName="Double Cross";uWidth=9;uHeight=lx=7;rx=3;
MazeLine[1]=" # #### ";
MazeLine[2]=" # # ## ";
MazeLine[3]=" # #### #";
@ -574,15 +593,15 @@ void Level(int MazeNumber)
l=((80-uWidth)/2);
t=((22-uHeight)/2);
r=80-l-uWidth;
FgCol(COLBRICK); printf(BRICK); printf(BRICK);printf(BRICK); ResetAttr();
FgCol(COLBRICK); printf(":::"); ResetAttr();
printf(" Level ");
if (MazeNumber<10) printf("0%d ",MazeNumber);
else printf("%d ",MazeNumber);
FgCol(COLBRICK); for (i=0;i<50;i++) printf(BRICK); ResetAttr();
FgCol(COLBRICK); printf("::::::::::::::::::::::::::::::::::::::::::::::::::"); ResetAttr();
printf(" Lives ");
if (uLives<10) printf("0%d",uLives);
else printf("%d",uLives);
FgCol(COLBRICK); printf(" "); printf(BRICK); printf(BRICK); printf(BRICK); PrintEnter(); ResetAttr();
FgCol(COLBRICK); printf(" "); printf(":::"); PrintEnter(); ResetAttr();
for (i=1;i!=t+1;i++) FillRow();
@ -590,20 +609,20 @@ void Level(int MazeNumber)
for (i=1;i!=uHeight+1;i++)
{
if (i==lx) for (k=0;k!=l;k++) { FgCol(COLWAY); printf("_"); ResetAttr(); }
if (i!=lx) for (k=0;k!=l;k++) { FgCol(COLBRICK); printf(BRICK); ResetAttr(); }
if (i!=lx) for (k=0;k!=l;k++) { FgCol(COLBRICK); printf(":"); ResetAttr(); }
ColorLine(i); printf(MazeLine[i]); ResetAttr(); // Print the Level line.
if (i==rx) for (k=0;k!=r;k++) { FgCol(COLWAY); printf("_"); ResetAttr(); }
if (i!=rx) for (k=0;k!=r;k++) { FgCol(COLBRICK); printf(BRICK); ResetAttr(); }
if (i!=rx) for (k=0;k!=r;k++) { FgCol(COLBRICK); printf(":"); ResetAttr(); }
PrintEnter();
}
FgCol(COLBRICK); for (i=t+uHeight+1;i!=22;i++) FillRow(); ResetAttr();
j=strlen(LevelName);
FgCol(COLBRICK); for (k=0;k!=((78-j)/2);k++) printf(BRICK); ResetAttr();
printf(" ");
printf(LevelName);
printf(" ");
FgCol(COLBRICK); for (k=0;k!=((78-j)/2);k++) printf(BRICK); ResetAttr();
FgCol(COLBRICK); for (k=0;k!=((78-j)/2);k++) printf(":"); ResetAttr();
InverseOn();
printf(" "); printf(LevelName); printf(" ");
InverseOff();
FgCol(COLBRICK); for (k=0;k!=((78-j)/2);k++) printf(":"); ResetAttr();
PrintEnter();
for (i=0;i!=l;i++)
@ -624,12 +643,14 @@ void Level(int MazeNumber)
void Title()
{
int seed; // for random seed initialization
ClearScreen();
gotogxy(0,2);
FillRow();
FillWall(); BgCol(7); FgCol(13);
FillWall(); BgCol(4); FgCol(13);
printf(" M"); FgCol(10); printf(" a"); FgCol(11); printf(" z");
FgCol(12); printf(" e"); FgCol(11); printf(" z"); FgCol(10); printf(" a");
FgCol(9); printf(" e"); FgCol(11); printf(" z"); FgCol(10); printf(" a");
FgCol(13); printf(" M "); ResetAttr();
FillWall(); PrintEnter();
FillRow();
@ -656,7 +677,8 @@ void Title()
{
gotogxy(Column,11);
PrintPlayer();
PressedKey=getkey();
PressedKey=getk();
seed++;
if (PressedKey==' ') break;
if (PressedKey=='Q' || PressedKey=='q')
@ -664,19 +686,20 @@ void Title()
bCloseFlag=TRUE;
break;
}
if (PressedKey=='6')
if (PressedKey=='6' || PressedKey=='d' || PressedKey=='D')
{
gotogxy(Column,11);
Column+=(Column<53);
printf(" ");
}
if (PressedKey=='4')
if (PressedKey=='4' || PressedKey=='a' || PressedKey=='A')
{
gotogxy(Column,11);
Column-=(Column>26);
printf(" ");
}
}
srand(seed);
}
@ -716,11 +739,6 @@ int main()
// quit
if (PressedKey=='Q' || PressedKey=='q')
{
//gotogxy(l+j-3,t+i-1);
//InverseOn();
//printf(ARGH[rand%9]);
//InverseOff();
//getkey();
gotogxy(35,10);
InverseOn();
printf("GAME OVER!");

Binary file not shown.