Skip to content

Commit

Permalink
Fixed bug in Unix background color for the console. Update CuiTetris.
Browse files Browse the repository at this point in the history
  • Loading branch information
wilkie committed May 7, 2010
1 parent 64f9bd4 commit 4dba0e5
Show file tree
Hide file tree
Showing 4 changed files with 24 additions and 10 deletions.
8 changes: 5 additions & 3 deletions examples/CuiTetris/app.d
@@ -1,5 +1,7 @@
import cui.application; import cui.application;


import djehuty;

import io.console; import io.console;


import gamewindow; import gamewindow;
Expand All @@ -22,13 +24,13 @@ class TermTetris : CuiApplication {


override void onApplicationEnd() { override void onApplicationEnd() {
Console.clear(); Console.clear();
Console.setColor(fgColor.White); Console.forecolor = Color.White;
Console.put("Your Score was: "); Console.put("Your Score was: ");
Console.setColor(fgColor.BrightYellow); Console.forecolor = Color.Yellow;
Console.putln(gameWindow.getScore()); Console.putln(gameWindow.getScore());


Console.putln(""); Console.putln("");
Console.setColor(fgColor.White); Console.forecolor = Color.Gray;
Console.putln("Thank you for playing!"); Console.putln("Thank you for playing!");
} }


Expand Down
23 changes: 17 additions & 6 deletions examples/CuiTetris/gamecontrol.d
Expand Up @@ -118,7 +118,7 @@ class GameControl : CuiWidget {
if (clr != board[i,j]) { if (clr != board[i,j]) {
clr = board[i,j]; clr = board[i,j];


Console.setColor(cast(bgColor)clr); Console.backcolor = colors[clr];
} }


Console.putAt(i*4, (j*2) + o, " "); Console.putAt(i*4, (j*2) + o, " ");
Expand All @@ -128,11 +128,21 @@ class GameControl : CuiWidget {
} }
} }


static Color colors[] = [
Color.Black,
Color.Red,
Color.Blue,
Color.Green,
Color.Yellow,
Color.Magenta,
Color.Cyan,
Color.White
];

void drawPiece() { void drawPiece() {
synchronized(this) { synchronized(this) {
lastPiece = new Coord[](4); lastPiece = new Coord[](4);

Console.backcolor = colors[board.getPieceType() + 1];
Console.setColor(cast(bgColor)(board.getPieceType() + 1));


foreach(i, pt; board.getPiece()) { foreach(i, pt; board.getPiece()) {
Coord curPt; Coord curPt;
Expand All @@ -149,13 +159,14 @@ class GameControl : CuiWidget {
} }
} }


Console.setColor(fgColor.White); Console.forecolor = Color.Gray;
} }
} }


void clearPiece() { void clearPiece() {
synchronized(this) { synchronized(this) {
Console.setColor(fgColor.Blue, bgColor.Black); Console.forecolor = Color.Blue;
Console.backcolor = Color.Black;
foreach(pt; lastPiece) { foreach(pt; lastPiece) {
if (pt.x >= 0 && pt.y >= 0 && pt.x < 40 && pt.y < 40) { if (pt.x >= 0 && pt.y >= 0 && pt.x < 40 && pt.y < 40) {
//Console.position(pt.x, pt.y); //Console.position(pt.x, pt.y);
Expand All @@ -164,7 +175,7 @@ class GameControl : CuiWidget {
Console.putAt(pt.x, pt.y + 1, " "); Console.putAt(pt.x, pt.y + 1, " ");
} }
} }
Console.setColor(fgColor.White); Console.forecolor = Color.Gray;
} }
} }


Expand Down
2 changes: 1 addition & 1 deletion examples/CuiTetris/gamewindow.d
Expand Up @@ -13,7 +13,7 @@ class GameWindow : CuiWindow {
game = new GameControl(); game = new GameControl();


push(scoreLabel); push(scoreLabel);
push(new CuiLabel(2, 3, 10, "Score", fgColor.BrightYellow)); push(new CuiLabel(2, 3, 10, "Score", Color.Yellow));
push(game); push(game);
} }


Expand Down
1 change: 1 addition & 0 deletions platform/unix/scaffold/console.d
Expand Up @@ -116,6 +116,7 @@ void ConsoleSetColors(Color fg, Color bg) {
fgidx %= 8; fgidx %= 8;
bright = 1; bright = 1;
} }
bgidx %= 8;
if (ApplicationController.instance.usingCurses) { if (ApplicationController.instance.usingCurses) {
int idx = fgidx << 3; int idx = fgidx << 3;
idx |= bgidx; idx |= bgidx;
Expand Down

0 comments on commit 4dba0e5

Please sign in to comment.