1
0
mirror of https://github.com/gryf/wmaker.git synced 2026-02-02 14:15:46 +01:00

changed indentation to use spaces only

This commit is contained in:
dan
2004-10-12 21:28:27 +00:00
parent 5912898b06
commit 6830b05716
240 changed files with 35951 additions and 35773 deletions

View File

@@ -25,12 +25,12 @@ Bool
CheckWin(void)
{
int i;
for (i = 0; i < Size*Size-1; i++) {
if (Map[i] != i)
return False;
if (Map[i] != i)
return False;
}
return True;
}
@@ -46,37 +46,37 @@ Bool
SlideButton(int button)
{
int x=0, y=0, done = 0;
/* locate the button */
for (y = 0; y < Size; y++) {
for (x = 0; x < Size; x++) {
if (MAP(x,y) == button) {
done = 1;
break;
}
}
if (done)
break;
for (x = 0; x < Size; x++) {
if (MAP(x,y) == button) {
done = 1;
break;
}
}
if (done)
break;
}
if (x > 0 && MAP(x-1, y) < 0) {
MAP(x,y) = -1;
MoveButton(button, x-1, y);
MAP(x-1,y) = button;
MAP(x,y) = -1;
MoveButton(button, x-1, y);
MAP(x-1,y) = button;
} else if (x < Size-1 && MAP(x+1, y) < 0) {
MAP(x,y) = -1;
MoveButton(button, x+1, y);
MAP(x+1,y) = button;
MAP(x,y) = -1;
MoveButton(button, x+1, y);
MAP(x+1,y) = button;
} else if (y > 0 && MAP(x, y-1) < 0) {
MAP(x,y) = -1;
MoveButton(button, x, y-1);
MAP(x,y-1) = button;
MAP(x,y) = -1;
MoveButton(button, x, y-1);
MAP(x,y-1) = button;
} else if (y < Size-1 && MAP(x, y+1) < 0) {
MAP(x,y) = -1;
MoveButton(button, x, y+1);
MAP(x,y+1) = button;
MAP(x,y) = -1;
MoveButton(button, x, y+1);
MAP(x,y+1) = button;
} else {
return False;
return False;
}
return True;
}
@@ -87,46 +87,46 @@ SlideButton(int button)
void ResetGame(void)
{
int i, x, y, ox, oy;
MoveCount = 0;
for (i = 0; i < Size*Size-1; i++) {
Map[i] = i;
Map[i] = i;
}
Map[i] = -1;
ox = x = Size-1;
oy = y = Size-1;
for (i = 0; i < 1000; i++) {
int ok;
ok = 1;
switch (rand()%4) {
case 0:
if (x > 0) x--; else ok = 0;
break;
case 2:
if (x < Size-1) x++; else ok = 0;
break;
case 1:
if (y > 0) y--; else ok = 0;
break;
case 3:
if (y < Size-1) y++; else ok = 0;
break;
}
if (ok) {
MoveButton(MAP(x,y), ox, oy);
int ok;
ok = 1;
switch (rand()%4) {
case 0:
if (x > 0) x--; else ok = 0;
break;
case 2:
if (x < Size-1) x++; else ok = 0;
break;
case 1:
if (y > 0) y--; else ok = 0;
break;
case 3:
if (y < Size-1) y++; else ok = 0;
break;
}
if (ok) {
MoveButton(MAP(x,y), ox, oy);
SWAP(MAP(ox, oy), MAP(x, y));
while (XPending(WMScreenDisplay(WMWidgetScreen(win)))) {
XEvent ev;
WMNextEvent(WMScreenDisplay(WMWidgetScreen(win)), &ev);
WMHandleEvent(&ev);
}
ox = x;
oy = y;
}
SWAP(MAP(ox, oy), MAP(x, y));
while (XPending(WMScreenDisplay(WMWidgetScreen(win)))) {
XEvent ev;
WMNextEvent(WMScreenDisplay(WMWidgetScreen(win)), &ev);
WMHandleEvent(&ev);
}
ox = x;
oy = y;
}
}
}
@@ -136,18 +136,18 @@ void buttonClick(WMWidget *w, void *ptr)
char buffer[300];
if (SlideButton((int)ptr)) {
MoveCount++;
MoveCount++;
if (CheckWin()) {
sprintf(buffer, "You finished the game in %i moves.", MoveCount);
if (CheckWin()) {
sprintf(buffer, "You finished the game in %i moves.", MoveCount);
if (WMRunAlertPanel(WMWidgetScreen(w), win, "You Won!", buffer,
"Wee!", "Gah! Lemme retry!", NULL) == WAPRDefault) {
exit(0);
}
ResetGame();
}
if (WMRunAlertPanel(WMWidgetScreen(w), win, "You Won!", buffer,
"Wee!", "Gah! Lemme retry!", NULL) == WAPRDefault) {
exit(0);
}
ResetGame();
}
}
}
@@ -156,17 +156,17 @@ static void resizeObserver(void *self, WMNotification *notif)
{
WMSize size = WMGetViewSize(WMWidgetView(win));
int x, y;
WinSize = size.width;
for (y = 0; y < Size; y++) {
for (x = 0; x < Size; x++) {
if (MAP(x,y) >= 0) {
WMResizeWidget(Button[(int)MAP(x,y)],
WinSize/Size, WinSize/Size);
WMMoveWidget(Button[(int)MAP(x,y)],
x*(WinSize/Size), y*(WinSize/Size));
}
}
for (x = 0; x < Size; x++) {
if (MAP(x,y) >= 0) {
WMResizeWidget(Button[(int)MAP(x,y)],
WinSize/Size, WinSize/Size);
WMMoveWidget(Button[(int)MAP(x,y)],
x*(WinSize/Size), y*(WinSize/Size));
}
}
}
}
@@ -177,18 +177,18 @@ int main(int argc, char **argv)
Display *dpy;
WMScreen *scr;
int x, y, i;
WMInitializeApplication("Puzzle", &argc, argv);
dpy = XOpenDisplay("");
if (!dpy) {
printf("could not open display\n");
exit(1);
printf("could not open display\n");
exit(1);
}
scr = WMCreateScreen(dpy, DefaultScreen(dpy));
win = WMCreateWindow(scr, "puzzle");
WMResizeWidget(win, WinSize, WinSize);
WMSetWindowTitle(win, "zuPzel");
@@ -197,48 +197,49 @@ int main(int argc, char **argv)
WMSetWindowResizeIncrements(win, Size, Size);
WMSetViewNotifySizeChanges(WMWidgetView(win), True);
WMAddNotificationObserver(resizeObserver, NULL,
WMViewSizeDidChangeNotification,
WMWidgetView(win));
WMViewSizeDidChangeNotification,
WMWidgetView(win));
for (i = y = 0; y < Size && i < Size*Size-1; y++) {
for (x = 0; x < Size && i < Size*Size-1; x++) {
char buf[32];
WMColor *color;
RColor col;
RHSVColor hsv;
hsv.hue = i*360/(Size*Size-1);
hsv.saturation = 120;
hsv.value = 200;
RHSVtoRGB(&hsv, &col);
for (x = 0; x < Size && i < Size*Size-1; x++) {
char buf[32];
WMColor *color;
RColor col;
RHSVColor hsv;
color = WMCreateRGBColor(scr, col.red<<8, col.green<<8,
col.blue<<8, False);
hsv.hue = i*360/(Size*Size-1);
hsv.saturation = 120;
hsv.value = 200;
MAP(x,y) = i;
Button[i] = WMCreateButton(win, WBTMomentaryLight);
WMSetWidgetBackgroundColor(Button[i], color);
WMReleaseColor(color);
WMSetButtonAction(Button[i], buttonClick, (void*)i);
WMResizeWidget(Button[i], WinSize/Size, WinSize/Size);
WMMoveWidget(Button[i], x*(WinSize/Size), y*(WinSize/Size));
sprintf(buf, "%i", i+1);
WMSetButtonText(Button[i], buf);
WMSetButtonTextAlignment(Button[i], WACenter);
i++;
}
RHSVtoRGB(&hsv, &col);
color = WMCreateRGBColor(scr, col.red<<8, col.green<<8,
col.blue<<8, False);
MAP(x,y) = i;
Button[i] = WMCreateButton(win, WBTMomentaryLight);
WMSetWidgetBackgroundColor(Button[i], color);
WMReleaseColor(color);
WMSetButtonAction(Button[i], buttonClick, (void*)i);
WMResizeWidget(Button[i], WinSize/Size, WinSize/Size);
WMMoveWidget(Button[i], x*(WinSize/Size), y*(WinSize/Size));
sprintf(buf, "%i", i+1);
WMSetButtonText(Button[i], buf);
WMSetButtonTextAlignment(Button[i], WACenter);
i++;
}
}
WMMapSubwidgets(win);
WMMapWidget(win);
WMRealizeWidget(win);
ResetGame();
WMScreenMainLoop(scr);
return 0;
}