~ajpaon/squell

42f36bea671c2fbfaf47c17637a9c0932ed91a0d — Andrew Paon 10 months ago 888d58e
Add 5-long pieces and u shapes

Table needs to be stretched by an extra row and column per piece. it's
tough to tell apart the different lengths so I fill it with period
placeholders instead of spaces
1 files changed, 40 insertions(+), 14 deletions(-)

M main.c
M main.c => main.c +40 -14
@@ 1,3 1,4 @@
#include <assert.h>
#include <errno.h>
#include <sqlite3.h>
#include <stddef.h>


@@ 238,7 239,7 @@ struct Piece piece_parse(const char *in) {
  };
}

#define NPIECES 22
#define NPIECES 28
struct Piece PIECES[NPIECES];

#define NCLEARS 27


@@ 299,7 300,7 @@ void render_piece(char *out, int offset, int width, struct Piece p,
        out[o + 0] = fillchar;
        out[o + 1] = fillchar;
      } else {
        out[o + 0] = ' ';
        out[o + 0] = '.';
        out[o + 1] = ' ';
      }



@@ 314,16 315,17 @@ void render_table(struct Piece table[3], int active_piece) {
  // similar to board rendering above. We first fill in the shape of the table
  // with symbolic characters, then we write out the ANSI-colored cells one
  // character at a time.
  char out[] = "+--------+--------+--------+\n"
               "|   A:   |   B:   |   C:   |\n"
               "+--------+--------+--------+\n"
               "|        |        |        |\n"
               "|        |        |        |\n"
               "|        |        |        |\n"
               "|        |        |        |\n"
               "+--------+--------+--------+\n";

  const int width = 3 * 8 + 5;
  char out[] = "+----------+----------+----------+\n"
               "|   A:     |   B:     |   C:     |\n"
               "+----------+----------+----------+\n"
               "|. . . . . |. . . . . |. . . . . |\n"
               "|. . . . . |. . . . . |. . . . . |\n"
               "|. . . . . |. . . . . |. . . . . |\n"
               "|. . . . . |. . . . . |. . . . . |\n"
               "|. . . . . |. . . . . |. . . . . |\n"
               "+----------+----------+----------+\n";

  const int width = 3 * 10 + 5;

  const char WHITE = 'W';
  const char GREEN = 'G';


@@ 333,10 335,10 @@ void render_table(struct Piece table[3], int active_piece) {
  render_piece(out, (width * 3) + 1, width, table[0],
               active_lookup[active_piece == 0]);

  render_piece(out, (width * 3) + 10, width, table[1],
  render_piece(out, (width * 3) + 12, width, table[1],
               active_lookup[active_piece == 1]);

  render_piece(out, (width * 3) + 19, width, table[2],
  render_piece(out, (width * 3) + 23, width, table[2],
               active_lookup[active_piece == 2]);

  puts("");


@@ 808,6 810,14 @@ void init_pieces() {
                            "X\n"
                            "X\n");

  PIECES[p++] = piece_parse("XXXXX\n");

  PIECES[p++] = piece_parse("X\n"
                            "X\n"
                            "X\n"
                            "X\n"
                            "X\n");

  PIECES[p++] = piece_parse("X   \n"
                            " X  \n"
                            "  X \n"


@@ 848,6 858,22 @@ void init_pieces() {

  PIECES[p++] = piece_parse("XX\n"
                            "XX\n");

  PIECES[p++] = piece_parse("X X\n"
                            "XXX\n");

  PIECES[p++] = piece_parse("XXX\n"
                            "X X\n");

  PIECES[p++] = piece_parse("XX\n"
                            "X \n"
                            "XX\n");

  PIECES[p++] = piece_parse("XX\n"
                            " X\n"
                            "XX\n");

  assert(p <= NPIECES);
}

// raw mode stuff copied mostly from kilo.c