commit 7baec828c46f0d02c56583c9cc65490beb76b470 Author: Slendi Date: Tue Mar 21 21:56:04 2023 +0200 "Initial" commit. Move to tbuild build system. Signed-off-by: Slendi diff --git a/.gitignore b/.gitignore new file mode 100644 index 0000000..76f4628 --- /dev/null +++ b/.gitignore @@ -0,0 +1,2 @@ +build +output diff --git a/LICENSE.md b/LICENSE.md new file mode 100644 index 0000000..2e61574 --- /dev/null +++ b/LICENSE.md @@ -0,0 +1,27 @@ +# DON'T BE A DICK PUBLIC LICENSE + +> Version 1.1, December 2016 + +> Copyright (C) 2022 Slendi + +Everyone is permitted to copy and distribute verbatim or modified +copies of this license document. + +> DON'T BE A DICK PUBLIC LICENSE +> TERMS AND CONDITIONS FOR COPYING, DISTRIBUTION AND MODIFICATION + +1. Do whatever you like with the original work, just don't be a dick. + + Being a dick includes - but is not limited to - the following instances: + + 1a. Outright copyright infringement - Don't just copy this and change the name. + 1b. Selling the unmodified original with no work done what-so-ever, that's REALLY being a dick. + 1c. Modifying the original work to contain hidden harmful content. That would make you a PROPER dick. + +2. If you become rich through modifications, related works/services, or supporting the original work, +share the love. Only a dick would make loads off this work and not buy the original work's +creator(s) a pint. + +3. Code is provided with no warranty. Using somebody else's code and bitching when it goes wrong makes +you a DONKEY dick. Fix the problem yourself. A non-dick would submit the fix back. + diff --git a/README.md b/README.md new file mode 100644 index 0000000..146dd84 --- /dev/null +++ b/README.md @@ -0,0 +1,16 @@ +TempleOS Wordle +=============== + +What's this? +------------ + +This is a TempleOS and ZealOS exclusive guessing game. + +Where do I get this from? +------------------------- +You can download one of the latest releases from (here)[https://git.templeos.me/slendi/wordletos/releases] or you can build it yourself using (tbuilld)[https://git.templeos.me/slendi/tbuild]. + +LICENSE +------- + +This software is licensed under the DBAD license. Click [here](LICENSE.md) for more details. diff --git a/src/HolyC.HC b/src/HolyC.HC new file mode 100644 index 0000000..e2dbdba --- /dev/null +++ b/src/HolyC.HC @@ -0,0 +1,39 @@ +// This file contains utility functions + +U0 GrChar(CDC *dc=gr.dc, U8 ch, I64 x, I64 y, I64 scale=1) +{ + I64 i,j,k=0; + for (i=0; icolor; + + switch(type) { + case LT_OK: dc->color = GREEN; break; + case LT_POS: dc->color = YELLOW; break; + case LT_SEL: dc->color = BLUE; break; + case LT_EMP: + default: dc->color = LTGRAY; + } + + GrRndRect(dc, LT_RAD+x, LT_RAD+y, LT_SZ, LT_SZ, LT_RAD); + + dc->color=BLACK; + + // FIXME: Buggy, needs better math + GrChar(dc, ch, x+LT_OFFX+(LT_CX-LT_FHALF)/2, y+LT_OFFY+(LT_CY-LT_FHALF)/2, LT_FSCALE); + + dc->color=pcol; +} + +U0 DrawWin(CDC *dc) +{ + if (win == W_NONE) return; + + I64 pcol=dc->color; + + dc->color=BLACK; + GrRndRect(dc, dc->width/2-DIALOGW/2, dc->height/2-DIALOGH/2, + DIALOGW, DIALOGH, FONT_WIDTH); + dc->color=WHITE; + GrRndRect(dc, dc->width/2-DIALOGW/2, dc->height/2-DIALOGH/2, + DIALOGW, DIALOGH, FONT_WIDTH/2); + + switch (win) + { + case W_WIN: + dc->color=GREEN; + GrPrint(dc, dc->width/2-4*FONT_WIDTH, dc->height/2-FONT_HEIGHT/2-FONT_HEIGHT, "You win!"); + break; + case W_FAIL: + dc->color=RED; + GrPrint(dc, dc->width/2-4.5*FONT_WIDTH, dc->height/2-FONT_HEIGHT/2-FONT_HEIGHT, "You lose!"); + break; + } + + dc->color=BLACK; + GrPrint(dc, dc->width/2-13*FONT_WIDTH, dc->height/2-FONT_HEIGHT/2+FONT_HEIGHT, "Press ENTER to play again!"); + + dc->color=pcol; +} + +U0 DrawTable(CDC *dc=gr.dc) +{ + I64 i,j; + I64 type; + U8 ch; + + I64 w=(LT_SZ+LT_RAD*2+LT_SPACING)*WLEN; + I64 h=(LT_SZ+LT_RAD*2+LT_SPACING)*WDEPTH; + I64 offx=dc->width/2-w/2; + I64 offy=dc->height/2-h/2; + + for (i=0; iwidth-FONT_WIDTH*21, FONT_HEIGHT, "Toggle theme: CTRL-T\n Quit: CTRL-Q | ESC"); + GrPrint(dc, dc->width-FONT_WIDTH*(StrLen(version)+1), dc->height-(FONT_HEIGHT*3), version); + DrawWin(dc); +} + +U0 ResetGame() +{ + I64 i; + I64 randomWord = RandRng(,wcnt); + + word = wwords[randomWord]; + if (word == NULL) + throw('WN'); + + cdepth=0; + + for (i=0; idraw_it = &WordleDrawIt; + + I64 wbase,len; + U8 *cheatCode="elephants"; + I64 cheatIdx=0; + try { + while (TRUE) { + wbase=cdepth*WLEN; + len=StrLen(gameTable+wbase); + + U8 key = GetKey(&sc); + switch (key) { // FIXME: This can probably be optimized further + case 'a'...'z': + if (key == cheatCode[cheatIdx]) + cheatIdx++; + else + cheatIdx=0; + + if (cheatIdx == StrLen(cheatCode)) + gcheats=!gcheats; + + if (win != W_NONE) break; + if (wbase+len >= (cdepth+1)*WLEN) break; + if (cdepth != 0) + if (wbase+len <= (cdepth-1)*WLEN) break; + + if (len <= WLEN) { + gameTable[wbase+len] = key; + } + break; + case CH_BACKSPACE: + if (win != W_NONE) break; + if (wbase+len > (cdepth+1)*WLEN) break; + if (cdepth != 0) + if (wbase+len <= (cdepth-1)*WLEN) break; + + if (len > 0) { + gameTable[wbase+len-1] = '\0'; + } + break; + case '\n': + if (win != W_NONE) { + ResetGame(); + break; + } + if (len == 5) + cdepth++; + win = CheckWin(); + break; + case CH_CTRLT: + if (wdark) + WordleLight(); + else + WordleDark(); + wdark=!wdark; + break; + case CH_CTRLQ: + case CH_SHIFT_ESC: + case CH_ESC: + goto wordle_done; + } + } + } catch PutExcept; + +wordle_done: + Free(gameTable); + + for (i=0; i