0
I and a colleague are beginners in programming and we are building a game in which we need to use chained list. He was responsible for creating a game menu using chained list and I for creating the game. Only now we need to put the codes together and it turns out we’re not making it.
I need a huge help from you guys to know how I make the game behave this way. In the Menu created the user will insert the words in the list using option 1, after the words are inserted the user enters option 4 and the game makes a Random of the inserted words and puts in the game to be discovered.
#include <stdio.h>
#include <stdlib.h>
#include <conio.h>
#include <string.h>
#include <time.h>
struct no
{
char info[15];
struct no*prox;
};
typedef struct no Lista;
void jogo() {
char palavra[25],letra[25],lacuna[25];
int vida=6,x=0,i,u,total=0,cont=0;
printf(" ******************************");
printf("\n JOGO DA FORCA \n");
printf(" ******************************\n");
printf("\n BOM JOGO\n\n");
printf("\nDIGITE A PALAVRA E TECLE ENTER PARA CONTINUAR");
printf("\n\nPALAVRA: ");
gets(palavra);
fflush(stdin);
system("cls");
for(i=0;i<strlen(palavra);i++)
{
lacuna[i]='X';
total++;
cont++;
}
while(vida>0)
{
printf("\nA PALAVRA COMTEM %i LETRAS\n",total);
printf("\nLETRAS RESTANTES: %i\n",cont);
printf("\n%s\n",lacuna);
printf("\nENTRE COM UMA LETRA: ");
gets(letra);
system("cls");
for(i=0;i<strlen(palavra);i++)
{
for(u=0;u<strlen(palavra);u++){
if(letra[u]==palavra[i])
{
lacuna[i]=palavra[i];
x++;
cont--;
}
}
}
if(cont==0){
printf("PARABENS! VOCE VENCEU!");
printf("\nACERTOU A PALAVRA %s", palavra);
}
if(x==0)
{
vida--;
printf("\nVOCE PERDEU UMA VIDA!\nVOCE TEM %d VIDA(S)
RESTANTES\n\n",vida);
}
x = 0;
}
printf("\n\nVC FOI ENFORCADO, Fim de jogo!\n\n\nPALAVRA SECRETA:
%s",palavra);
printf("\n\n***********************\n\n");
printf("* JOGO DA FORCA *\n\n");
printf(" ___ \n");
printf(" | | \n");
printf(" | O \n");
printf(" |/|\ \n");
printf(" | | \n");
printf(" |/ \ \n");
printf(" |______ \n");
printf("\n**********************\n");
getchar();
getchar();
}
void cria (Lista **L)
{
*L=NULL;
}
void Ins_Inicio (Lista **L, char v[15])
{
Lista *p = (Lista *) calloc (1, sizeof(Lista));
strcpy(p->info, v);
p->prox=*L;
*L = p;
}
void imprime (Lista *L)
{
Lista*p;
p=L;
while (p != NULL)
{
printf("%s-->", p->info);
p=p->prox;
}
printf("NULL\n");
}
void jogar (Lista *L)
{
int num, total_nos=0;
Lista *p;
p=L;
while (p!=NULL)
{
total_nos++;
p=p->prox;
}
int rand();
num = rand()+ (total_nos)+1;
while (p != NULL)
{
}}
main()
{
char palavra[25],letra[25],lacuna[25];
int vida=6,x,i;
Lista *L;
int op, ret, fim;
char val[15];
cria(&L);
do
{
int clrscr();
puts("1 - Insere palavras no INICIO da lista");
puts("2 - Remove palavras da lista");
puts("3 - IMPRIMIR a lista");
puts("4 - Jogar");
puts("5 - Sair");
puts("\nDigite a opcao desejada");
scanf("%d", &op);
switch(op)
{
case 1: puts("Digite o valor a ser inserido:");
fflush(stdin);
gets(val);
Ins_Inicio(&L,val);
break;
case 2: puts("Digite o valor a ser removido");
fflush(stdin);
gets(val);
break;
case 3: imprime(L);
getch();
break;
case 4: jogar(L);
jogo();
break;
}
}
while(op!=5);
}
Here is an offtoic recognition: if you want to learn "C" - stand firm on the path you have chosen. If you want to learn "programming" and do this by creating games-like programs that are playable on the way - I recommend using another language - more "high-level" (this is not pejorative, it’s just a way of classifying languages) - like Python, Javascript, or Ruby.
– jsbueno
I disagree @jsbueno. Making a game for a language you are learning is a great way to test your knowledge.
– Francisco
Hi Francisco - so you agree with me - see what I wrote: "if you want to learn C, keep on going". My observation is that if they want to learn to program codes of the type of this game, but can be with a language that facilitates this.
– jsbueno
@jsbueno It’s easier to become a PP or PC than to study C!!!
– user83187