From 37b4a8a477a4315580d836d8284b01ef1c2ff043 Mon Sep 17 00:00:00 2001 From: Howard T Date: Wed, 26 Apr 2017 21:50:09 +0100 Subject: [PATCH] First Commit - Add the main file, cardHolder class, Card class, and the card images file --- Cards.m | 27 ++++ cardHolder.m | 296 ++++++++++++++++++++++++++++++++++++++++++++ card_images.mat | Bin 0 -> 58700 bytes sulitear.m | 318 ++++++++++++++++++++++++++++++++++++++++++++++++ 4 files changed, 641 insertions(+) create mode 100644 Cards.m create mode 100644 cardHolder.m create mode 100644 card_images.mat create mode 100644 sulitear.m diff --git a/Cards.m b/Cards.m new file mode 100644 index 0000000..0b6f8c7 --- /dev/null +++ b/Cards.m @@ -0,0 +1,27 @@ +classdef Cards + properties(SetAccess = private) + value + image_data + backimage_data + end + methods + function crd = Cards(value,image_data,backimage_data) + crd.value = value; + crd.image_data = image_data; + crd.backimage_data = backimage_data; + end + function [num,colour,suit] = get_Card_Info(crd) + num = mod(crd.value,100); + suit = floor(crd.value/100); + colour = mod(suit,2); + end + function img_data = get_Card_Image(crd,side) + if strcmp(side,'back') + img_data = crd.backimage_data; + else + img_data = crd.image_data; + end + img_data = (double(flipud(img_data)))/255; + end + end +end \ No newline at end of file diff --git a/cardHolder.m b/cardHolder.m new file mode 100644 index 0000000..2491e97 --- /dev/null +++ b/cardHolder.m @@ -0,0 +1,296 @@ +classdef cardHolder < handle + %% Deck Properties + properties (SetAccess = private) + %Deck position + x % x position of the top left of the holder + y % y position of the top left of the holder + % Card dimension and offset + card_width + card_height + offset % The offset between display each card in a deck + cards % The cards is currently holding + % Card deck orientation and dimensions + deck_orientation % Either display horizontal or vertical + start_display_index % Display only a number of cards in a deck, -1 for display all + current_display_index % Current number of cards to be displayed + % Overall deck dimension, used for collision purposes + deck_width + deck_height + % Deck properties + always_hidden % Never open the hidden cards + receivable + % Deck graphics handle, used for updating the deck's graphics + card_graphics_data = {} + card_draw_handle = [] + card_text = [] + end + properties (SetAccess = public) + selected_start_index % The card index which is selected + hidden_start_index % The number of cards that is hidden + end + methods + %% Constructor + function cH = cardHolder(x,y,cards,card_width,card_height,offset,deck_orientation,start_display_index,hidden_cards,always_hidden,receivable) + cH.x = x; + cH.y = y; + + cH.deck_orientation = deck_orientation; + if start_display_index<1 + start_display_index = -1; + end + cH.start_display_index = start_display_index; + cH.current_display_index = start_display_index; + + cH.cards = cards; + cH.card_width = card_width; + cH.card_height = card_height; + cH.offset = offset; + + cH.receivable = receivable ; + cH.always_hidden = always_hidden; + hidden_cards = min(hidden_cards,length(cards)); + cH.hidden_start_index = hidden_cards; + + cH.selected_start_index = 0; + cH.update_deck_dimensions() + end + %% Deck Get Functions + % Get the number of cards in the deck + function n_of_cards = get_Number_Of_Cards(cH) + n_of_cards = length(cH.cards); + end + function receive = is_Receivable(cH) + receive = cH.receivable; + end + % Get the card at the bottom of the selected cards + function card = get_bottom_selected(cH) + card = cH.cards(end-cH.selected_start_index+1); + end + + % Get the last card, which is top of the deck + function lastcard = get_Last_Cards(cH) + % If empty, return 0 + if cH.is_Empty() + lastcard = 0; + return + end + + if (cH.get_Number_Of_Cards()-cH.hidden_start_index)>0 + lastcard = cH.cards(end); % Return the card number if not hidden + else + lastcard = -1; % If hidden, return -1; + end + end + %% Deck Check Functions + %Check if the deck is empty + function empty = is_Empty(cH) + empty = (cH.get_Number_Of_Cards() == 0); + end + + %Check if there is a collision with a deck + function collide = check_Deck_Collision(cH,x,y,type) + + if strcmp(type,'full') %Check for entire deck collision + xrange = [cH.x cH.x+cH.deck_width]; + yrange = [cH.y-cH.deck_height cH.y]; + elseif strcmp(type,'first') %Check for only first card collision + xoffset = cH.deck_width - cH.card_width; + yoffset = cH.deck_height - cH.card_height; + xrange = [cH.x+xoffset cH.x+cH.deck_width]; + yrange = [cH.y-cH.deck_height cH.y-yoffset]; + end + + collide = (x>xrange(1) && xyrange(1) && y