📄 cards.c
字号:
/******************************************************************
* SEAL 2.0 *
* Copyright (c) 1999-2002 SEAL Developers. All Rights Reserved. *
* *
* Web site: http://sealsystem.sourceforge.net/ *
* E-mail (current maintainer): orudge@users.sourceforge.net *
******************************************************************/
/*
This program is free software; you can redistribute it and/or modify
it under the terms of the GNU General Public License as published by
the Free Software Foundation; either version 2 of the License, or
(at your option) any later version.
This program is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
GNU General Public License for more details.
You should have received a copy of the GNU General Public License
along with this program; if not, write to the Free Software
Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
*/
/****************************************************************/
/* */
/* cards.c */
/* */
/* For creating card games for Seal 2 */
/* */
/* Copyright (c) 2001,2002 */
/* Tobias Johansson */
/* All Rights Reserved */
/* */
/* mail: tobbe_snodd@hotmail.com */
/* web: http://www.seal.private.as */
/* */
/* Cards is free software; you can redistribute it and/or */
/* modify it under the terms of the GNU General Public License */
/* as published by the Free Software Foundation; either version */
/* 2, or (at your option) any later version. */
/* */
/* Cards is distributed in the hope that it will be useful, but */
/* WITHOUT ANY WARRANTY; without even the implied warranty of */
/* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See */
/* the GNU General Public License for more details. */
/* */
/* You should have received a copy of the GNU General Public */
/* License along with cards; see the file COPYING. If not, */
/* write to the Free Software Foundation, 675 Mass Ave, */
/* Cambridge, MA 02139, USA. */
/* */
/****************************************************************/
/* Revision History (as of 02/04/2002):
*
* 02/04/2002: Appended CARDS.DAT to XDL instead of having seperate file (orudge)
* 04/04/2002: Fixed visual glitch with skins in About box (orudge)
*/
#define CARDS_INT_VERSION "1.1"
#include "allegro.h"
#include "seal.h"
#include "app.h"
#include "button.h"
#include "view.h"
#include "registry.h"
#include "dos.h"
#include "cards.h"
p_view vDecks;
l_int selDeck = C_BACK0;
t_rect selDeckCoords[10] = {{7, 22, 12+CARD_WIDTH, 27+CARD_HEIGHT},
{87, 22, 92+CARD_WIDTH, 27+CARD_HEIGHT},
{167, 22, 172+CARD_WIDTH, 27+CARD_HEIGHT},
{247, 22, 252+CARD_WIDTH, 27+CARD_HEIGHT},
{327, 22, 332+CARD_WIDTH, 27+CARD_HEIGHT},
{7, 127, 12+CARD_WIDTH, 132+CARD_HEIGHT},
{87, 127, 92+CARD_WIDTH, 132+CARD_HEIGHT},
{167, 127, 172+CARD_WIDTH, 132+CARD_HEIGHT},
{247, 127, 252+CARD_WIDTH, 132+CARD_HEIGHT},
{327, 127, 332+CARD_WIDTH, 132+CARD_HEIGHT}};
static DATAFILE *datFile = NULL;
static BITMAP *invBuf = NULL;
SetInfoAppName("Card drawing library v1.1");
SetInfoDesciption("Card drawing library for Seal 2");
SetInfoCopyright("(c) 2001-2002 Tobias Johansson");
SetInfoManufacturer("Tobias Johansson");
l_int get_selDeck_from_reg(void) {
if (!key_exists("software/cards")) create_key("software", "cards");
if (key_exists(key_in_path("software/cards", "deck"))) {
selDeck = get_key_integer(key_in_path("software/cards", "deck"));
} else {
create_key("software/cards", "deck");
set_key_integer(key_in_path("software/cards", "deck"), C_BACK0);
};
};
static l_int load_datFile(void) {
// Loads the card graphics in dat-file GFXFILE.
if (!datFile) {
datFile = conv_to_skipcolor_data(DLXGetFileData(ap_id), CO_SKIP_RED, CO_SKIP_GREEN, CO_SKIP_BLUE);
// datFile = load_datafile(GFXFILE);
invBuf = create_bitmap(CARD_WIDTH, CARD_HEIGHT);
return 1;
};
return 0;
};
l_text cards_get_version(void) {
return CARDS_INT_VERSION;
};
l_int cards_init_deck(t_card deck[]) {
l_int c;
// Load the card graphics if not already loaded.
load_datFile();
// Fills up the deck array with the cards (1-52)
for (c=1 ; c<53 ; c++) {
deck[c].card = c;
deck[c].showFace = 0;
deck[c].selected = 0;
};
return 1;
};
l_int cards_uninit_deck(void) {
//Unloads card graphics if they aren't already
if (datFile) {
// unload_datafile(datFile);
datFile = NULL;
if (!datFile) return 1;
};
return 0;
};
void cards_shuffle_deck(t_card deck[]) {
// Loop through the array and exchange every
// card with another random card in the deck.
l_int c, xcrd;
t_card tcrd;
srand(time(0)); // Randomize using current time as seed.
for (c=1 ; c<53 ; c++) {
xcrd = (rand() % 51) + 1;
tcrd = deck[c];
deck[c] = deck[xcrd];
deck[xcrd] = tcrd;
};
};
l_int cards_shuffle_deck_ex(t_card deck[]) {
// Same as "cards_shuffle_deck" but returns
// the number of the game (the seed).
l_int c, xcrd, selGame;
t_card tcrd;
srand(time(0)); // Randomize using current time as seed
selGame = rand() % 32000; // Select a game between 0 and 32000
srand(selGame); // Randomize using the selected game
for (c=1 ; c<53 ; c++) {
xcrd = (rand() % 51) + 1;
tcrd = deck[c];
deck[c] = deck[xcrd];
deck[xcrd] = tcrd;
};
return selGame;
};
void cards_shuffle_deck_select(t_card deck[], l_int selGame) {
// Loop through the array and exchange every
// card with another random card in the deck.
// Uses selGame as seed when randomizing.
l_int c, xcrd;
t_card tcrd;
srand(selGame); // Randomize using the selected game
for (c=1 ; c<53 ; c++) {
xcrd = (rand() % 51) + 1;
tcrd = deck[c];
deck[c] = deck[xcrd];
deck[xcrd] = tcrd;
};
};
l_int cards_game_select(l_int curGame) {
// Lets the user select the seed.
l_int selGame = -1;
l_text retVal;
retVal = (l_text) inputbox("Select a game", "Enter the number of the game to play (1-32000):", set_format_text(NULL,"%d", curGame));
if (retVal==NULL) return NULL; // Cancel was clicked.
selGame = atoi(retVal);
if (selGame<1 || selGame>32000) {
// Not a valid game (1-32000)
msgbox(MW_INFO, MB_OK, "Not a valid game!\n\nYour selection must be between 1 and 32000.");
return NULL;
};
// msgbox(MW_INFO, MB_OK, "%d", selGame);
return selGame;
};
l_int cards_get_suite(t_card card) {
if (card.card) return (int) (card.card - 1) / 13;
else return 0;
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -