?? same.c
字號:
/*** $Id: same.c,v 1.7 2006-03-02 05:28:28 xgwang Exp $**** Same: the Same game.** (C) 1997 the Free Software Foundation**** Author: Miguel de Icaza.** Federico Mena.** Horacio Pe?a.**** The idea is originally from KDE's same game program.**** Ported to MiniGUI by Wei Yongming***//*** This source 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 software 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 library; if not, write to the Free** Software Foundation, Inc., 59 Temple Place - Suite 330, Boston,** MA 02111-1307, USA*/#include <sys/types.h>#include <string.h>#include <stdlib.h>#include <time.h>#include <dirent.h>#include <minigui/common.h>#include <minigui/minigui.h>#include <minigui/gdi.h>#include <minigui/window.h>#include <minigui/control.h>#define IDM_NEW 100#define IDM_SCORES 110#define IDM_EXIT 120#define IDM_PREF 200#define IDM_ABOUT 300#define STONE_SIZE 40#define STONE_COLS 15#define STONE_LINES 10#define ID_TIMER 100#define _(x) (x)static RECT rcBoard;static HWND hwnd_score = HWND_INVALID, hwnd_menu;static BITMAP stones;static int tagged_count = 0;static int ball_timeout_id = -1;static int old_x = -1, old_y = -1;static int score;static const char* lang= "en";static const char**pmain_menu =NULL;static const char**pgame_menu =NULL;static const char**pabout_menu =NULL;static const char**pmessagebox =NULL;static const char**phelpmessage = NULL;static const char* messagebox_cn[] ={ "你確定要退出嗎?", "同色球", "得分:%.5d", "游戲結束!\n你的分數(shù)是:%.5d", "同色球游戲", "場景", "分數(shù)", "同色球--1.0\n\nCopyright (C) 2003 ~ 2008 北京飛漫軟件技術有限公司\n\n 保留所有權利"};static const char* messagebox_tw[] ={ "你確定要退出嗎?", "同色球", "得分:%.5d", "游戲結束!\n你的分數(shù)是:%.5d", "同色球游戲", "場景", "分數(shù)", "同色球--1.0\n\nCopyright (C) 2003 ~ 2008 北京飛漫軟件技術有限公司\n\n 保留所有權利"};static const char* messagebox_en[] ={ "Are you sure to quit?", "Same", "Score: %.5d", //2 "End of Game! \nYour Score: %.5d", //3 "The Same Game", //4 "Scenario: ", //5 "Score:", //6 "Same -- Version 1.0\n\nCopyright (C) 2003 ~ 2008 Beijing Feynman Software Technology Co., Ltd.\nAll rights reserved." //7};static const char* about_menu_cn[] ={ "關于", "關于同色球游戲"};static const char* about_menu_tw[] ={ "關於", "關於同色球游戲"};static const char* about_menu_en[] ={ "About", "About same game"};static const char* game_menu_cn[] ={ "游戲", "新游戲", "退出"};static const char* game_menu_tw[] ={ "游戲", "新游戲", "退出"};static const char* game_menu_en[] ={ "Game", "New game", "Exit"};static const char* main_menu_cn[] ={ "游戲", "關于"};static const char* main_menu_tw[] ={ "游戲", "關於"};static const char* main_menu_en[] ={ "Game", "About"};static const char* main_help_cn[] ={" 同色球 -- 1.0 \n\n Copyright (C) 2003 ~ 2008 北京飛漫軟件技術有限公司\n\n 保留所有權利."};static const char* main_help_tw[] ={" 同色球 -- 1.0 \n\n Copyright (C) 2003 ~ 2008 北京飛漫軟件技術有限公司\n\n 保留所有權利."};static const char* main_help_en[] ={" Same -- Version 1.0 \n\n Copyright (C) 2003 ~ 2008 Beijing Feynman Software Technology Co., Ltd.\nAll rights reserved."};static int cur_sel_scen = 0;static PLOGFONT cap_font = NULL;static PLOGFONT ctrl_font = NULL;static PLOGFONT menu_font = NULL;static PLOGFONT utf8_font = NULL;static void init_same(){ cap_font = g_SysLogFont[SYSLOGFONT_CAPTION]; ctrl_font = g_SysLogFont[SYSLOGFONT_CONTROL]; menu_font = g_SysLogFont[SYSLOGFONT_MENU]; utf8_font = CreateLogFontByName("*-Arial-rrncnn-*-12-UTF-8"); g_SysLogFont[SYSLOGFONT_CAPTION] = utf8_font; g_SysLogFont[SYSLOGFONT_CONTROL] = utf8_font; g_SysLogFont[SYSLOGFONT_MENU] = utf8_font; if(strcasecmp(lang,"zh_cn")==0){ local_SysText = GetSysTextInUTF8("zh_CN"); } else if(strcasecmp(lang,"zh_tw")==0){ local_SysText = GetSysTextInUTF8("zh_TW"); } else local_SysText = GetSysTextInUTF8("EN");}static void release_same(){ g_SysLogFont[SYSLOGFONT_CAPTION] = cap_font; g_SysLogFont[SYSLOGFONT_CONTROL] = ctrl_font; g_SysLogFont[SYSLOGFONT_MENU] = menu_font; DestroyLogFont(utf8_font);}static struct ball { int color; int tag; int frame;} field [STONE_COLS][STONE_LINES];static int nstones;static int ncolors;static int sync_stones = 0;#define mapx(x) (x)#define mapy(y) (STONE_LINES-1-(y))static voiddraw_ball (HDC hdc, int x, int y){ int bx, by; if (field [x][y].color){ by = STONE_SIZE * (field [x][y].color - 1); bx = STONE_SIZE * (field [x][y].frame); FillBoxWithBitmapPart (hdc, x * STONE_SIZE, y * STONE_SIZE, STONE_SIZE, STONE_SIZE, 0, 0, &stones, bx, by); } else { SetBrushColor (hdc, PIXEL_black); FillBox (hdc, x * STONE_SIZE, y * STONE_SIZE, STONE_SIZE, STONE_SIZE); }}static void paint (HWND hwnd, HDC hdc){ RECT rc; int x1, y1, x2, y2, x, y; GetClientRect (hdc, &rc); x1 = rc.left / STONE_SIZE; y1 = rc.top / STONE_SIZE; x2 = rc.right / STONE_SIZE; y2 = rc.bottom / STONE_SIZE; for (x = 0; x < STONE_COLS; x++){ for (y = 0; y < STONE_LINES; y++){ draw_ball (hdc, x, y); } }}static void untag_all (HWND hwnd){ int x, y; HDC hdc = GetClientDC (hwnd); for (x = 0; x < STONE_COLS; x++) for (y = 0; y < STONE_LINES; y++){ field [x][y].tag = 0; if (sync_stones && field [x][y].frame != 0) { field [x][y].frame = 0; draw_ball (hdc, x, y); } } ReleaseDC (hdc);}static int flood_fill (int x, int y, int color){ int c = 0; if (field [x][y].color != color) return c; if (field [x][y].tag) return c; c = 1; field [x][y].tag = 1; if (x+1 < STONE_COLS) c += flood_fill (x+1, y, color); if (x) c += flood_fill (x-1, y, color); if (y+1 < STONE_LINES) c += flood_fill (x, y+1, color); if (y) c += flood_fill (x, y-1, color); return c;}static int move_tagged_balls (HDC hdc){ int x, y; for (x = 0; x < STONE_COLS; x++) for (y = 0; y < STONE_LINES; y++){ if (!field [x][y].tag) continue; field [x][y].frame = (field [x][y].frame + 1) % nstones; draw_ball (hdc, x, y); } return 1;}static void disable_timeout (HWND hwnd){ if (ball_timeout_id != -1){ KillTimer (hwnd, ball_timeout_id); ball_timeout_id = -1; }}static void mark_balls (HWND hwnd, int x, int y){ if (x == old_x && y == old_y) return; old_x = x; old_y = y; untag_all (hwnd); disable_timeout (hwnd); if (!field [x][y].color) return; tagged_count = flood_fill (x, y, field [x][y].color); if (tagged_count > 1) { SetTimer (hwnd, ID_TIMER, 10); ball_timeout_id = ID_TIMER; }}static void unmark_balls (HWND hWnd){ old_x = -1; old_y = -1; disable_timeout (hWnd); untag_all (hWnd);}static void compress_column (int x){ int y, ym; for (y = STONE_LINES - 1; y >= 0; y--){ if (!field [mapx(x)][mapy(y)].tag) continue; for (ym = y; ym < STONE_LINES - 1; ym++) field [mapx(x)][mapy(ym)] = field [mapx(x)][mapy(ym+1)]; field [mapx(x)][mapy(ym)].color = 0; field [mapx(x)][mapy(ym)].tag = 0; }}static void compress_y (void){ int x; for (x = 0; x < STONE_COLS; x++) compress_column (x);}static void copy_col (int dest, int src){ int y; for (y = 0; y < STONE_LINES; y++) field [mapx(dest)][mapy(y)] = field [mapx(src)][mapy(y)];}static void clean_last_col (void){ int y; for (y = 0; y < STONE_LINES; y++){ field [mapx(STONE_COLS-1)][mapy(y)].color = 0; field [mapx(STONE_COLS-1)][mapy(y)].tag = 0; }}static void compress_x (void){ int x, xm, l; for (x = 0; x < STONE_COLS; x++){ for (l = STONE_COLS; field [mapx(x)][mapy(0)].color == 0 && l; l--){ for (xm = x; xm < STONE_COLS-1; xm++) copy_col (xm, xm+1); clean_last_col (); } }}static void set_score (int new_score){ char b [40]; score = new_score; sprintf (b, pmessagebox[2], score); if (hwnd_score != HWND_INVALID) SetWindowText (hwnd_score, b);}static void end_of_game (HWND hWnd, char *title){ char b [256]; sprintf (b, pmessagebox[3], score); MessageBox (hWnd, b, title, MB_OK | MB_ICONINFORMATION | MB_BASEDONPARENT);}static void check_game_over (HWND hwnd){ int cleared=1; int x,y; for(x = 0; x < STONE_COLS; x++) for(y = 0 ; y < STONE_LINES; y++) { if (!field [x][y].color) continue; cleared = 0; if(x+1 < STONE_COLS) if(field[x][y].color == field[x+1][y].color) return; if(y+1 < STONE_LINES) if(field[x][y].color == field[x][y+1].color) return; } if (cleared){ set_score (score+1000); end_of_game (hwnd, _(pmessagebox[4])); } else end_of_game(hwnd, _(pmessagebox[4]));}static void kill_balls (HWND hwnd, int x, int y){ if (!field [x][y].color) return; if (tagged_count < 2) return; set_score (score + (tagged_count - 2) * (tagged_count - 2)); compress_y (); compress_x (); InvalidateRect (hwnd, &rcBoard, FALSE); check_game_over (hwnd);}
?? 快捷鍵說明
復制代碼
Ctrl + C
搜索代碼
Ctrl + F
全屏模式
F11
切換主題
Ctrl + Shift + D
顯示快捷鍵
?
增大字號
Ctrl + =
減小字號
Ctrl + -