From a1301e94a0c47fc86bed6caffc2cedc74bcc449f Mon Sep 17 00:00:00 2001 From: Geoffrey Frogeye Date: Sat, 5 Apr 2014 17:03:58 +0200 Subject: [PATCH] Prettyfication Is that even a word? No more french, no more useless comment, no more endless switch at beginning --- 2048.G1A | Bin 18952 -> 18648 bytes 2048.c | 160 ++++++++++++++++++------------------------------------- 2048.dlw | 6 +-- 3 files changed, 56 insertions(+), 110 deletions(-) diff --git a/2048.G1A b/2048.G1A index 1907562aa47743a570fbf083d720438391ea3723..1e2cf02ca8c83aa17b07e3d42ef757db2c690c75 100644 GIT binary patch delta 1536 zcma)+e@qis9KheZR=DdGQ$g`WMxn)ug>h$*QiqeaM>|kM11NFKEO0G~+o(TcH~;dM zkU)vz#HWif{LxIZ8AGPa88sQdvMh_)+)_A399c|b5tn6gn_ZZHkg@Nz#<>4>FQ5Cq z_kG{*_ulvWzPacHe18aY*G9*$pNn1|G_L#(WAUGrmD`(-pj)2~alEcZsQO~pRlKd? zK6>d#)8RUfJFGJ|iH+K{Y4lw+tRB7+ywZra z?`Wi9AgNdVEWtU39lzDlBHNj|QA>_erA_=|5=~!zxWdncTLYFJF_3#GDKCG(@={ll zcOF!ETLkmY_t}u@VNc*>4(~iv)%@4NWS9D|0B_b8%$%7X^sw71gO>i<7upu_Q6iOvmByp{y`I*}OvOYnpZRD(eGu}gP>CLZ* zC-j}(U|x&IgSPJQ&@fQY>P3znURr&fJk{5hRDQSz{OQgXuxj?8_?G|LsW#HIss?kU zZcIgNz8dfJ4eNGJiF?kE!c zm*y@$M(Rbed_fFYCi)OFc|U_XBng(Xft=}ck_n`4GQNOfS%`@bN(k0?^6mnjsXgs2 z57=g+!D6fHG&9{FG+A8(x_EyOfy9VSpai@T6R@bg)4d^wl2Xkav-6Exq zS0w1?J6)NbkLG1Mlu|8{+9@7`o`4H5cZyO{n@OTtNKVn~gZTkVICYAalFxm+p?awk zuAn!;RXSQc>guAB7kh5R$U^3lp<=^86si{n-UE7&VEhW?5uh7@s`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H~n0N68XZF8+Yjs}{*k`&HYh@17E+dPAHV zrV7`c=CYhhV1P8K7d;1;3hx{SMu4&362!^g7Q~V+^=k`yV5{^aw$7!n zd;^MrR^KT926h^ZYbJ6 zr#jL;X3mJ%j+xuZNlS;^Eh~4(?$p70(}4AWwG9X1mPvv|IFA7jfq#HWU;^< #define false 0 #define true 1 typedef char bool; @@ -60,7 +57,7 @@ bool Game_won = false; bool Game_terminated = false; bool Game_keepPlaying = true; -int storage_bestScore = 6357; +int storage_bestScore = 0; Grid Grid_grid; @@ -70,10 +67,8 @@ int rand_int(int min, int max) { } int drawFixedTiles() { - // Variables int x, y; - // Éxecution for (x = 0; x <= 3; x++) { for (y = 0; y <= 3; y++) { drawTileCase(Grid_grid.array[x][y]); @@ -82,47 +77,7 @@ int drawFixedTiles() { } int drawTile(int x, int y, int value) { ML_rectangle(x + 1, y + 1, x + 11, y + 11, 0, ML_TRANSPARENT, ML_WHITE); - switch (value) { - case 0: - ML_bmp_or(tile0, x, y, 13, 13); - break; - case 1: - ML_bmp_or(tile1, x, y, 13, 13); - break; - case 2: - ML_bmp_or(tile2, x, y, 13, 13); - break; - case 3: - ML_bmp_or(tile3, x, y, 13, 13); - break; - case 4: - ML_bmp_or(tile4, x, y, 13, 13); - break; - case 5: - ML_bmp_or(tile5, x, y, 13, 13); - break; - case 6: - ML_bmp_or(tile6, x, y, 13, 13); - break; - case 7: - ML_bmp_or(tile7, x, y, 13, 13); - break; - case 8: - ML_bmp_or(tile8, x, y, 13, 13); - break; - case 9: - ML_bmp_or(tile9, x, y, 13, 13); - break; - case 10: - ML_bmp_or(tile10, x, y, 13, 13); - break; - case 11: - ML_bmp_or(tile11, x, y, 13, 13); - break; - default: - ML_bmp_or(tile12, x, y, 13, 13); - break; - } + ML_bmp_or(tile[value], x, y, 13, 13); } int drawTileCase(Tile tile) { @@ -131,7 +86,7 @@ int drawTileCase(Tile tile) { // Grid -bool Grid_withinBounds(Cell position) { // En abuser +bool Grid_withinBounds(Cell position) { return (position.x >= 0 && position.x < 4 && position.y >= 0 && position.y < 4); } @@ -149,7 +104,7 @@ bool Grid_cellOccupied(Cell cell) { return (Grid_cellContent(cell).value > 0); } -bool Grid_cellAvailable(Cell cell) { // Pareil +bool Grid_cellAvailable(Cell cell) { return !Grid_cellOccupied(cell); } @@ -195,11 +150,11 @@ void storage_setBestScore(int bestScore) { // Screen (O HTML_Actuator) void Screen_updateScore() { - // Affiche le score à l'écran + } void Screen_updateBestScore() { - // Affiche le meilleur score à l'écran + } void Screen_message(bool won) { @@ -228,12 +183,6 @@ void Screen_actuate() { ML_display_vram(); } -Cell convertNumber2Pos(int number) { - Cell position; - position.x = number/4; - position.x = number%4; -} - // Game (O Game_manager) bool Game_isGameTerminated() { @@ -323,7 +272,7 @@ Cell Grid_randomAvaiableCell() { avaiableCellsNumber = Grid_avaiableCellsAmount(); choosenCellNumber = rand_int(1, avaiableCellsNumber); - avaiableCellsNumber = 0; // Sert de compteur ici + avaiableCellsNumber = 0; // Used as counter here for (x = 0; x <= 3; x++) { for (y = 0; y <= 3; y++) { position.x = x; @@ -418,7 +367,7 @@ int initGame() { ML_clear_screen(); - // Draw Titre + // Draw Title PrintXY(67, 54, "2048", 0); // Reset variables @@ -457,43 +406,41 @@ int AddIn_main(int isAppli, unsigned short OptionNum) { // Variables unsigned int key; - while (1) { // Tant qu'on joue... - initGame(); - while (1) { // Boucle des mouvements - GetKey(&key); - switch (key) { - case KEY_CTRL_UP: - Game_move(0); - break; - case KEY_CTRL_RIGHT: - Game_move(1); - break; - case KEY_CTRL_DOWN: - Game_move(2); - break; - case KEY_CTRL_LEFT: - Game_move(3); - break; - case KEY_CTRL_DEL: - initGame(); - break; - case KEY_CHAR_PLUS: - Game_addRandomTile(); - Game_actuate(); - break; - case KEY_CHAR_STORE: - Game_actuate(); - break; - default: - break; - } - } + initGame(); + while (1) { // Main loop + GetKey(&key); + switch (key) { + case KEY_CTRL_UP: + Game_move(0); + break; + case KEY_CTRL_RIGHT: + Game_move(1); + break; + case KEY_CTRL_DOWN: + Game_move(2); + break; + case KEY_CTRL_LEFT: + Game_move(3); + break; + case KEY_CTRL_DEL: + initGame(); + break; + case KEY_CHAR_PLUS: // DEBUG + Game_addRandomTile(); + Game_actuate(); + break; + case KEY_CHAR_STORE: // DEBUG + Game_actuate(); + break; + default: + break; + } } - return 1; + return 1; // 1 is OK here } -// Code propre au SDK. NE PAS MODIFIER ! +// Exclusive code to any Add-in #pragma section _BR_Size unsigned long BR_Size; @@ -507,4 +454,3 @@ int InitializeSystem(int isAppli, unsigned short OptionNum) { } #pragma section - diff --git a/2048.dlw b/2048.dlw index a7fe65f..ed2a83f 100644 --- a/2048.dlw +++ b/2048.dlw @@ -2,7 +2,7 @@ [_1] Type=5 -Order=2 +Order=1 Top=60 Left=1965 Height=10080 @@ -14,7 +14,7 @@ OptionA=0 [_2] Type=1 -Order=0 +Order=2 Top=0 Left=12645 Height=4665 @@ -92,7 +92,7 @@ OptionA=0 [_9] Type=15 -Order=1 +Order=0 Top=0 Left=2010 Height=11580