parent
							
								
									57c481f506
								
							
						
					
					
						commit
						90e50dcc4c
					
				
							
								
								
									
										3
									
								
								README
									
									
									
									
									
								
							
							
						
						
									
										3
									
								
								README
									
									
									
									
									
								
							@ -44,10 +44,11 @@
 | 
				
			|||||||
 | 
					
 | 
				
			||||||
** Usage
 | 
					** Usage
 | 
				
			||||||
   #+BEGIN_SRC text
 | 
					   #+BEGIN_SRC text
 | 
				
			||||||
   usage: ttysolitaire [-v|--version] [-h|--help] [-p|--passes=NUMBER]
 | 
					   usage: ttysolitaire [-v|--version] [-h|--help] [-p|--passes=NUMBER] [-c|--colors]
 | 
				
			||||||
   -v, --version  Show version
 | 
					   -v, --version  Show version
 | 
				
			||||||
   -h, --help     Show this message
 | 
					   -h, --help     Show this message
 | 
				
			||||||
   -p, --passes   Number of passes through the deck
 | 
					   -p, --passes   Number of passes through the deck
 | 
				
			||||||
 | 
					   -c, --colors   Four unique colors, one for each suit
 | 
				
			||||||
   #+END_SRC
 | 
					   #+END_SRC
 | 
				
			||||||
 | 
					
 | 
				
			||||||
** Development
 | 
					** Development
 | 
				
			||||||
 | 
				
			|||||||
@ -174,7 +174,7 @@ static void deal_cards(struct deck *deck) {
 | 
				
			|||||||
  }
 | 
					  }
 | 
				
			||||||
}
 | 
					}
 | 
				
			||||||
 | 
					
 | 
				
			||||||
