C The WordGame codes are below include include include incl
C++:
The WordGame codes are below
------------------------------------------------------------------------
#include <windows.h>
#include <commctrl.h>
#include <stdio.h>
#include \"resource.h\"
#include <iostream>
#include <string>
#include <cstring>
#include <sstream>
using namespace std;
//Declare global variables
char word[4]={\'d\',\'b\',\'a\',\'w\'};
char letter;
int check[4]={0,0,0,0};
HWND t1,t2,t3,t4;
HINSTANCE hInst;
BOOL CALLBACK DlgMain(HWND hwndDlg, UINT uMsg, WPARAM wParam, LPARAM lParam)
{
switch(uMsg)
{
case WM_INITDIALOG:
{
}
return TRUE;
case WM_CLOSE:
{
EndDialog(hwndDlg, 0);
}
return TRUE;
case WM_COMMAND:
{
switch(LOWORD(wParam))
{
//insert the cases for the buttons
case 1:
//check if the letter a is in the Word
//get the handes for each textbox
t1=GetDlgItem(hwndDlg,100);
t2=GetDlgItem(hwndDlg,101);
t3=GetDlgItem(hwndDlg,102);
t4=GetDlgItem(hwndDlg,103);
// check if the letter is in the word
for (int i=0;i<4;i++){
if (word[i]==\'a\')
check[i]=1;
}
//write the letter in the correct position
for(int i=0;i<4;i++){
switch(i)
{
case 0:
if(check[i]==1){
SetWindowText(t1,\"a\");
check[i]=0;
}
break;
case 1:
if(check[i]==1){
SetWindowText(t2,\"a\");
check[i]=0;
}
break;
case 2:
if(check[i]==1){
SetWindowText(t3,\"a\");
check[i]=0;
}
break;
case 3:
if(check[i]==1){
SetWindowText(t3,\"a\");
check[i]=0;
}
break;
}
}
break;
case 2:
//check if the letter a is in the Word
//get the handes for each textbox
t1=GetDlgItem(hwndDlg,100);
t2=GetDlgItem(hwndDlg,101);
t3=GetDlgItem(hwndDlg,102);
t4=GetDlgItem(hwndDlg,103);
// check if the letter is in the word
for (int i=0;i<4;i++){
if (word[i]==\'b\')
check[i]=1;
}
//write the letter in the correct position
for(int i=0;i<4;i++){
switch(i)
{
case 0:
if(check[i]==1){
SetWindowText(t1,\"b\");
check[i]=0;
}
break;
case 1:
if(check[i]==1){
SetWindowText(t2,\"b\");
check[i]=0;
}
break;
case 2:
if(check[i]==1){
SetWindowText(t3,\"b\");
check[i]=0;
}
break;
case 3:
if(check[i]==1){
SetWindowText(t3,\"b\");
check[i]=0;
}
break;
}
}
break;
}
}
return TRUE;
}
return FALSE;
}
int APIENTRY WinMain(HINSTANCE hInstance, HINSTANCE hPrevInstance, LPSTR lpCmdLine, int nShowCmd)
{
hInst=hInstance;
InitCommonControls();
return DialogBox(hInst, MAKEINTRESOURCE(DLG_MAIN), NULL, (DLGPROC)DlgMain);
}
___________________________
#include <windows.h>
#include <commctrl.h>
#include <richedit.h>
#include \"resource.h\"
//
// Dialog resources
//
LANGUAGE LANG_NEUTRAL, SUBLANG_NEUTRAL
DLG_MAIN DIALOG 0, 0, 286, 296
STYLE DS_3DLOOK | DS_CENTER | DS_MODALFRAME | DS_SHELLFONT | WS_CAPTION | WS_VISIBLE | WS_POPUP | WS_SYSMENU
CAPTION \"Dialog\"
FONT 8, \"Ms Shell Dlg\"
{
EDITTEXT 100, 35, 38, 30, 26, ES_AUTOHSCROLL, WS_EX_LEFT
EDITTEXT 101, 81, 38, 30, 26, ES_AUTOHSCROLL, WS_EX_LEFT
EDITTEXT 102, 124, 38, 30, 26, ES_AUTOHSCROLL, WS_EX_LEFT
EDITTEXT 103, 169, 37, 30, 26, ES_AUTOHSCROLL, WS_EX_LEFT
PUSHBUTTON \"A\", 1, 34, 94, 21, 18, 0, WS_EX_LEFT
PUSHBUTTON \"B\", 2, 61, 94, 18, 18, 0, WS_EX_LEFT
PUSHBUTTON \"C\", 0, 84, 94, 19, 17, 0, WS_EX_LEFT
PUSHBUTTON \"D\", 0, 107, 94, 18, 17, 0, WS_EX_LEFT
PUSHBUTTON \"E\", 0, 129, 94, 18, 17, 0, WS_EX_LEFT
PUSHBUTTON \"F\", 0, 153, 94, 19, 18, 0, WS_EX_LEFT
PUSHBUTTON \"G\", 0, 176, 94, 18, 17, 0, WS_EX_LEFT
}
//
// Manifest resources
//
LANGUAGE LANG_NEUTRAL, SUBLANG_NEUTRAL
1 RT_MANIFEST \".\\\\manifest.xml\"
_____________________________________________
2. Download the WordGame project. The program let the user to guess a 4 letter word each time that the use click a letter button the program will check if the letter is in the word and show the letter in a text box. Th word is stored in a char variable (constraint the size to a 4 letter word) 3. Code all the missing buttons 4. Show a counter of the number of mistakes. 5. Use a message box to show the user that he gassed the word correctly 6. Let the user to reset the game.Solution
Please find the modified program below:
#include <windows.h>
#include <commctrl.h>
#include <stdio.h>
#include \"resource.h\"
#include <iostream>
#include <string>
#include <cstring>
#include <sstream>
using namespace std;
//Declare global variables
char word[4]={\'d\',\'b\',\'a\',\'w\'};
char letter;
int check[4]={0,0,0,0};
HWND t1,t2,t3,t4;
HINSTANCE hInst;
BOOL CALLBACK DlgMain(HWND hwndDlg, UINT uMsg, WPARAM wParam, LPARAM lParam)
{
switch(uMsg)
{
case WM_INITDIALOG:
{
}
return TRUE;
case WM_CLOSE: // If the user clicks the X to close the dialog box
{
EndDialog(hwndDlg, 0);
}
return TRUE;
case WM_COMMAND:
{
switch(LOWORD(wParam))
{
//insert the cases for the buttons
case 1:
//check if the letter a is in the Word
//get the handes for each textbox
t1=GetDlgItem(hwndDlg,100);
t2=GetDlgItem(hwndDlg,101);
t3=GetDlgItem(hwndDlg,102);
t4=GetDlgItem(hwndDlg,103);
// check if the letter is in the word
for (int i=0;i<4;i++){
if (word[i]==\'a\')
check[i]=1;
}
//write the letter in the correct position
for(int i=0;i<4;i++){
switch(i)
{
case 0:
if(check[i]==1){
SetWindowText(t1,\"a\");
check[i]=0;
}
break;
case 1:
if(check[i]==1){
SetWindowText(t2,\"a\");
check[i]=0;
}
break;
case 2:
if(check[i]==1){
SetWindowText(t3,\"a\");
check[i]=0;
}
break;
case 3:
if(check[i]==1){
SetWindowText(t3,\"a\");
check[i]=0;
}
break;
}
}
break;
case 2:
//check if the letter b is in the Word
//get the handes for each textbox
t1=GetDlgItem(hwndDlg,100);
t2=GetDlgItem(hwndDlg,101);
t3=GetDlgItem(hwndDlg,102);
t4=GetDlgItem(hwndDlg,103);
// check if the letter is in the word
for (int i=0;i<4;i++){
if (word[i]==\'b\')
check[i]=1;
}
//write the letter in the correct position
for(int i=0;i<4;i++){
switch(i)
{
case 0:
if(check[i]==1){
SetWindowText(t1,\"b\");
check[i]=0;
}
break;
case 1:
if(check[i]==1){
SetWindowText(t2,\"b\");
check[i]=0;
}
break;
case 2:
if(check[i]==1){
SetWindowText(t3,\"b\");
check[i]=0;
}
break;
case 3:
if(check[i]==1){
SetWindowText(t3,\"b\");
check[i]=0;
}
break;
}
}
break;
case 3:
//check if the letter d is in the Word
//get the handes for each textbox
t1=GetDlgItem(hwndDlg,100);
t2=GetDlgItem(hwndDlg,101);
t3=GetDlgItem(hwndDlg,102);
t4=GetDlgItem(hwndDlg,103);
// check if the letter is in the word
for (int i=0;i<4;i++){
if (word[i]==\'d\')
check[i]=1;
}
//write the letter in the correct position
for(int i=0;i<4;i++){
switch(i)
{
case 0:
if(check[i]==1){
SetWindowText(t1,\"d\");
check[i]=0;
}
break;
case 1:
if(check[i]==1){
SetWindowText(t2,\"d\");
check[i]=0;
}
break;
case 2:
if(check[i]==1){
SetWindowText(t3,\"d\");
check[i]=0;
}
break;
case 3:
if(check[i]==1){
SetWindowText(t3,\"d\");
check[i]=0;
}
break;
}
}
break;
case 4:
//check if the letter w is in the Word
//get the handes for each textbox
t1=GetDlgItem(hwndDlg,100);
t2=GetDlgItem(hwndDlg,101);
t3=GetDlgItem(hwndDlg,102);
t4=GetDlgItem(hwndDlg,103);
// check if the letter is in the word
for (int i=0;i<4;i++){
if (word[i]==\'w\')
check[i]=1;
}
//write the letter in the correct position
for(int i=0;i<4;i++){
switch(i)
{
case 0:
if(check[i]==1){
SetWindowText(t1,\"w\");
check[i]=0;
}
break;
case 1:
if(check[i]==1){
SetWindowText(t2,\"w\");
check[i]=0;
}
break;
case 2:
if(check[i]==1){
SetWindowText(t3,\"w\");
check[i]=0;
}
break;
case 3:
if(check[i]==1){
SetWindowText(t3,\"w\");
check[i]=0;
}
break;
}
}
break;
}
}
return TRUE;
}
return FALSE;
}
int APIENTRY WinMain(HINSTANCE hInstance, HINSTANCE hPrevInstance, LPSTR lpCmdLine, int nShowCmd)
{
hInst=hInstance;
InitCommonControls();
return DialogBox(hInst, MAKEINTRESOURCE(DLG_MAIN), NULL, (DLGPROC)DlgMain);
}
___________________________
#include <windows.h>
#include <commctrl.h>
#include <richedit.h>
#include \"resource.h\"
//
// Dialog resources
//
LANGUAGE LANG_NEUTRAL, SUBLANG_NEUTRAL
DLG_MAIN DIALOG 0, 0, 286, 296
STYLE DS_3DLOOK | DS_CENTER | DS_MODALFRAME | DS_SHELLFONT | WS_CAPTION | WS_VISIBLE | WS_POPUP | WS_SYSMENU
CAPTION \"Dialog\"
FONT 8, \"Ms Shell Dlg\"
BEGIN
{
EDITTEXT 100, 35, 38, 30, 26, ES_AUTOHSCROLL, WS_EX_LEFT
EDITTEXT 101, 81, 38, 30, 26, ES_AUTOHSCROLL, WS_EX_LEFT
EDITTEXT 102, 124, 38, 30, 26, ES_AUTOHSCROLL, WS_EX_LEFT
EDITTEXT 103, 169, 37, 30, 26, ES_AUTOHSCROLL, WS_EX_LEFT
PUSHBUTTON \"A\", 1, 34, 94, 21, 18, 0, WS_EX_LEFT
PUSHBUTTON \"B\", 2, 61, 94, 18, 18, 0, WS_EX_LEFT
PUSHBUTTON \"C\", 0, 84, 94, 19, 17, 0, WS_EX_LEFT
PUSHBUTTON \"D\", 0, 107, 94, 18, 17, 0, WS_EX_LEFT
PUSHBUTTON \"E\", 0, 129, 94, 18, 17, 0, WS_EX_LEFT
PUSHBUTTON \"F\", 0, 153, 94, 19, 18, 0, WS_EX_LEFT
PUSHBUTTON \"G\", 0, 176, 94, 18, 17, 0, WS_EX_LEFT
}
END







