我如何将图形放入此程序并使用Visual Studio 2012 [英] How Can I Put Graphics In This Program And Im Using Visual Studio 2012

查看:98
本文介绍了我如何将图形放入此程序并使用Visual Studio 2012的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

  #include   <   iostream.h  >  
#include < stdlib.h >
#include < string.h >
#include < conio.h >

const int MAXLENGTH = 20 ;
const int MAX_TRIES = 5 ;
const int MAXROW = 7 ;

int letterFill( char char [], char []);
void initUnknown( char [], char []);

int main()
{
clrscr();
char unknown [MAXLENGTH];
char letter;
int num_of_wrong_guesses = 0 ;
char 字[MAXLENGTH];
char words [] [MAXLENGTH] =
{
dadu
haala
jamshoro
karachi
mithi
nawabshah
rohri
sukkur
thatta
umerkot
};

// 随机选择并复制单词数组
randomize();
int n = random( 10 );
strcpy(word,words [n]);

// 使用*字符初始化密码。
initUnknown(word,unknown);

// 欢迎用户
cout<< \ n \ n欢迎来到游戏......猜猜海德拉巴城市名称;
cout<< \ n \ n每个字母由星号表示 - >'*';
cout<< \ n \ n您只需在一次尝试中键入一个字母;
cout<< \ n \ n你有<< MAX_TRIES<< 尝试猜测正确的城市名称。;
cout<< \ n ~~~~~~~~~~~~~~~~~~~~~~~ ~~~~~~~~~~~~~~~~~~~~~~;

// 循环直到猜测用完
< span class =code-keyword> while
(num_of_wrong_guesses< MAX_TRIES)
{
cout<< \ n \ n<<未知;
cout<< \ n \ n取一封信:;
cin>>信件;
// 如果猜测正确,请用字母填写密码,
< span class =code-comment> //
否则增加错误猜测的数量。
if (letterFill(字母,单词,未知)== 0
{
cout<< endl<< 哎呀!那封信不在那里!<< ENDL;
num_of_wrong_guesses ++;
}
else
{
cout<< endl<< 你找到了一封信!不是那么令人兴奋的Dude(Y)< *!*><< ENDL;
}
// 告诉用户剩下多少猜测。
cout<< 您有<< MAX_TRIES - num_of_wrong_guesses;
cout<< 猜对了。<< ENDL;
// 检查他们是否猜到了这个词。
if (strcmp(word,unknown)== 0
{
cout<<单词<< ENDL;
cout<< 是的!你明白了!;
break ;
}

}
如果(num_of_wrong_guesses == MAX_TRIES)
{
cout< ;< \ n抱歉,你输了......你被绞死了。<< ENDL;
cout<< 这个词是:<<单词<< ENDL;
}
getch();
return 0 ;
}

/ * 取一个字符猜测和密码,填写
未完成的猜测。返回匹配的字符数。
此外,如果已经猜到了字符,则返回零。 * /


int letterFill( char guess, char secretword [], char guessword [])
{
int i;
int matches = 0 ;
for (i = 0 ; secretword [i]!= ' \ 0'; i ++)
{

// 我们之前的猜测中是否已匹配此字母?
if (guess == guessword [i])
return 0 ;

// 这个秘密字是猜测吗?
if (guess == secretword [i])
{
guessword [i] = guess;
匹配++;
}
}
返回匹配;
}


// 初始化未知单词

void initUnknown( char word [], char unknown [])
{
int i;
int length = strlen(word);
for (i = 0 ; i< length; i ++)
unknown [i] = ' *';
unknown [i] = ' \0';
}

解决方案

基本上,你没有。

这是一个控制台应用,控制台只支持文本。

如果你想使用图形,那么你需要查看一个Windows应用程序 - 也许是一个WinForms应用程序?


通常你在Windows GUI应用程序中使用图形。这种应用程序的开发与您所做的非常不同(Console one)。您可以开始阅读像

theForger的Win32 API编程教程
这样的教程。 a href =http://www.winprog.org/tutorial/start.htmltarget =_ blanktitle =New Window> ^ ](这是一种'对金属'的发展,您也可以查看一个框架,例如 MFC )。


您可以输出艺术品:

(例子)http://chris.com/ascii/

(ascii art generator example) http://www.glassgiant.com/ascii/ [ ^

#include <iostream.h>
#include <stdlib.h>
#include <string.h>
#include <conio.h>

const int MAXLENGTH=20;
const int MAX_TRIES=5;
const int MAXROW=7;

int letterFill (char, char[], char[]);
void initUnknown (char[], char[]);

int main ()
{
clrscr();
	char unknown [MAXLENGTH];
	char letter;
	int num_of_wrong_guesses=0;
	char word[MAXLENGTH];
	char words[][MAXLENGTH] =
	{
		"dadu",
		"haala",
		"jamshoro",
		"karachi",
		"mithi",
		"nawabshah",
		"rohri",
		"sukkur",
		"thatta",
		"umerkot"
	};

	//choose and copy a word from array of words randomly
	randomize();
	int n=random(10);
	strcpy(word,words[n]);

	// Initialize the secret word with the * character.
	initUnknown(word, unknown);

	// welcome the user
	cout << "\n\nWelcome To The Game...Guess a Hyderabad Cities Name";
	cout << "\n\nEach letter is represented by a star -> '*'";
	cout << "\n\nYou have to type only one Alphabet in one try";
	cout << "\n\nYou have " << MAX_TRIES << " tries to try and guess the correct City name.";
	cout << "\n~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~";

	// Loop until the guesses are used up
	while (num_of_wrong_guesses < MAX_TRIES)
	{
		cout << "\n\n" << unknown;
		cout << "\n\nGuess a letter: ";
		cin >> letter;
		// Fill secret word with letter if the guess is correct,
		// otherwise increment the number of wrong guesses.
		if (letterFill(letter, word, unknown)==0)
		{
			cout << endl << "Whoops! That letter isn't in there!" << endl;
			num_of_wrong_guesses++;
		}
		else
		{
			cout << endl << "You found a letter! Isn't that exciting Dude (Y) <*!*>" << endl;
		}
		// Tell user how many guesses has left.
		cout << "You have " << MAX_TRIES - num_of_wrong_guesses;
		cout << " guesses left." << endl;
		// Check if they guessed the word.
		if (strcmp(word, unknown) == 0)
		{
			cout << word << endl;
			cout << "Yeah! You got it!";
			break;
		}

	}
	if(num_of_wrong_guesses == MAX_TRIES)
	{
		cout << "\nSorry, you lose...you've been hanged." << endl;
		cout << "The word was : " << word << endl;
	}
	getch();
	return 0;
}

/* Take a one character guess and the secret word, and fill in the
 unfinished guessword. Returns number of characters matched.
 Also, returns zero if the character is already guessed. */

int letterFill (char guess, char secretword[], char guessword[])
{
	int i;
	int matches=0;
	for (i = 0; secretword[i]!='\0'; i++)
	{

		// Did we already match this letter in a previous guess?
		if (guess == guessword[i])
			return 0;

		// Is the guess in the secret word?
		if (guess == secretword[i])
		{
			guessword[i] = guess;
			matches++;
		}
	}
	return matches;
}


// Initialize the unknown word

void initUnknown (char word[], char unknown[])
{
	int i;
	int length = strlen(word);
	for (i = 0; i < length; i++)
		unknown[i]='*';
	unknown[i]='\0';
}

解决方案

Basically, you don't.
That is a console app, and the Console only supports text.
If you want to use graphics, then you need to look at a Windows application - perhaps a WinForms app?


Typically you use graphics in a Windows GUI application. The development of such kind of application is very different from the one you did (a Console one). You could start reading a tutorial like
"theForger's Win32 API Programming Tutorial"
[^] (this is a kind of 'to the metal' development, you may also check out a framework, like for instance, MFC).


you can output acii art:
(examples) http://chris.com/ascii/
(ascii art generator example) http://www.glassgiant.com/ascii/[^]


这篇关于我如何将图形放入此程序并使用Visual Studio 2012的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