📄 game_in_minigui.c
字号:
/*
** $Id: russia.c,v 1.10 2003/08/15 08:45:46 weiym Exp $
**
** russia.c: little game russia black
**
** Copyright (C) 2001 ~ 2002 Song Lixin and others.
** Copyright (C) 2003 Feynman Software.
*/
/*
** 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 <stdio.h>
#include <unistd.h>
#include <stdlib.h>
#include <time.h>
#include <string.h>
#include <sys/time.h>
#include <pthread.h>
#include <semaphore.h>
#include <pwd.h>
#include <sys/types.h>
#include <syslog.h>
#include <assert.h>
#include <minigui/common.h>
#include <minigui/minigui.h>
#include <minigui/gdi.h>
#include <minigui/window.h>
#include <minigui/control.h>
#define ETCFILENAME "RussiaSquare.conf"
#define DIFFICULTY_HOP 5000
#define HIGHEST_SCORE 1000000
#define ID_NEWONE 8000
#define ID_NEWTWO 8010
#define ID_NEWTWOTEASE 8011
#define ID_HIGHSCORE 8020
#define ID_EXIT8040
#define ID_KEYSARRANGE 8500
#define ID_BACKGROUND8520
#define ID_ABOUT9010
#define WIDTH_LARGEWIN 380
#define HEIGHT_LARGEWIN 520
#define RUSSIA_SQUARE_TIMER1 600
#define RUSSIA_SQUARE_TIMER2 800
//#define RUSSIA_SQUARE_BASIC_INTERVAL 1100
#define RUSSIA_SQUARE_HEIGHT 22
#define RUSSIA_SQUARE_WIDTH 10
#define RUSSIA_SQUARE_GRID 20
#define ACTION_INIT 0
#define ACTION_PUTIN 1
#define ACTION_LEFT 2
#define ACTION_RIGHT 3
#define ACTION_ROTATE4
#define ACTION_DOWN 5
#define LINE_FULL 0
#define LINE_EMPTY 1
#define LINE_PARTLYFULL 2
#define IDC_STATIC_NUMBER_1 10010
#define IDC_STATIC_NUMBER_2 10020
#define IDC_STATIC_NUMBER_3 10030
#define IDC_STATIC_NUMBER_4 10040
#define IDC_STATIC_NUMBER_5 10050
#define IDC_DIFFICULT_1 10060
#define IDC_DIFFICULT_2 10070
#define IDC_UP_1 10080
#define IDC_UP_2 10090
#define IDC_DOWN_1 10100
#define IDC_DOWN_2 10110
#define IDC_LEFT_1 10120
#define IDC_LEFT_2 10130
#defineIDC_RIGHT_1 10140
#defineIDC_RIGHT_2 10150
#define IDC_ROTATE_1 10160
#define IDC_ROTATE_2 10170
#define IDC_PAUSE_1 10180
#define IDC_PAUSE_2 10190
#define IDC_START_1 10200
#define IDC_START_2 10210
#define IDC_NAMEINPUT 10220
#define SETTING_TABLE_ORIGINX 14
#define SETTING_TABLE_ORIGINY 14
#define SETTING_TABLE_HEIGHT 30
#define SETTING_TABLE_WIDTH1 60
#define SETTING_TABLE_WIDTH2 120
typedef struct {
#define SQUARE_NOTHING 0
#define SQUARE_LONG 1
#define SQUARE_SQUARE 2
#define SQUARE_HILL 3
#define SQUARE_LEFT_DUCK 4
#define SQUARE_RIGHT_DUCK 5
#define SQUARE_LEFT_CHAIR 6
#define SQUARE_RIGHT_CHAIR 7
//All the type is listed here:
// **** ** * ** ** * *
// ** *** ** ** *** ***
int iType;
#define DIR_NONE 0
#define DIR_UP1
#define DIR_DOWN2
#define DIR_LEFT3
#define DIR_RIGHT4
int iDir;
//first,get at a contour of the square,which is a rectangle,
//then we get the cordinate of the point at the left up corner.
POINT poOrigin;
POINT poRightBottom;
POINT poAll[4];
} MovingSquare;
typedef struct {
int iLevel;//rank from 0 to 11
int iScore;// 0--1200000
MovingSquare * pMovingSquare;
MovingSquare *pPreCreatedSquare;
POINT poOrigin;
int iStateMatrix[RUSSIA_SQUARE_HEIGHT][RUSSIA_SQUARE_WIDTH];
BOOL bBegin;
BOOL bDead;
BOOL bPause;
} PlayingWindow;
typedef struct {
int iKeyRotate;
int iKeyDown;
int iKeyLeft;
int iKeyRight;
int iKeyStart;
int iKeyPause;
int iDifficulty;//initial difficulty,rank from 0 to 11;
} KeySetting;
typedef struct{
char strTitleHolder[50];
int iHighScore;
} HighScoreRecord;
typedef struct {
PlayingWindow *pPlayingWindow1;
PlayingWindow *pPlayingWindow2;
KeySetting KeySetting1;
KeySetting KeySetting2;
HighScoreRecord HighScore[5];
char strEtcFilePath[MAX_PATH+1];
char strText[50];
int iTempStateMatrix[RUSSIA_SQUARE_HEIGHT][RUSSIA_SQUARE_WIDTH];
BOOL bTease;
BOOL bBusy;
} RussiaSquare;
RussiaSquare theApp;
static int TimerFreq[12]={5,10,15,20,25,30,35,40,45,50,55,60};
int TestMyWinProc(HWND hWnd,int message,WPARAM wParam,LPARAM lParam);
void InitMyWinCreateInfo(PMAINWINCREATE pCreateInfo);
HMENU createmenu1(void);
HMENU createpmenustart(void);
HMENU createpmenusetting(void);
HMENU createpmenuabout(void);
int LineFullEmpty(int *pLine);
BOOL InitializeApp(void);
void FreePlayingWindow(HWND hWnd);
void OnCommandNewOne(HWND hWnd);
void OnCommandNewTwo(HWND hWnd);
void OnClose(HWND hWnd);
void OnDraw(HWND hWnd,HDC hDC);
void DrawPlayingWindow( HDC hDC,POINT poStart,\
int iSideLength,PlayingWindow * pPlayingWindow);
BOOL OnLeftKeyDown(HWND hWnd,PlayingWindow *pPlayingWindow,int iWhich);
BOOL OnRightKeyDown(HWND hWnd,PlayingWindow *pPlayingWindow,int iWhich);
BOOL OnRotateKeyDown(HWND hWnd,PlayingWindow *pPlayingWindow,int iWhich);
BOOL OnDownKeyDown(HWND hWnd,PlayingWindow *pPlayingWindow,int iWhich);
BOOL OnStartKeyDown(HWND hWnd,PlayingWindow *pPlayingWindow,int iWhich);
BOOL OnPauseKeyDown(HWND hWnd,PlayingWindow *pPlayingWindow,int iWhich);
void OnTimer(HWND hWnd,PlayingWindow *pPlayingWindow,int iWhich);
BOOL MoveSquare(PlayingWindow * pPlayingWindow,int iDir);
BOOL MoveSquareLong(PlayingWindow * pPlayingWindow,int iAction);
BOOL MoveSquareSquare(PlayingWindow * pPlayingWindow,int iAction);
BOOL MoveSquareLeftDuck(PlayingWindow * pPlayingWindow,int iAction);
BOOL MoveSquareRightDuck(PlayingWindow * pPlayingWindow,int iAction);
BOOL MoveSquareHill(PlayingWindow * pPlayingWindow,int iAction);
BOOL MoveSquareLeftChair(PlayingWindow * pPlayingWindow,int iAction);
BOOL MoveSquareRightChair(PlayingWindow * pPlayingWindow,int iAction);
int PutSquare(PlayingWindow *pPlayingWindow);
BOOL WillNotTouch(PlayingWindow *pPlayingWindow);
BOOL WillNotTouchLong(PlayingWindow *pPlayingWindow);
BOOL WillNotTouchSquare(PlayingWindow *pPlayingWindow);
BOOL WillNotTouchLeftDuck(PlayingWindow *pPlayingWindow);
BOOL WillNotTouchRightDuck(PlayingWindow *pPlayingWindow);
BOOL WillNotTouchHill(PlayingWindow *pPlayingWindow);
BOOL WillNotTouchLeftChair(PlayingWindow *pPlayingWindow);
BOOL WillNotTouchRightChair(PlayingWindow *pPlayingWindow);
int RemoveFullLines(PlayingWindow * pPlayingWindow,int iWhich);
void ConvertRectCord(HWND hWnd,int iWhich,RECT * pRect);
void DrawLittleBrick(HDC hDC,POINT poStart,int iSideLength,int iType);
BOOL TestPosition(PlayingWindow *pPlayingWindow ,int i,int j);
BOOL TestPosition1(PlayingWindow *pPlayingWindow ,int i,int j);
void SaveSettingvalue(void);
static int DialogKeySettingProc(HWND hDlg, int message, WPARAM wParam, LPARAM lParam);
static void DialogKeySetting(HWND hWnd);
static int DialogHighScoreProc(HWND hDlg, int message, WPARAM wParam, LPARAM lParam);
static void DialogHighScore(HWND hWnd);
void UpdateHighScore(HWND hWnd,PlayingWindow *pPlayingWindow);
void SaveKeySetting(int wParam,int iCtrlID,KeySetting * tempKeySetting);
BOOL ConvertScanCode(int wParam,char * strText);
BOOL HaveSameKeySetting(KeySetting *pKeySetting);
BOOL IncrementScore(PlayingWindow *pPlayingWindow,int iLines);
BOOL TeaseTheOtherPlayer(int iWhich,int iBegin,int iLines);
DLGTEMPLATE DlgHighScore =
{
WS_BORDER | WS_CAPTION,
WS_EX_NONE,
70, 80, 300, 220,
"英雄榜",
0, 0,
6, NULL,
0
};
CTRLDATA CtrlHighScore [] =
{
{
"static",
WS_VISIBLE | SS_CENTER,
14, 30, 280, 20,
IDC_STATIC_NUMBER_1,
"第一名",
0
},
{
"static",
WS_VISIBLE | SS_CENTER,
14, 55, 280, 20,
IDC_STATIC_NUMBER_2,
"第二名",
0
},
{
"static",
WS_VISIBLE | SS_CENTER,
14, 80, 280, 20,
IDC_STATIC_NUMBER_3,
"第三名",
0
},
{
"static",
WS_VISIBLE | SS_CENTER,
14, 105, 280, 20,
IDC_STATIC_NUMBER_4,
"第四名",
0
},
{
"static",
WS_VISIBLE | SS_CENTER,
14, 130, 280, 20,
IDC_STATIC_NUMBER_5,
"第五名",
0
},
{
"button",
WS_VISIBLE | BS_PUSHBUTTON | BS_DEFPUSHBUTTON | WS_TABSTOP,
100, 155, 100, 28,
IDOK,
"确定",
0
}
};
static void DialogHighScore(HWND hWnd)
{
DlgHighScore.controls = CtrlHighScore;
theApp.bBusy=TRUE;
DialogBoxIndirectParam (&DlgHighScore, hWnd, DialogHighScoreProc, 0L);
theApp.bBusy=FALSE;
}
static int
DialogHighScoreProc(HWND hDlg, int message, WPARAM wParam, LPARAM lParam)
{
char strText[50];
switch (message) {
case MSG_INITDIALOG:
snprintf(strText,50,"第一名:%s 高分:%d",theApp.HighScore[0].strTitleHolder,theApp.HighScore[0].iHighScore);
SetDlgItemText(hDlg,IDC_STATIC_NUMBER_1,strText);
snprintf(strText,50,"第二名:%s 高分:%d",theApp.HighScore[1].strTitleHolder,theApp.HighScore[1].iHighScore);
SetDlgItemText(hDlg,IDC_STATIC_NUMBER_2,strText);
snprintf(strText,50,"第三名:%s 高分:%d",theApp.HighScore[2].strTitleHolder,theApp.HighScore[2].iHighScore);
SetDlgItemText(hDlg,IDC_STATIC_NUMBER_3,strText);
snprintf(strText,50,"第四名:%s 高分:%d",theApp.HighScore[3].strTitleHolder,theApp.HighScore[3].iHighScore);
SetDlgItemText(hDlg,IDC_STATIC_NUMBER_4,strText);
snprintf(strText,50,"第五名:%s 高分:%d",theApp.HighScore[4].strTitleHolder,theApp.HighScore[4].iHighScore);
SetDlgItemText(hDlg,IDC_STATIC_NUMBER_5,strText);
return 1;
case MSG_COMMAND:
switch (wParam) {
case IDOK:
case IDCANCEL:
EndDialog (hDlg, wParam);
break;
}
break;
}
return DefaultDialogProc (hDlg, message, wParam, lParam);
}
DLGTEMPLATE DlgKeySetting =
{
WS_BORDER | WS_CAPTION,
WS_EX_NONE,
70, 80,350 , 360,
"输入",
0, 0,
25, NULL,
0
};
CTRLDATA CtrlKeySetting [] =
{
{
"static",
WS_VISIBLE | SS_CENTER,
SETTING_TABLE_ORIGINX+SETTING_TABLE_WIDTH1,
SETTING_TABLE_ORIGINY,
SETTING_TABLE_WIDTH2,
SETTING_TABLE_HEIGHT,
IDC_STATIC,
"玩家一",
0
},
{
"static",
WS_VISIBLE | SS_CENTER,
SETTING_TABLE_ORIGINX+SETTING_TABLE_WIDTH1+SETTING_TABLE_WIDTH2,
SETTING_TABLE_ORIGINY,
SETTING_TABLE_WIDTH2,
SETTING_TABLE_HEIGHT,
IDC_STATIC,
"玩家二",
0
},
{
"static",
WS_VISIBLE | SS_CENTER,
SETTING_TABLE_ORIGINX,
SETTING_TABLE_ORIGINY+SETTING_TABLE_HEIGHT,
SETTING_TABLE_WIDTH1,
SETTING_TABLE_HEIGHT,
IDC_STATIC,
"难度",
0
},
{
"edit",
WS_VISIBLE | WS_BORDER | WS_TABSTOP,
SETTING_TABLE_ORIGINX+SETTING_TABLE_WIDTH1,
SETTING_TABLE_ORIGINY+SETTING_TABLE_HEIGHT,
SETTING_TABLE_WIDTH2,
SETTING_TABLE_HEIGHT,
IDC_DIFFICULT_1,
NULL,
0
},
{
"edit",
WS_VISIBLE | WS_BORDER | WS_TABSTOP,
SETTING_TABLE_ORIGINX+SETTING_TABLE_WIDTH1+SETTING_TABLE_WIDTH2,
SETTING_TABLE_ORIGINY+SETTING_TABLE_HEIGHT,
SETTING_TABLE_WIDTH2,
SETTING_TABLE_HEIGHT,
IDC_DIFFICULT_2,
NULL,
0
},
{
"static",
WS_VISIBLE | SS_CENTER,
SETTING_TABLE_ORIGINX,
SETTING_TABLE_ORIGINY+SETTING_TABLE_HEIGHT*2,
SETTING_TABLE_WIDTH1,
SETTING_TABLE_HEIGHT,
IDC_STATIC,
"下",
0
},
{
"edit",
WS_VISIBLE | WS_BORDER | WS_TABSTOP,
SETTING_TABLE_ORIGINX+SETTING_TABLE_WIDTH1,
SETTING_TABLE_ORIGINY+SETTING_TABLE_HEIGHT*2,
SETTING_TABLE_WIDTH2,
SETTING_TABLE_HEIGHT,
IDC_DOWN_1,
NULL,
0
},
{
"edit",
WS_VISIBLE | WS_BORDER | WS_TABSTOP,
SETTING_TABLE_ORIGINX+SETTING_TABLE_WIDTH1+SETTING_TABLE_WIDTH2,
SETTING_TABLE_ORIGINY+SETTING_TABLE_HEIGHT*2,
SETTING_TABLE_WIDTH2,
SETTING_TABLE_HEIGHT,
IDC_DOWN_2,
NULL,
0
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -