Windows Programming-Aircraft war notes (database record game score)

Source: Internet
Author: User

2015/07/23////////////////

by xbw//////////////////////

Environmental vs2013////////////

This aircraft war, did also have several days, I more than half of the time in the database, the first time, also learned a lot of things, in this record, but also share experience;

Then said last time, yesterday, the realization of a number of data storage and invocation, ecstatic, yesterday has been tested on the user points of the storage, but yesterday not only failed, but also the source of the program destroyed, fortunately again this paste the complete code, quickly restored, today a think, if there is account registration without scoring records, What is the point of that, and then tinker up;

Let's talk a little bit about ideas,,,

This score to match with the account, is to save the final score to the current user, this, for the sake of simple implementation, I made a game to end the storage Record dialog box, first look at the layout

This score, closed the user editing function, the game score is the game score, can not be changed, this account, is the current player's account, you need to input, as long as the wrong, will put the score stored to other users, alas, in order to achieve it, temporarily do not automatically match, a will be in, This is the process;

In the implementation process, but also made a lot of embarrassing things, who let their knowledge reserve is not enough;

For the data in different CPP transfer let me big expense, but also built a lot of classes, not duplicate definition is that the mistake, tinker one morning or not, when looking for information, found this can be solved with global variables, my days, only with an extern int score;

extern, alas, look below the main code bar;;;

New class for Save Record dialog box Jilu class, English is not good, no way;

. cpp

Jilu.cpp: Implement file//#pragma once#include "stdafx.h" #include "PlaneGame.h" #include "jilu.h" #include "afxdialogex.h" # Include "afxdao.h"//#include "final.h"//Jilu Dialog implement_dynamic (Jilu, CDialogEx) extern int Score;jilu::jilu (cwnd* Pparent/*=null*/): CDialogEx (Jilu::idd, pparent), M_score (0), Zhongyu (_t ("")) {M_score = score;} Jilu::~jilu () {}void Jilu::D odataexchange (cdataexchange* pdx) {cdialogex::D odataexchange (PDX);DD x_text (PDX, IDC_ EDIT2, M_score);DD x_text (PDX, idc_edit1, Zhongyu);} Begin_message_map (Jilu, CDialogEx) on_en_change (Idc_edit2, &jilu::onenchangeedit2) ON_BN_CLICKED (IDOK, & Jilu::onbnclickedok) End_message_map ()//Jilu Message handler void Jilu::onenchangeedit2 () {//TODO: If the control is a RICHEDIT control, it will not// This notification is sent unless you override the Cdialogex::oninitdialog ()//function and call CRichEditCtrl (). SetEventMask (),//The ENM_CHANGE flag "or" is also calculated into the mask. TODO: In this Add control notification handler code//cstring str1;//cstring str2;//cstring Str3;/*int A, B; GetDlgItemText (Idc_edit1, str1); GetDlgItemText (Idc_edit2, str2); a = _wtoi (str1); b = _wtoi (STR2); for(int i = A; I <= b; i++) {//updatedata (true); if (i% 3 = = 0) {str3. Format (_t ("%s%d"), STR3, i), str3 + = _t ("\ r \ n");} Std::cout << Std::endl;} *//*cstring Str3;int score = 100;str3;str3. Format (_t ("%s%d"), Str3,score); Setdlgitemtext (Idc_edit2, STR3); */}void Jilu::onbnclickedok () {CString Str; Str.format (_t ("%d"), score); UpdateData (TRUE);//The last video has been said, continue to update the data in time CString Filepath = _t ("Database.mdb"); CDaoDatabase DB; CDaoRecordset Dbset (&db);d B. Open (Filepath);D bset. Open (Afx_dao_use_default_type, _t ("SELECT * from DataTable"), 0); if (Zhongyu. IsEmpty ()) {MessageBox (_t ("Information cannot be empty!"), _t ("tenderness hint"));} Else{cstring Sname; COleVariant var;//field type var. ChangeType (VT_BSTR, NULL); int first = 1;while (! Dbset.iseof ())///There is no end to table {Dbset.getfieldvalue (_t ("Name"), Var); Sname = (LPCSTR) var.pbstrval;if (Sname.compare (zhongyu) = = 0)//If the password and account are consistent with the database {Dbset.edit ();D bset. SetFieldValue (_t ("Score"), _variant_t (STR));D bset. Update (); MessageBox (_t ("Record stored"), _t ("tenderness hint")); first = 0;break;} Else{dbset.movenext ();}} if (first){MessageBox (_t ("User does not exist"), _t ("tenderness hint"));}} Dbset.close ();d B. Close ();//TODO: Add control notification handler code here}


. h

#pragma once//jilu dialog box//#include "final.h" Class Jilu:public cdialogex{declare_dynamic (Jilu)/*private:int fen;public: Jilu () {};jilu (int a) {fen = A;} int get (int a) {fen = A;} int get () {return fen;} */public:jilu (cwnd* pparent = NULL);   Standard constructor virtual ~jilu (); int mm_score=0;//dialog data enum {IDD = idd_dialog3};p rotected:virtual void DoDataExchange (Cdataexc hange* PDX);    DDX/DDV supports Declare_message_map () public:int m_score;afx_msg void OnEnChangeEdit2 (); afx_msg void OnBnClickedOK (); CString Zhongyu;};


That global variable, where we should put it, is where the game ends,

int score = 0;int Number = 0;int R_life = 10;void cplanegameview::updateframe (cdc* PMEMDC) {//Draw Sky/*pmemdc->fillsolidre CT (0,0,GAME_WIDTH,GAME_HEIGHT,RGB (84, 142, 239));//Draw our fighter if (m_pme!=null) {M_pme->draw (m_pmemdc,false);} else{   //game overcstring str=_t ("Game over!"); Pmemdc->setbkmode (TRANSPARENT);p memdc->settextalign (ta_center);p Memdc->settextcolor (RGB (255,0,0)); Pmemdc->textout (GAME_WIDTH/2,GAME_HEIGHT/2,STR);} *///background if (back_y >= 0) {CBitmap membitmap; Membitmap.createcompatiblebitmap (M_PDC, Game_width, 3072); M_pmemdc->selectobject (&MemBitmap); image. Draw (*M_PMEMDC, 0, 0, game_width, game_height, 0, back_y, Game_width, game_height); Back_y-= 1;} if (back_y <= 0) back_y = 2000;//Draw our fighter


Just put it where it should be.;;;

So, there are some problems in the middle, again, about this access data, several times to give me pop out of memory, I think it is what ghost,

After practice found the problem, this variable type must be matched with the stored data defined variables, integer stored as characters will be out of memory, experience, this integer to the character type also found a function, also good, very convenient,

CString Str;
Str.format (_t ("%d"), score);

In this way, experience, share to you, welcome to learn to communicate, to provide guidance, thank YOU!!!!

Copyright NOTICE: This article for Bo Master original article, without Bo Master permission not reproduced.

Windows Programming-Aircraft war notes (database record game score)

Related Article

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.