void game_init(struct game *game, int passes_through_deck) {
 | 
					void game_init(struct game *game, int passes_through_deck, int color_mode) {
 | 
				
			||||||
  cursor_malloc(&cursor);
 | 
					  cursor_malloc(&cursor);
 | 
				
			||||||
  cursor_init(cursor);
 | 
					  cursor_init(cursor);
 | 
				
			||||||
  deck_malloc(&deck);
 | 
					  deck_malloc(&deck);
 | 
				
			||||||
@ -190,6 +190,8 @@ void game_init(struct game *game, int passes_through_deck) {
 | 
				
			|||||||
    frame_set(deck->maneuvre[i]->card->frame, MANEUVRE_BEGIN_Y, maneuvre_begin_x(i));
 | 
					    frame_set(deck->maneuvre[i]->card->frame, MANEUVRE_BEGIN_Y, maneuvre_begin_x(i));
 | 
				
			||||||
  }
 | 
					  }
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					  game->color_mode = color_mode;
 | 
				
			||||||
 | 
					
 | 
				
			||||||
  fill_deck(deck);
 | 
					  fill_deck(deck);
 | 
				
			||||||
  shuffle_deck(deck);
 | 
					  shuffle_deck(deck);
 | 
				
			||||||
  deal_cards(deck);
 | 
					  deal_cards(deck);
 | 
				
			||||||
 | 
				
			|||||||
@ -32,6 +32,7 @@
 | 
				
			|||||||
 | 
					
 | 
				
			||||||
struct game {
 | 
					struct game {
 | 
				
			||||||
  int passes_through_deck_left;
 | 
					  int passes_through_deck_left;
 | 
				
			||||||
 | 
					  int color_mode;
 | 
				
			||||||
};
 | 
					};
 | 
				
			||||||
 | 
					
 | 
				
			||||||
struct deck *deck;
 | 
					struct deck *deck;
 | 
				
			||||||
@ -42,7 +43,7 @@ bool stock_stack(struct stack *);
 | 
				
			|||||||
bool valid_move(struct stack *, struct stack *);
 | 
					bool valid_move(struct stack *, struct stack *);
 | 
				
			||||||
void move_card(struct stack **, struct stack **);
 | 
					void move_card(struct stack **, struct stack **);
 | 
				
			||||||
void move_block(struct stack **, struct stack **, int);
 | 
					void move_block(struct stack **, struct stack **, int);
 | 
				
			||||||
void game_init(struct game *, int);
 | 
					void game_init(struct game *, int, int);
 | 
				
			||||||
bool game_won();
 | 
					bool game_won();
 | 
				
			||||||
void game_end();
 | 
					void game_end();
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
				
			|||||||
							
								
								
									
										25
									
								
								src/gui.c
									
									
									
									
									
								
							
							
						
						
									
										25
									
								
								src/gui.c
									
									
									
									
									
								
							@ -6,6 +6,7 @@
 | 
				
			|||||||
#include "gui.h"
 | 
					#include "gui.h"
 | 
				
			||||||
#include "deck.h"
 | 
					#include "deck.h"
 | 
				
			||||||
#include "game.h"
 | 
					#include "game.h"
 | 
				
			||||||
 | 
					#include "card.h"
 | 
				
			||||||
 | 
					
 | 
				
			||||||
static const char *card_suits[4] = { "\u2666", "\u2660", "\u2665", "\u2663" };
 | 
					static const char *card_suits[4] = { "\u2666", "\u2660", "\u2665", "\u2663" };
 | 
				
			||||||
static const char *card_values[13] = {
 | 
					static const char *card_values[13] = {
 | 
				
			||||||
@ -21,10 +22,28 @@ static void draw_value(struct card *card) {
 | 
				
			|||||||
}
 | 
					}
 | 
				
			||||||
 | 
					
 | 
				
			||||||
static void draw_suit(struct card *card) {
 | 
					static void draw_suit(struct card *card) {
 | 
				
			||||||
  if (card->suit % 2 == 0) {
 | 
					  if (game.color_mode == 0) {
 | 
				
			||||||
    wattron(card->frame->window, COLOR_PAIR(RED_ON_WHITE));
 | 
					    if (card->suit % 2 == 0) {
 | 
				
			||||||
 | 
					      wattron(card->frame->window, COLOR_PAIR(RED_ON_WHITE));
 | 
				
			||||||
 | 
					    } else {
 | 
				
			||||||
 | 
					      wattron(card->frame->window, COLOR_PAIR(BLACK_ON_WHITE));
 | 
				
			||||||
 | 
					    }
 | 
				
			||||||
  } else {
 | 
					  } else {
 | 
				
			||||||
    wattron(card->frame->window, COLOR_PAIR(BLACK_ON_WHITE));
 | 
					    switch (card->suit) {
 | 
				
			||||||
 | 
					      case SPADES:
 | 
				
			||||||
 | 
					        wattron(card->frame->window, COLOR_PAIR(GREEN_ON_WHITE));
 | 
				
			||||||
 | 
					        break;
 | 
				
			||||||
 | 
					      case DIAMONDS:
 | 
				
			||||||
 | 
					        wattron(card->frame->window, COLOR_PAIR(YELLOW_ON_WHITE));
 | 
				
			||||||
 | 
					        break;
 | 
				
			||||||
 | 
					      case CLUBS:
 | 
				
			||||||
 | 
					        wattron(card->frame->window, COLOR_PAIR(BLACK_ON_WHITE));
 | 
				
			||||||
 | 
					        break;
 | 
				
			||||||
 | 
					      case HEARTS:
 | 
				
			||||||
 | 
					      default:
 | 
				
			||||||
 | 
					        wattron(card->frame->window, COLOR_PAIR(RED_ON_WHITE));
 | 
				
			||||||
 | 
					        break;
 | 
				
			||||||
 | 
					    }
 | 
				
			||||||
  }
 | 
					  }
 | 
				
			||||||
  mvwprintw(card->frame->window,
 | 
					  mvwprintw(card->frame->window,
 | 
				
			||||||
            0,
 | 
					            0,
 | 
				
			||||||
 | 
				
			|||||||
							
								
								
									
										10
									
								
								src/gui.h
									
									
									
									
									
								
							
							
						
						
									
										10
									
								
								src/gui.h
									
									
									
									
									
								
							@ -6,10 +6,12 @@
 | 
				
			|||||||
#include "deck.h"
 | 
					#include "deck.h"
 | 
				
			||||||
#include "cursor.h"
 | 
					#include "cursor.h"
 | 
				
			||||||
 | 
					
 | 
				
			||||||
#define BLACK_ON_WHITE 1
 | 
					#define BLACK_ON_WHITE  1
 | 
				
			||||||
#define RED_ON_WHITE   2
 | 
					#define RED_ON_WHITE    2
 | 
				
			||||||
#define WHITE_ON_BLUE  3
 | 
					#define GREEN_ON_WHITE  3
 | 
				
			||||||
#define WHITE_ON_GREEN 4
 | 
					#define YELLOW_ON_WHITE 4
 | 
				
			||||||
 | 
					#define WHITE_ON_BLUE   5
 | 
				
			||||||
 | 
					#define WHITE_ON_GREEN  6
 | 
				
			||||||
 | 
					
 | 
				
			||||||
extern struct game game;
 | 
					extern struct game game;
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
				
			|||||||
@ -23,9 +23,11 @@ int main(int argc, char *argv[]) {
 | 
				
			|||||||
  int option;
 | 
					  int option;
 | 
				
			||||||
  int option_index;
 | 
					  int option_index;
 | 
				
			||||||
  int passes_through_deck = 3;
 | 
					  int passes_through_deck = 3;
 | 
				
			||||||
 | 
					  int color_mode = 0;
 | 
				
			||||||
  static const struct option options[] = {
 | 
					  static const struct option options[] = {
 | 
				
			||||||
    {"help",    no_argument,       NULL, 'h'},
 | 
					    {"help",    no_argument,       NULL, 'h'},
 | 
				
			||||||
    {"version", no_argument,       NULL, 'v'},
 | 
					    {"version", no_argument,       NULL, 'v'},
 | 
				
			||||||
 | 
					    {"colors", no_argument,        NULL, 'c'},
 | 
				
			||||||
    {"passes",  required_argument, NULL, 'p'},
 | 
					    {"passes",  required_argument, NULL, 'p'},
 | 
				
			||||||
    {0, 0, 0, 0}
 | 
					    {0, 0, 0, 0}
 | 
				
			||||||
  };
 | 
					  };
 | 
				
			||||||
@ -40,6 +42,9 @@ int main(int argc, char *argv[]) {
 | 
				
			|||||||
    case 'p':
 | 
					    case 'p':
 | 
				
			||||||
      passes_through_deck = atoi(optarg);
 | 
					      passes_through_deck = atoi(optarg);
 | 
				
			||||||
      break;
 | 
					      break;
 | 
				
			||||||
 | 
					    case 'c':
 | 
				
			||||||
 | 
					      color_mode = 1;
 | 
				
			||||||
 | 
					      break;
 | 
				
			||||||
    case 'h':
 | 
					    case 'h':
 | 
				
			||||||
    default:
 | 
					    default:
 | 
				
			||||||
      usage(program_name);
 | 
					      usage(program_name);
 | 
				
			||||||
@ -58,8 +63,10 @@ int main(int argc, char *argv[]) {
 | 
				
			|||||||
  assume_default_colors(COLOR_WHITE, COLOR_GREEN);
 | 
					  assume_default_colors(COLOR_WHITE, COLOR_GREEN);
 | 
				
			||||||
  init_pair(1, COLOR_BLACK, COLOR_WHITE);
 | 
					  init_pair(1, COLOR_BLACK, COLOR_WHITE);
 | 
				
			||||||
  init_pair(2, COLOR_RED, COLOR_WHITE);
 | 
					  init_pair(2, COLOR_RED, COLOR_WHITE);
 | 
				
			||||||
  init_pair(3, COLOR_WHITE, COLOR_BLUE);
 | 
					  init_pair(3, COLOR_GREEN, COLOR_WHITE);
 | 
				
			||||||
  init_pair(4, COLOR_WHITE, COLOR_GREEN);
 | 
					  init_pair(4, COLOR_YELLOW, COLOR_WHITE);
 | 
				
			||||||
 | 
					  init_pair(5, COLOR_WHITE, COLOR_BLUE);
 | 
				
			||||||
 | 
					  init_pair(6, COLOR_WHITE, COLOR_GREEN);
 | 
				
			||||||
 | 
					
 | 
				
			||||||
  int key;
 | 
					  int key;
 | 
				
			||||||
 | 
					
 | 
				
			||||||
@ -89,7 +96,7 @@ int main(int argc, char *argv[]) {
 | 
				
			|||||||
      if (key == KEY_SPACEBAR) {
 | 
					      if (key == KEY_SPACEBAR) {
 | 
				
			||||||
        clear();
 | 
					        clear();
 | 
				
			||||||
        refresh();
 | 
					        refresh();
 | 
				
			||||||
        game_init(&game, passes_through_deck);
 | 
					        game_init(&game, passes_through_deck, color_mode);
 | 
				
			||||||
        break;
 | 
					        break;
 | 
				
			||||||
      }
 | 
					      }
 | 
				
			||||||
    } else if (key == KEY_RESIZE) {
 | 
					    } else if (key == KEY_RESIZE) {
 | 
				
			||||||
@ -120,10 +127,11 @@ void draw_greeting() {
 | 
				
			|||||||
}
 | 
					}
 | 
				
			||||||
 | 
					
 | 
				
			||||||
void usage(const char *program_name) {
 | 
					void usage(const char *program_name) {
 | 
				
			||||||
  printf("usage: %s [-v|--version] [-h|--help] [-p|--passes=NUMBER]\n", program_name);
 | 
					  printf("usage: %s [-v|--version] [-h|--help] [-p|--passes=NUMBER] [-c|--colors]\n", program_name);
 | 
				
			||||||
  printf("  -v, --version  Show version\n");
 | 
					  printf("  -v, --version  Show version\n");
 | 
				
			||||||
  printf("  -h, --help     Show this message\n");
 | 
					  printf("  -h, --help     Show this message\n");
 | 
				
			||||||
  printf("  -p, --passes   Number of passes through the deck\n");
 | 
					  printf("  -p, --passes   Number of passes through the deck\n");
 | 
				
			||||||
 | 
					  printf("  -c, --colors   Four unique colors, one for each suit\n");
 | 
				
			||||||
}
 | 
					}
 | 
				
			||||||
 | 
					
 | 
				
			||||||
void version() {
 | 
					void version() {
 | 
				
			||||||
 | 
				
			|||||||
		Loading…
	
	
			
			x
			
			
		
	
		Reference in New Issue
	
	Block a user