Candy Crush type game in C

Started by
16 comments, last by shadowisadog 10 years, 4 months ago

Hi guys,
I'm a first semester student of Programming and I have an assignment where I have to design a game somewhat like candy crush, called number crush where instead of candy, when 3 numbers are aligned, you get a point. and the numbers disappear.

I have to use C to design the game.
can anyone please help me?

Advertisement

Moving you to our For Beginners forum, as this questions seems to be more about developing (creating) the game than game-play design.

Have you learned how to write output to the command console, and do you know how to collect input from the user?

Have you been given any libraries or starting code to use?

What have you tried to start with?

- Jason Astle-Adams

we were given an .exe file and were told to model our game on it.
can you check the game out and assist me in writing the code for it?

We were just given a compiled C code in .exe format and a word file explaining vaguely what to do and we were asked to model our game on it.
I've only gotten as far as the code i've shown below.


#include <time.h>
#include <math.h>
#include <stdio.h>
#include <conio.h>
#define ROW 10
#define COL 10
int x,y;

int main()
{
 int r=1;
 int arr[ROW][COL];
 char name[20];
 printf("-------NUMBER CRUSH-------\n***************************\n\n");
 printf("Enter your name: ");
 scanf("%c", &name);
 system("cls");
 r=1;
 while(r=1)
 {
  printf("-------NUMBER CRUSH-------\n***************************\n\n");
  printf("Welcome %c, LET'S PLAY!!\n\n", name);
  initialize(arr);
  printf("\n\n");
  printf("to regenerate the array press 1: ");
  scanf("%i", &r);
  system("cls");
 }
 return 0;
}

/*define grid and populate with random numbers and print to screen*/
int initialize(int grid[ROW][COL])
{
 int n;
 srand(time(NULL));
 for(x=0;x<10;x++)
 {
  for(y=0;y<10;y++)
  {
   n=2+rand()%7;
   grid[x][y]=n;
   printf("%d    ", n);
  }
  printf("\n\n\n");
 }
 return 0;
}
Being that this is a school assignment we can not write the code. That is not how you learn.
How about instead you ask specific questions about issues you have and we try our best to better explain the concepts.

i do not want you to write the entire code, just guide me in the right direction.
I will post new portions of the code as i'm done writing them and I would appreciate it if you could take a look and point me in the right direction.

can you do that?


 r=1;
 while(r=1)
 {
  printf("-------NUMBER CRUSH-------\n***************************\n\n");
  printf("Welcome %c, LET'S PLAY!!\n\n", name);
  initialize(arr);
  printf("\n\n");
  printf("to regenerate the array press 1: ");
  scanf("%i", &r);
  system("cls");
 }

right now i'm having trouble with this portion of the code.
the loop is only supposed to work if i press 1, otherwise if i press anything else it should terminate but that is not happening.
can you tell me where i'm going wrong?

Possibly because


while(r=1)
is assigning 1 to r. Instead you might want to use:


while(r==1)
http://tinyurl.com/shewonyay - Thanks so much for those who voted on my GF's Competition Cosplay Entry for Cosplayzine. She won! I owe you all beers :)

Mutiny - Open-source C++ Unity re-implementation.
Defile of Eden 2 - FreeBSD and OpenBSD binaries of our latest game.

also i can not get the 1D array called name to store the complete string.
it is supposed to store the complete string which is entered using the scanf command and stored in the name array

it just displays some random ASCII character instead of the whole string.
what am i doing wrong here?


char name[20];
printf("-------NUMBER CRUSH-------\n***************************\n\n");
printf("Enter your name: ");
scanf("%c", &name);
system("cls");
r=1;
while(r=1)
{
printf("-------NUMBER CRUSH-------\n*************
You need to change the 4th line to:

scanf("%s", &name);
Using %c will only read a single character, not a complete string.

You can use this page as a reference for format specifiers: http://www.cplusplus.com/reference/cstdio/printf/

This topic is closed to new replies.

Advertisement