forked from chrisguo/beijing_fushengji
-
Notifications
You must be signed in to change notification settings - Fork 3
/
SelectionDlg.cpp
executable file
·2360 lines (2078 loc) · 66.8 KB
/
SelectionDlg.cpp
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
750
751
752
753
754
755
756
757
758
759
760
761
762
763
764
765
766
767
768
769
770
771
772
773
774
775
776
777
778
779
780
781
782
783
784
785
786
787
788
789
790
791
792
793
794
795
796
797
798
799
800
801
802
803
804
805
806
807
808
809
810
811
812
813
814
815
816
817
818
819
820
821
822
823
824
825
826
827
828
829
830
831
832
833
834
835
836
837
838
839
840
841
842
843
844
845
846
847
848
849
850
851
852
853
854
855
856
857
858
859
860
861
862
863
864
865
866
867
868
869
870
871
872
873
874
875
876
877
878
879
880
881
882
883
884
885
886
887
888
889
890
891
892
893
894
895
896
897
898
899
900
901
902
903
904
905
906
907
908
909
910
911
912
913
914
915
916
917
918
919
920
921
922
923
924
925
926
927
928
929
930
931
932
933
934
935
936
937
938
939
940
941
942
943
944
945
946
947
948
949
950
951
952
953
954
955
956
957
958
959
960
961
962
963
964
965
966
967
968
969
970
971
972
973
974
975
976
977
978
979
980
981
982
983
984
985
986
987
988
989
990
991
992
993
994
995
996
997
998
999
1000
//****************************************************************//
//* This is the BeijingHell Main user interface system and *//
//* events handling system. *//
//* *//
//* Author : Guo xianghao *//
//* Date : 2000-2001 *//
//* E-mail : [email protected] *//
//* All rights reserved. *//
// Guoly computing company. //
//****************************************************************//
/*
History:
version 1.2.2 for Windows XP:
real-time news causes game can not run under XP.
disable it using define
version 1.1.0 2001/2/25
fix another bug regarding to price.
some new features added, including: hacking, house agency, network club,
"boss coming " protect etc.
version 1.0.3 2001/1/9
fix the bug.
put on www.csdn.net, and game.sina.com.cn provides free download, more than
21500 downlaods now.
version 1.0.2, 2001/1/6
there's a bug related to goods mangement, Zhangjian found it.
Fixed.
created: 2000/12
*/
#include "stdafx.h"
#include <mmsystem.h> //for play sound
#include <io.h> //for get filelength
#include "DualListDemo.h"
#include "SelectionDlg.h"
#include "BuyDlg.h"
#include "SellDlg.h"
#include "ListCtrlSortClass.h"
#include "EnterBank.h"
#include "Hispital.h"
#include "ReplayLoad.h"
#include "NewsDlg.h"
#include "RijiDlg.h"
#include "NetworkClub.h"
#include "TopPlayerDlg.h"
#include "Wangba.h"
#include "DLGHTML.h"
#include "HouseDlg.h"
#include "RichTop10.h"
#include "HyperLink.h"
#include "SetupGame.h"
#include "StoryDlg.h"
#include "BeijingIntroDlg.h"
#include "BossComeDlg.h"
#include "PostMoneyDlg.h"
#include "ShengmingDlg.h"
#include "BitmapPicture.h"
#ifdef _DEBUG
#define new DEBUG_NEW
#undef THIS_FILE
static char THIS_FILE[] = __FILE__;
#endif
#define BEIJING 1
#define SHANGHAI 2
// when this is defined, real_time news is disabled.
//#define FOR_WINDOWS_XP 1
/*
get min of two int
*/
int MIN(int x, int y)
{
if(x>y)
return y;
else
return x;
}
/*
get a random number ranged from 0 to upper
*/
int RandomNum(int upper);
int RandomNum(int upper)
{
static int i=0;
if(i==0){
srand((unsigned)(time(NULL)));
i=1;
}
return rand()%upper;
};
#define GAME_MESSAGE_COUNT 18 // normal event number
/*
Random events type.
*/
typedef struct MessageType {
int freq; // the frequency of the events
char *msg; // what message to display when event happen
int drug; // goods ID to be influenced
int plus; // price increased ( *)
int minus; //price decrease ( /)
int add; // how many goods to give user (+)
} Message;
Message gameMessages [GAME_MESSAGE_COUNT] = {
{170, "专家提议提高大学生“动手素质”,进口玩具颇受欢迎!", 5, 2, 0, 0},
{139, "有人自豪地说:生病不用打针吃药,喝假白酒(剧毒)就可以!", 3, 3, 0, 0},
{100, "医院的秘密报告:“《上海小宝贝》功效甚过伟哥”!", 4, 5, 0, 0},
{41, "文盲说:“2000年诺贝尔文学奖?呸!不如盗版VCD港台片。”", 2, 4, 0, 0},
{37, "《北京经济小报》社论:“走私汽车大力推进汽车消费!”", 1, 3, 0, 0},
{23, "《北京真理报》社论:“提倡爱美,落到实处”,伪劣化妆品大受欢迎!", 7, 4, 0, 0},
{37, "8858.com电子书店也不敢卖《上海小宝贝》,黑市一册可卖天价!", 4, 8, 0, 0},
{15, "谢不疯在晚会上说:“我酷!我使用伪劣化妆品!”,伪劣化妆品供不应求!", 7, 7, 0, 0},
{40, "北京有人狂饮山西假酒,可以卖出天价!", 3, 7, 0, 0},
{29, "北京的大学生们开始找工作,水货手机大受欢迎!!", 6, 7, 0, 0},
{35, "北京的富人疯狂地购买走私汽车!价格狂升!", 1, 8, 0, 0},
{17, "市场上充斥着来自福建的走私香烟!", 0, 0, 8, 0},
{24, "北京的孩子们都忙于上网学习,进口玩具没人愿意买。", 5, 0, 5, 0},
{18, "盗版业十分兴旺,“中国硅谷”——中关村全是卖盗版VCD的村姑!", 2, 0, 8, 0},
{160, "厦门的老同学资助俺两部走私汽车!发了!!", 1, 0, 0, 2},
{45, "工商局扫荡后,俺在黑暗角落里发现了老乡丢失的进口香烟。", 0, 0, 0, 6},
{35, "俺老乡回家前把一些山西假白酒(剧毒)给俺!", 3, 0, 0, 4},
{140,"媒体报道:又有日本出口到中国的产品出事了! 出事后日本人死不认帐,拒绝赔偿。村长得知此消息,托人把他用的水货手机(无任何厂商标识)硬卖给您,收您2500元。",6,0,0,1}
};
// bad events user may encounter which do harm to user's health
typedef struct EventType {
int freq; // the frequency of this event
char *msg; // the message to dispplay while event happen
int hunt; // how many points user get hurted when event happen
char *sound; // the sound file to play for the event
} BadEvent;
#define EVENT_CNT 12 // total such events
BadEvent random_event [EVENT_CNT] = {
{117, "大街上两个流氓打了俺!", 3,"kill.wav"},
{157, "俺在过街地道被人打了蒙棍! ", 20,"death.wav"},
{21, "工商局的追俺超过三个胡同。 ",1,"dog.wav"},
{100, "北京拥挤的交通让俺心焦! ",1,"harley.wav"},
{35, "开小巴的打俺一耳光!",1,"hit.wav"},
{313, "一群民工打了俺!", 10,"flee.wav"},
{120, "附近胡同的一个小青年砸俺一砖头!", 5,"death.wav"},
{29, "附近写字楼一个假保安用电棍电击俺!",3,"el.wav"},
{43, "北京臭黑的小河熏着我了! ",1,"vomit.wav"},
{45, "守自行车的王大婶嘲笑俺没北京户口!",1,"level.wav"},
{48, "北京高温40度!俺热...",1,"lan.wav"},
{33, "申奥添了新风景,北京又来沙尘暴!",1,"breath.wav"}
};
/*
The event that has influency to user's money
*/
typedef struct StealType {
int freq; //the frequency of the event
char *msg; //the message to display when event happen
int ratoi; // how many ratio decreased. money=money*(1-ratoi)
} StealEvent;
#define STEAL_EVENT_CNT 7 //total numbers of such events
StealEvent random_steal_event [STEAL_EVENT_CNT] = {
{60, "俺怜悯地铁口扮演成乞丐的老太太。", 10},
{125, "一个汉子在街头拦住俺:“哥们,给点钱用!”。",10},
{100, "一个大个子碰了俺一下,说:“别挤了!”。",40},
{65, "三个带红袖章的老太太揪住俺:“你是外地人?罚款!”",20},
{35, "两个猛男揪住俺:“交长话附加费、上网费。”", 15},
{27, "副主任说:“办经商证?晚上不要去我家给我送钱哦。”", 10},
{40, "北京空气污染得厉害,俺去氧吧吸氧...", 5}
};
// about dialog
class CAboutDlg : public CDialog
{
public:
CAboutDlg();
CHyperLink m_urlEMail; // my email address( hyperlink type)
CHyperLink m_urlGroups; // news group of BeijingHell
CHyperLink m_homepage2; // homepage2
CBitmapPicture m_pic;
// Dialog Data
//{{AFX_DATA(CAboutDlg)
enum { IDD = IDD_ABOUTBOX };
//}}AFX_DATA
// ClassWizard generated virtual function overrides
//{{AFX_VIRTUAL(CAboutDlg)
protected:
virtual void DoDataExchange(CDataExchange* pDX); // DDX/DDV support
//}}AFX_VIRTUAL
// Implementation
protected:
//{{AFX_MSG(CAboutDlg)
afx_msg void OnDoubleclickedAuthor();
afx_msg void OnAuthor();
afx_msg void OnPostMoney();
afx_msg void OnDeclare();
afx_msg void OnRButtonDown(UINT nFlags, CPoint point);
virtual BOOL OnInitDialog();
//virtual BOOL OnInitDialog();
//}}AFX_MSG
DECLARE_MESSAGE_MAP()
};
CAboutDlg::CAboutDlg() : CDialog(CAboutDlg::IDD)
{
//{{AFX_DATA_INIT(CAboutDlg)
CString cs="作者:郭祥昊,男,1970年4月生,1998年毕业于北京邮电大学,获博士学位,专业:人工智能与自然语言处理。热爱游戏到了自己开发的地步。";
CString cs1="";
//}}AFX_DATA_INIT
}
void CAboutDlg::DoDataExchange(CDataExchange* pDX)
{
CDialog::DoDataExchange(pDX);
//{{AFX_DATA_MAP(CAboutDlg)
DDX_Control(pDX, IDC_GUO_EMAIL, m_urlEMail);
DDX_Control(pDX, IDC_GUO_GROUPS, m_urlGroups);
DDX_Control(pDX, IDC_LOGO, m_pic);
//}}AFX_DATA_MAP
}
BEGIN_MESSAGE_MAP(CAboutDlg, CDialog)
//{{AFX_MSG_MAP(CAboutDlg)
ON_BN_DOUBLECLICKED(IDC_AUTHOR, OnDoubleclickedAuthor)
ON_BN_CLICKED(IDC_AUTHOR, OnAuthor)
ON_BN_CLICKED(IDC_POST_MONEY, OnPostMoney)
ON_BN_CLICKED(IDC_DECLARE, OnDeclare)
ON_WM_RBUTTONDOWN()
//}}AFX_MSG_MAP
END_MESSAGE_MAP()
// when user double click a small area near icon
void CAboutDlg::OnDoubleclickedAuthor()
{
// TODO: Add your control notification handler code here
AfxMessageBox("Programmed by Guo xianghao([email protected])2000/12");
}
void CAboutDlg::OnAuthor()
{
// TODO: Add your control notification handler code here
OnDoubleclickedAuthor() ;
}
void CAboutDlg::OnPostMoney()
{
// TODO: Add your control notification handler code here
CPostMoneyDlg dlg;
dlg.DoModal();
}
void CAboutDlg::OnDeclare()
{
// TODO: Add your control notification handler code here
CShengmingDlg dlg;
dlg.DoModal();
}
void CAboutDlg::OnRButtonDown(UINT nFlags, CPoint point)
{
// TODO: Add your message handler code here and/or call default
static int i=0;
CString cs1="作者:郭祥昊,男,1970年4月生,1998年毕业于北京邮电大学,获博士学位,专业:人工智能与自然语言处理。目前从事自然语言处理研究,开发软件。热爱游戏到了自己开发的地步。在北京浮生超过10年。";
CString cs2="我爱自然,艺术、文学。编程序主要使用C/C++,但是对80x86汇编语言也非常熟悉,曾经给女朋友(现在是我孩子的妈)编过一个计算机病毒。我还精通LISP和Prolog语言,对信息检索技术和概念检索技术有很深入的研究。";
i+=1;
if(i>5)
{
if(i>10)
{
AfxMessageBox(cs2);
i=0;
}
else if(i==6)
AfxMessageBox(cs1);
}
CDialog::OnRButtonDown(nFlags, point);
}
BOOL CAboutDlg::OnInitDialog()
{
CDialog::OnInitDialog();
// TODO: Add extra initialization here
m_pic.SetBitmap(IDB_LOGO);
return TRUE; // return TRUE unless you set the focus to a control
// EXCEPTION: OCX Property Pages should return FALSE
}
/////////////////////////////////////////////////////////////////////////////
// Main user interface dialog :CSelectionDlg dialog
// init some(if not all) important varibles
CSelectionDlg::CSelectionDlg(CWnd* pParent /*=NULL*/)
: CDialog(CSelectionDlg::IDD, pParent)
{
m_hIcon = AfxGetApp()->LoadIcon(IDR_MAINFRAME);
m_City=BEIJING;
m_pDragImage = NULL;
m_pDragWnd = NULL;
//init game
int i;
MyCash=2000; // my init cash is 2000
MyDebt=5000; // my init debt is 5000
MyBank=0; // bank savings is 0
myTotal=0; // init goods I have
myCoat=100; // totally how many goods I can carry, due to house size
m_nMyHealth=100; // init health points
m_MyFame=100; // init fame points
m_nVisitWangba=0; // how many times a user can visit wangba, to avoid wanba abuse
m_MyCurrentLoc=-1; // I'm not in any of the locations at first
// user can change the following varibles by set up dialog:
m_bCloseSound=FALSE; // sound is open at game begining by default
m_bHackActs=FALSE; // don't allow hacker's action in bank network by default
m_nTimeLeft=40; //this is the total turns user can play
/*---------------------- init goods ------------------------------------------*/
for(i=0;i<8;i++){
m_DrugPrice[i]=0;
m_nMyDrugs[i]=-1; // do not have any goods in the begining
}
for(i=0;i<9;i++) // alloc memory for goods' name
m_chDrugName[i]=(char *)malloc(100);
// init the goods' name
strcpy(m_chDrugName[0],"进口香烟");
strcpy(m_chDrugName[1],"走私汽车");
strcpy(m_chDrugName[2],"盗版VCD、游戏");
strcpy(m_chDrugName[3],"假白酒(剧毒!)");
strcpy(m_chDrugName[4],"《上海小宝贝》(禁书)");
strcpy(m_chDrugName[5],"进口玩具");
strcpy(m_chDrugName[7],"伪劣化妆品");
strcpy(m_chDrugName[6],"水货手机");
strcpy(m_chDrugName[8],"");
/*------------------- end of init goods -----------------------------------------*/
}
CSelectionDlg::~CSelectionDlg()
{
delete m_pDragImage;
m_pDragImage = NULL;
}
void CSelectionDlg::DoDataExchange(CDataExchange* pDX)
{
CDialog::DoDataExchange(pDX);
//{{AFX_DATA_MAP(CSelectionDlg)
DDX_Control(pDX, IDC_LIST2, m_list2);
DDX_Control(pDX, IDC_LIST1, m_list1);
DDX_Control(pDX, IDC_MY_DEBT_LED, m_Text2);
DDX_Control(pDX, IDC_STATIC_COUNTER, m_HealthDisplay);
DDX_Control(pDX, IDC_STATIC_FAME, m_FameDisplay);
DDX_Control(pDX, IDC_BANK_MONEY, m_BankDisplay);
DDX_Control(pDX, IDC_CASH, m_CashDisplay);
DDX_Control(pDX, IDC_STATIC1, m_sTicker);
DDX_Control(pDX, IDC_BG, m_Picture);
//DDX_Radio(pDX,IDC_LOC_BEIJINGZHAN,m_nLoc);
//}}AFX_DATA_MAP
}
BEGIN_MESSAGE_MAP(CSelectionDlg, CDialog)
//{{AFX_MSG_MAP(CSelectionDlg)
ON_BN_CLICKED(IDC_ADD, OnAdd)
ON_BN_CLICKED(IDC_REMOVE, OnRemove)
ON_BN_CLICKED(IDC_ADDALL, OnAddAll)
ON_BN_CLICKED(IDC_REMOVEALL, OnRemoveAll)
ON_NOTIFY(NM_DBLCLK, IDC_LIST1, OnDblclkList1)
ON_NOTIFY(NM_DBLCLK, IDC_LIST2, OnDblclkList2)
ON_NOTIFY(LVN_BEGINDRAG, IDC_LIST1, OnBegindragList1)
ON_NOTIFY(LVN_BEGINDRAG, IDC_LIST2, OnBegindragList2)
ON_WM_MOUSEMOVE()
ON_WM_LBUTTONUP()
ON_NOTIFY(LVN_COLUMNCLICK, IDC_LIST1, OnColumnclickList1)
ON_NOTIFY(LVN_COLUMNCLICK, IDC_LIST2, OnColumnclickList2)
ON_BN_CLICKED(IDC_LOC_JIANGUOMEN, OnLocJianguomen)
ON_BN_CLICKED(IDC_LOC_BEIJINGZHAN, OnLocBeijingzhan)
ON_BN_CLICKED(IDC_LOC_XIZHIMEN, OnLocXizhimen)
ON_BN_CLICKED(IDC_LOC_CHONGWENMEN, OnLocChongwenmen)
ON_BN_CLICKED(IDC_LOC_DONGZHIMEN, OnLocDongzhimen)
ON_BN_CLICKED(IDC_LOC_FUXINGMEN, OnLocFuxingmen)
ON_BN_CLICKED(IDC_LOC_JISHUITAN, OnLocJishuitan)
ON_BN_CLICKED(IDC_LOC_CHANGCHUNJIE, OnLocChangchunjie)
ON_BN_CLICKED(IDC_GOTO_BANK, OnGotoBank)
ON_BN_CLICKED(IDC_HOSPITAL, OnHospital)
ON_BN_CLICKED(IDC_POSTOFFICE, OnPostoffice)
ON_COMMAND(ID_EXIT_ME, OnExit)
ON_COMMAND(ID_HIGH, OnHighScore)
ON_COMMAND(IDM_BANK, OnBank)
ON_COMMAND(IDM_HOSPIAL, OnMenuHospial)
ON_COMMAND(IDM_AIRPORT, OnAirport)
ON_COMMAND(IDM_WANGBA, OnWangba)
ON_COMMAND(ID_INTRO, OnIntro)
ON_COMMAND(ID_ABOUT, OnAbout)
ON_BN_CLICKED(IDC_TRY, OnTry)
ON_BN_CLICKED(IDC_POST, OnPost)
ON_BN_CLICKED(IDC_AGENCY, OnHouseAgency)
ON_COMMAND(IDM_NEW_GAME, OnNewGame)
ON_COMMAND(IDM_HOUSE_AGENT, OnHouseAgent)
ON_COMMAND(IDM_SETUP, OnSetup)
ON_COMMAND(IDC_STORY, OnStory)
ON_COMMAND(IDC_BEIJING_INTRO, OnBeijingIntro)
ON_WM_KEYDOWN()
ON_BN_CLICKED(IDC_BOSS, OnBoss)
ON_BN_CLICKED(IDC_LOC_GONGZHUFEN, OnLocGongzhufen)
ON_BN_CLICKED(IDC_LOC_PINGGUOYUAN, OnLocPingguoyuan)
ON_COMMAND(IDM_POSTOFFICE, OnPostoffice)
ON_BN_CLICKED(IDC_HOSP, OnHospital)
ON_BN_CLICKED(IDC_WANGBA, OnWangba)
ON_BN_CLICKED(IDC_GO_SHANGHAI, OnGoShanghai)
//}}AFX_MSG_MAP
END_MESSAGE_MAP()
/////////////////////////////////////////////////////////////////////////////
// CSelectionDlg message handlers.
// some other varibles are initialized.
BOOL CSelectionDlg::OnInitDialog()
{
CDialog::OnInitDialog();
CMenu* pSysMenu = GetSystemMenu(FALSE);
if (pSysMenu != NULL)
{
CString strAboutMenu;
strAboutMenu.LoadString(IDS_ABOUTBOX);
if (!strAboutMenu.IsEmpty())
{
pSysMenu->AppendMenu(MF_SEPARATOR);
// pSysMenu->AppendMenu(MF_STRING, IDM_ABOUTBOX, strAboutMenu);
}
}
// user can't close this dialog directly. ie, the close box on the top right is
// disbaled. This is to avoid user close the application directly, cause the help
// html file not to be deleted.
CMenu* mnu = this->GetSystemMenu(FALSE);
mnu->ModifyMenu(SC_CLOSE,MF_BYCOMMAND | MF_GRAYED );
// Set the icon for this dialog. The framework does this automatically
// when the application's main window is not a dialog
SetIcon(m_hIcon, TRUE); // Set big icon
SetIcon(m_hIcon, FALSE); // Set small icon
// full row select
m_list1.SendMessage(LVM_SETEXTENDEDLISTVIEWSTYLE, LVS_EX_FULLROWSELECT, LVS_EX_FULLROWSELECT);
m_list2.SendMessage(LVM_SETEXTENDEDLISTVIEWSTYLE, LVS_EX_FULLROWSELECT, LVS_EX_FULLROWSELECT);
// set image list to listctrl
if ( m_ImageList.Create(16, 16, ILC_COLOR, 0, 4) &&
m_ImageList.Add(AfxGetApp()->LoadIcon(IDI_MONEY)) != -1)
{
m_list1.SetImageList(&m_ImageList, LVSIL_SMALL);
m_list2.SetImageList(&m_ImageList, LVSIL_SMALL);
}
// create black market column
m_list1.InsertColumn(0, "商品", LVCFMT_LEFT, 68);
m_list1.InsertColumn(1, "黑市价格", LVCFMT_LEFT, 67);
m_list1.InsertColumn(2, "", LVCFMT_LEFT, 27);
// create house column
m_list2.InsertColumn(0, "商品", LVCFMT_LEFT, 68);
m_list2.InsertColumn(1, "买进价格", LVCFMT_LEFT, 67);
m_list2.InsertColumn(2, "数量", LVCFMT_LEFT, 57);
// add some items
for (int i = 0; i < 1; i++)
{
CString str;
str.Format("(%03d , ", i);
int n = m_list1.InsertItem(i, str + "01)", 0);
m_list1.SetItemText(n, 1, str + "02)");
m_list1.SetItemText(n, 2, str + "03)");
}
m_nBuyCount=0;
m_nSellCount=0;
m_nMyHealth=100; // well , I'm fit
m_MyFame=100; // well, my fame is very OK
m_nVisitWangba=0;
m_nSortList1Item = -1;
m_nSortList2Item = -1;
m_list1.SetColumnWidth(0,150);
m_list2.SetColumnWidth(0,100);
m_hcArrow = AfxGetApp()->LoadStandardCursor(IDC_ARROW);
m_hcNo = AfxGetApp()->LoadStandardCursor(IDC_NO);
// the text color to display debt is red.
m_Text2.SetBackColor(BLACK);
m_Text2.SetColor(BLACK, RGB(240,0,0));
// note: m_sTicker caused the game can not be run under Windows XP.
#ifndef FOR_WINDOWS_XP
// load and display real time news on the bottom
m_sTicker.SetTickerText(" Loading data, please wait...");
//IMPORTANT CALL to set the Window Coordinates of the Ticker
m_sTicker.GetWindowRect (&m_TickerRect);
m_sTicker.ShowRates ("Ticker.txt", RGB(255,255,255),RGB(255,255,43),"Comic Sans MS",17,4, MODE_RATES_TICKER);
// set the scrol speed of news
m_sTicker.SetTickerSpeed (2);
#endif
// 5 goods at start
makeDrugPrices(3);
HandleCashAndDebt();
DisplayDrugs();
// cool buttons
// boss coming protect. if user press this button, a large dialog appears, cover the
// game
m_btnBoss.SubclassDlgItem(IDC_BOSS, this);
COLORREF crStandard = ::GetSysColor(COLOR_BTNFACE);
m_btnBoss.SetInactiveBgColor(crStandard);
m_btnBoss.SetActiveBgColor(crStandard);
m_btnShanghai.SubclassDlgItem(IDC_GO_SHANGHAI, this);
crStandard = ::GetSysColor(COLOR_BTNFACE);
m_btnShanghai.SetInactiveBgColor(crStandard);
m_btnShanghai.SetActiveBgColor(crStandard);
// bank botton
m_btnTry.SubclassDlgItem(IDC_TRY, this); // Assign the icon
m_btnTry.SetIcon(IDI_HAND5, IDI_HAND4);
crStandard = ::GetSysColor(COLOR_BTNFACE);
m_btnTry.SetInactiveBgColor(crStandard - RGB(10,10,10));
m_btnTry.SetActiveBgColor(crStandard + RGB(40,40,40));
// hospital button
m_btnHosp.SubclassDlgItem(IDC_HOSP, this); // Assign the icon
m_btnHosp.SetIcon(IDI_HAND3, IDI_HAND2);
crStandard = ::GetSysColor(COLOR_BTNFACE);
m_btnHosp.SetInactiveBgColor(crStandard - RGB(10,10,10));
m_btnHosp.SetActiveBgColor(crStandard + RGB(40,40,40));
// post office button
m_btnPost.SubclassDlgItem(IDC_POST, this); // Assign the icon
m_btnPost.SetIcon(IDI_HAND7, IDI_HAND6);
crStandard = ::GetSysColor(COLOR_BTNFACE);
m_btnPost.SetInactiveBgColor(crStandard - RGB(10,10,10));
m_btnPost.SetActiveBgColor(crStandard + RGB(40,40,40));
// house agency button
m_btnAgency.SubclassDlgItem(IDC_AGENCY, this); // Assign the icon
m_btnAgency.SetIcon(IDI_HAND1,IDI_HOUSE1);
crStandard = ::GetSysColor(COLOR_BTNFACE);
m_btnAgency.SetInactiveBgColor(crStandard - RGB(10,10,10));
m_btnAgency.SetActiveBgColor(crStandard + RGB(40,40,40));
// network club button
m_btnNet.SubclassDlgItem(IDC_WANGBA, this); // Assign the icon
m_btnNet.SetIcon(IDI_HAND9, IDI_HAND8);
crStandard = ::GetSysColor(COLOR_BTNFACE);
m_btnNet.SetInactiveBgColor(crStandard - RGB(10,10,10));
m_btnNet.SetActiveBgColor(crStandard + RGB(40,40,40));
/*LoadBitmap (IDB_GAME_BK);
SetTransparent (TRUE);
SetTransColor (RGB(255,0,255));
SetStaticTransparent (TRUE);
SetClickAnywhereMove (TRUE);*/
// redisplay all the variables
RefreshDisplay();
CString str;
// display days user stay in Beijing
str.Format("北京浮生(%d/40天)",40-m_nTimeLeft);
// show this on the dialog title
SetWindowText(str);
GenerateRandomHelpFile();
// load the bitmap background
m_Picture.SetBitmap(IDB_BG);
return TRUE; // return TRUE unless you set the focus to a control
// EXCEPTION: OCX Property Pages should return FALSE
}
void CSelectionDlg::OnSysCommand(UINT nID, LPARAM lParam)
{
if ((nID & 0xFFF0) == ID_ABOUT)
{
CAboutDlg dlgAbout;
dlgAbout.DoModal();
}
else
{
CDialog::OnSysCommand(nID, lParam);
}
}
void CSelectionDlg::OnPaint()
{
if (IsIconic())
{
CPaintDC dc(this); // device context for painting
SendMessage(WM_ICONERASEBKGND, (WPARAM) dc.GetSafeHdc(), 0);
// Center icon in client rectangle
int cxIcon = GetSystemMetrics(SM_CXICON);
int cyIcon = GetSystemMetrics(SM_CYICON);
CRect rect;
GetClientRect(&rect);
int x = (rect.Width() - cxIcon + 1) / 2;
int y = (rect.Height() - cyIcon + 1) / 2;
// Draw the icon
dc.DrawIcon(x, y, m_hIcon);
}
else
{
CDialog::OnPaint();
}
}
HCURSOR CSelectionDlg::OnQueryDragIcon()
{
return (HCURSOR) m_hIcon;
}
void CSelectionDlg::OnAbout()
{
// TODO: Add your control notification handler code here
CAboutDlg dlgAbout;
dlgAbout.DoModal();
}
// "Buy" button is pressed. Handle the buy event
void CSelectionDlg::OnAdd()
{
CBuyDlg dlg;
CString num,str;
CString drug_name;
long price=0;
POSITION pos = m_list1.GetFirstSelectedItemPosition();
while (pos) {
int nItem = m_list1.GetNextSelectedItem(pos);
drug_name=m_list1.GetItemText(nItem, 0);
num=m_list1.GetItemText(nItem, 1);
price=atol(num);
}
if(price==0) //user did not select any drugs
{
CRijiDlg dlg(NULL,"我还没有选定买什么物品呢。");
dlg.DoModal();
RefreshDisplay();
return ;
}
// user do not have enough money to buy even one selected goods
if(MyCash< price){
if(MyBank>0){
CRijiDlg dlg(NULL,"俺带的现金不够,去银行提点钱吧。");
dlg.DoModal();
}
else
{
CRijiDlg dlg(NULL,"俺的现金不够,银行又没有存款,咋办哩?");
dlg.DoModal();
}
RefreshDisplay();
return ;
}
// decide the max number of drug user can buy
if(myTotal+MyCash/price >myCoat )
dlg.m_nMaxCount=MIN(myCoat-myTotal,MyCash/price);
else
dlg.m_nMaxCount=MyCash/price;
dlg.max=dlg.m_nMaxCount;
dlg.cash=MyCash;
dlg.drug_name=drug_name;
if(dlg.DoModal()==IDOK){ //user decide to buy
if(m_bCloseSound==FALSE)
PlaySound("sound\\buy.wav",NULL,SND_ASYNC );
m_nBuyCount=dlg.m_nMaxCount; //this is the acutal number user buy
myTotal+=m_nBuyCount; // coat occupied since goods come
if(myTotal>myCoat)
myTotal=myCoat;
MyCash-=price*m_nBuyCount; // cash decrease after user buy something
// display the changed cash
str.Format("%ld",MyCash);
m_CashDisplay.SetText(str);
// move goods
MoveListItems(m_list1, m_list2);
}
RefreshDisplay();
}
// handle the "Sell" event
void CSelectionDlg::OnRemove()
{
MoveListItems(m_list2, m_list1);
}
// this function is never called, it is part of the orignal example
void CSelectionDlg::OnAddAll()
{
// Select all then action
for (int i = 0; i < m_list1.GetItemCount(); i++)
m_list1.SetItemState(i, LVIS_SELECTED, LVIS_SELECTED);
OnAdd();
}
// this function is never called, it is part of the orignal example
void CSelectionDlg::OnRemoveAll()
{
// Select all then action
for (int i = 0; i < m_list2.GetItemCount(); i++)
m_list2.SetItemState(i, LVIS_SELECTED, LVIS_SELECTED);
OnRemove();
}
// this function is never called, it is part of the orignal example
void CSelectionDlg::OnDblclkList1(NMHDR* pNMHDR, LRESULT* pResult)
{
OnAdd();
*pResult = 0;
}
// this function is never called, it is part of the orignal example
void CSelectionDlg::OnDblclkList2(NMHDR* pNMHDR, LRESULT* pResult)
{
OnRemove();
*pResult = 0;
}
void CSelectionDlg::MoveListItems(CListCtrl & pFromList, CListCtrl & pToList)
{
static int bad_fame1=0, bad_fame2=0; // static var to display fame being bad msg
if (pFromList.GetSelectedCount() <= 0)
return; // no row selected to move
// Unselect row at pToList
int k = -1;
while ((k = pToList.GetNextItem(k, LVNI_SELECTED)) != -1)
{
pToList.SetItemState(k, 0, LVIS_SELECTED);
}
if(pFromList==m_list1){ //buy
int n=0;
int right_has=0;
CString right_drug;
// firstly, get the left drug_name & price
POSITION pos = m_list1.GetFirstSelectedItemPosition();
int nItem = m_list1.GetNextSelectedItem(pos);
CString drug_name=m_list1.GetItemText(nItem, 0);
CString price= m_list1.GetItemText(nItem, 1);
// secondly, to see the house.
// if no such goods find, add it
// else merge it
for (int i = 0; i < m_list2.GetItemCount(); i++)
{
right_drug=m_list2.GetItemText(i,0);
if(right_drug==drug_name) //find such drug in the right
{
right_has=1;
break;
}
}
//find, the displayed price shoud be avarage of old and new
if(right_has==1)
{
CString old_cnt,old;
int j;
int old_price;
old_cnt=m_list2.GetItemText(i, 2);
old=old_cnt;
old_price=atoi(m_list2.GetItemText(i, 1));
j=atoi(old_cnt);
j+=m_nBuyCount;
old_cnt.Format("%d",j);
m_list2.SetItemText(i,2,old_cnt);
CString guo;
guo.Format("%d",(int)((atoi(price)*m_nBuyCount+old_price*atoi(old))/(j)));
m_list2.SetItemText(i,1,guo);
}
// well, can hold some goods there
else if(m_nBuyCount!=0){
CString cnt;
n=m_list2.InsertItem(0,drug_name);
m_list2.SetItemText(n,1,m_list1.GetItemText(nItem, 1));
cnt.Format("%d",m_nBuyCount);
m_list2.SetItemText(n,2,cnt);
}
// no more room left for hold the goods
else{
CString msg;
msg.Format("好可惜!俺租的房子太小,只能放%d个物品。租更大的房子?",myCoat);
CRijiDlg dlg(NULL,msg);
dlg.DoModal();
RefreshDisplay();
}
}
else //sell
{
int n=0;
int left_has=0;
CString left_drug;
// firstly, get the left drug_name & price
POSITION pos = m_list2.GetFirstSelectedItemPosition();
int nItem = m_list2.GetNextSelectedItem(pos);
CString drug_name=m_list2.GetItemText(nItem, 0);
CString count= m_list2.GetItemText(nItem, 2);
// secondly, to see the left
// if no such drug find, add it
// else merge it
for (int i = 0; i < m_list1.GetItemCount(); i++)
{
left_drug=m_list1.GetItemText(i,0);
if(left_drug==drug_name) //find such drug in the right
{
left_has=1;
break;
}
}
if(left_has==1) //find
{
/*
1. Ask user how many he wants to sell
get the count at first
2. if sell all
delete right item
else
decrease right item count
3. count house room and user's cash
*/
CSellDlg dlg;
dlg.m_nMaxCount=atoi(count);
dlg.max=atoi(count);
dlg.m_strSellMsg.Format("您有%d个",atoi(count));
dlg.m_strSellMsg+=drug_name;
dlg.m_strSellMsg+=",想卖出多少?";
if(dlg.DoModal()==IDOK){
if(m_bCloseSound==FALSE)
PlaySound("sound\\money.wav",NULL,SND_ASYNC );
m_nSellCount=dlg.m_nMaxCount; //this is the acutal number user buy
myTotal-=m_nSellCount; // coat occupied since drug in
MyCash+=m_nSellCount*atoi(m_list1.GetItemText(i,1));
CString str;
str.Format("%ld",MyCash);
m_CashDisplay.SetText(str);
if(m_nSellCount==atoi(count)) // all sold out
m_list2.DeleteItem(nItem);
else // sell only a part
{
CString drug_left;
drug_left.Format("%d",atoi(count)-m_nSellCount);
m_list2.SetItemText(nItem,2,drug_left);
}
// some drug would decrease user's fame
if(drug_name=="《上海小宝贝》(禁书)" )
{
CString fame;
fame="";
fame+="买卖";
fame+=drug_name;
fame+=",";
fame+="污染社会,俺的名声变坏了啊!";
// if it is the first time for a user to sell such goods,
// display some message to inform fame being bad
if(bad_fame1==0){
CRijiDlg dlg(NULL,fame);
dlg.DoModal();
bad_fame1=1;
}
CString str;
m_MyFame-=7; // decrease by 7 point every time
if(m_MyFame<60){
m_FameDisplay.SetBackColor(BLACK);
m_FameDisplay.SetColor(BLACK, RGB(240,0,0));
}
if(m_MyFame<0) m_MyFame=0; // no neg value allowed.
str.Format("%ld",m_MyFame);
m_FameDisplay.SetText(str);
}
// ok, same as above
else if(drug_name=="假白酒(剧毒!)" )
{
CString fame;
fame="";
fame+="买卖";
fame+=drug_name;
fame+=",";
fame+="危害社会,俺的名声下降了.";
if(bad_fame2==0){
CRijiDlg dlg(NULL,fame);
dlg.DoModal();
bad_fame2=1;
}
CString str;
m_MyFame-=10;
if(m_MyFame<60){
m_FameDisplay.SetBackColor(BLACK);
m_FameDisplay.SetColor(BLACK, RGB(240,0,0));
}
if(m_MyFame<0) m_MyFame=0;
str.Format("%ld",m_MyFame);
m_FameDisplay.SetText(str);
}
}
RefreshDisplay();
}
else{ // no one is selling the selected goods in the black market
CString cnt;
cnt="哦?仿佛没有人在这里做";
cnt+=drug_name;
cnt+="生意。";
CRijiDlg dlg(NULL,cnt);
dlg.DoModal();
RefreshDisplay();
}
}
pToList.EnsureVisible(0, TRUE);
pToList.SetFocus();
}
void CSelectionDlg::OnBegindragList1(NMHDR* pNMHDR, LRESULT* pResult)
{
OnBegindrag(&m_list1, pNMHDR);
*pResult = 0;
}
void CSelectionDlg::OnBegindragList2(NMHDR* pNMHDR, LRESULT* pResult)
{
OnBegindrag(&m_list2, pNMHDR);
*pResult = 0;
}
void CSelectionDlg::OnBegindrag(CListCtrl* pList, NMHDR* pNMHDR)
{
NM_LISTVIEW* pNMListView = (NM_LISTVIEW*)pNMHDR;
if (pList->GetSelectedCount() <= 0)
return; // No row selected
POINT pt;
m_pDragImage = CreateDragImageEx(pList, &pt);
if (m_pDragImage == NULL)
return;
m_pDragWnd = pList;
CPoint ptStart = pNMListView->ptAction;
ptStart -= pt;
m_pDragImage->BeginDrag(0, ptStart);
m_pDragImage->DragEnter(GetDesktopWindow(), pNMListView->ptAction);
SetCapture();
}
void CSelectionDlg::OnMouseMove(UINT nFlags, CPoint point)
{
CDialog::OnMouseMove(nFlags, point);
if (m_pDragImage && m_pDragWnd) // In Drag&Drop mode ?
{
CPoint ptDropPoint(point);
ClientToScreen(&ptDropPoint);
m_pDragImage->DragMove(ptDropPoint);
CWnd* pDropWnd = CWnd::WindowFromPoint(ptDropPoint);
SetCursor (((pDropWnd == &m_list1) || (pDropWnd == &m_list2)) ? m_hcArrow : m_hcNo);
}