GeekInterview.com
   Home |  Tech FAQ  |   Interview Questions |  Placement Papers |  Tech Articles |  Learn |  Freelance Projects |  Online Testing |  Geeks Talk |  Job Postings |  Knowledge Base | Site Search |  Add/Ask Question

GeekInterview.com  >  Interview Questions  >  Programming  >  C
Go To First  |  Previous Question  |  Next Question 
 C  |  Question 420 of 437    Print  
how to program a scrabble game?

  
Total Answers and Comments: 1 Last Update: July 17, 2008     Asked by: ronix123 
  
 Sponsored Links

 
 Best Rated Answer

No best answer available. Please pick the good answer available or submit your answer.
July 17, 2008 10:49:39   #1  
zoyarasul Member Since: July 2008   Contribution: 1    

RE: how to program a scrabble game?

#include<stdio.h>
#include<stdlib.h>
#include<conio.h>
#include<graphics.h>
#include<dos.h>
#include<alloc.h>
#include<process.h>
union REGS in,out;
void *buf;
int size,count=0,px,py,rnd[4][4],correct=0;

float octave [7]={130.81,146.83,164.81,174.61,196,220,246.94};

int callmouse()
{    in.x.ax=1;
     int86(51,&in,&out);
     return 1;

}
void mouseposi(int &xpos,int &ypos,int &click)
{   in.x.ax=3;
    int86(51,&in,&out);
    click=out.x.bx;
    xpos=out.x.cx;
    ypos=out.x.dx;
    return ;
}
int  mousehide()
{
   in.x.ax=2;
   int86(51,&in,&out);
   return 1;
}
void done(void)
{
   int i,j;
   mousehide();
   j=0;
   int n;
   for(i=1;i<=15;i++)
   {
      n=random(7);
     sound(octave[n]*4);
      delay(300);
      setfillstyle(1,2);
      bar(42+j,425,68+j,455);
      setfillstyle(1,0);
      bar(68+j,425,72+j,455);
      j=j+29;
   }
   nosound();
   delay(1000);
   for(j=0;j<382;j+=2)
   {
     for(i=0;i<575;i+=2)
     {
    putpixel(26+i,25+j,4);
    putpixel(26+i,460-j,4);
    putpixel(25+j*3/4,28+i*3/4,2);
    putpixel(595-j*3/4,458-i*3/4,2);
    delay(0);
     }
   }
   delay(1000);
   settextstyle(1,0,5);
   setcolor(14);

   outtextxy(320,300,"http://electrofriends.com");
   outtextxy(321,300,"http://electrofriends.com");
   delay(500);
   getch();
   exit(0);
}
checknum(int mat[4][4])
{
   int k=0,i,j;
   correct=0;
   for(i=0;i<=3;i++)
   {
     for(j=0;j<=3;j++)
     {
    k++;
    if(k==mat[i][j])
       correct++;
     }
   }
   gotoxy(10,11);
   printf("NUMBERS ARE IN CORRECT POSITION IS ..: %d  ",correct);
   if(correct==15)
   {
      bar(130,40,480,80);
      settextstyle(1,0,4);
      outtextxy(300,60,"CONGRAGULATIONS !");
      done();
   }
   else
   {
      bar(20,415,480,463);
      j=0;
      for(i=1;i<=correct;i++)
      {
     setfillstyle(1,1);
     bar(42+j,425,68+j,455);
     setfillstyle(1,0);
     bar(68+j,425,72+j,455);
     j=j+29;
      }
   }
   return 0;
}

void  move(int &a,int &b,int &c,int &d,int &w,int &x,int &y,int &z,int &num)
{
   if(a>192 && b>190 && c<403 && d<404)
   {
      sound(600);
      count++;
      gotoxy(10,9);
      printf("NUMBER OF MOVES..: %d   ",count);
      mousehide();
      size=imagesize(a,b,c,d);
      free(buf);
      buf=malloc(size);
      getimage(a,b,c,d,buf);
      bar(a,b,c,d);
      putimage(w,x,buf,COPY_PUT);
      w=a;
      x=b;
      y=c;
      z=d;
      if(num==1)
      {
     rnd[px][py]=rnd[px+1][py];
     rnd[px+1][py]=0;
     px++;
      }
      else if(num==2)
      {
     rnd[px][py]=rnd[px-1][py];
     rnd[px-1][py]=0;
     px--;
      }
      else if(num==3)
      {
     rnd[px][py]=rnd[px][py+1];
     rnd[px][py+1]=0;
     py++;
      }
      else if(num==4)
      {
     rnd[px][py]=rnd[px][py-1];
     rnd[px][py-1]=0;
     py--;
      }
      checknum(rnd);
      callmouse();
      delay(40);
      nosound();
   }
   return ;
}

main()
{
   int a1,b1,cl,a,b,c,d,w,x,y,z,key,p=0,q=0;
   int g=DETECT,m,ext=0,rst=0,rx,ry,num,i,j;
   initgraph(&g,&m,"c:\TC\bgi");
   randomize();
   gotoxy(50,9);
   printf("http://electrofriends.com");

   do
   {
   correct=0;
   count=0;
   gotoxy(10,9);
   printf("NUMBER OF MOVES..: %d   ",count);

   gotoxy(10,11);
   printf("NUMBERS ARE IN CORRECT POSITION IS ..: %d  ",correct);
   setfillstyle(SOLID_FILL,4);
   setcolor(15);
   for(j=200;j<360;j+=50)
   {
     for(i=200;i<365;i+=50)
     {
       rectangle(j-1,i-1,j+46,i+46);
       bar(j,i,j+45,i+45);
     }
   }
   rectangle(192,190,403,404);
   settextstyle(1,0,3);
   for(i=0;i<=3;i++)
   {
     for(j=0;j<=3;j++)
     {
    rnd[i][j]=0;
     }
   }
   for(i=0;i<=15;i++)
   {
     do
     {
    rx=random(4);
    ry=random(4);
     }  while(rnd[rx][ry]);
     rnd[rx][ry]=i;
   }
   char ab[10];
   settextjustify(CENTER_TEXT,CENTER_TEXT);
   q=p=0;
   for(i=0;i<=3;i++)
   {
     for(j=0;j<=3;j++)
     {
       if(rnd[i][j]!=0)
       {
      sprintf(ab,"%d",rnd[i][j]);
      outtextxy(225+p,217+q,ab);
       }
       else
       {
      setfillstyle(1,0);
      px=i;py=j;
      bar(199+p,199+q,247+p,247+q);
      w=199+p;
      x=199+q;
      y=247+p;
      z=247+q;
       }
       p+=50 ;
     }
     p=0;
     q+=50 ;
   }
   bar(130,40,480,80);
   bar(10,425,480,455);
   setfillstyle(SOLID_FILL,4);
   rectangle(534,374,591,411);
   bar(535,375,590,410);
   outtextxy(561,390,"EXIT");
   rectangle(484,419,591,456);
   bar(485,420,590,455);
   outtextxy(538,433,"RESTART");
   setcolor(4);
   rectangle(10,10,610,470);
   rectangle(15,15,605,465);
   setcolor(14);
   rectangle(12,12,607,467);
   settextstyle(1,0,4);
   outtextxy(300,60,"SHUFFLE GAME");
   line(150,85,450,85);

   j=0;
   delay(1500);
    int n;
   for(i=1;i<=15;i++)
   {
     n=random(7);
     sound(octave[n]*4);
     delay(300);
     setfillstyle(1,2);
     bar(42+j,425,68+j,455);
     setfillstyle(1,0);
     bar(68+j,425,72+j,455);
     j=j+29;
   }
   nosound();
   setfillstyle(SOLID_FILL,0);
   bar(30,425,480,455);
   settextstyle(2,0,5);
   outtextxy(250,425,"YOU CAN USE ARROW BUTTONS OR MOUSE TO MOVE BLOCKS.");
   outtextxy(250,450,"      PRESS ANY KEY TO START........" );



   getch();
   bar(20,415,480,463);
  callmouse();
   do
   {
      gotoxy(10,20);
      mouseposi(a1,b1,cl);
      if(a1>w && a1<y && b1>x+50 && b1<z+50 && cl==1)
     {
       num=1;
       move(w,x+50,y,z+50,w,x,y,z,num);                   //up
     }
      if(a1>w && a1<y && b1>x-50 && b1<z-50 && cl==1)
     {
       num=2;
       move(w,x-50,y,z-50,w,x,y,z,num);              //down
     }
      if(a1>w+50 && a1<y+50 && b1>x && b1<z && cl==1)
     {
       num=3;
       move(w+50,x,y+50,z,w,x,y,z,num);                   //left
     }
      if(a1>w-50 && a1<y-50 && b1>x && b1<z && cl==1)
     {
       num=4;
       move(w-50,x,y-50,z,w,x,y,z,num);                   //right
     }
      if(kbhit())
      {
    key=getch();
    switch(key)
    {
      case 72: num=1;
           move(w,x+50,y,z+50,w,x,y,z,num);           //up
           break;
      case 80: num=2;
           move(w,x-50,y,z-50,w,x,y,z,num);           //down
           break;
      case 75: num=3;
           move(w+50,x,y+50,z,w,x,y,z,num);          //left
           break;
      case 77: num=4;
           move(w-50,x,y-50,z,w,x,y,z,num);          //right
           break;
    }
      }

      if((a1>535 && a1<590 && b1>375 && b1<410 && cl==1) || key==27)
     done();
     rst=0;
      if(a1>485 && a1<590 && b1>420 && b1<455 && cl==1 )
      rst=1;
   } while(rst==0);
  } while(rst!=0);
  closegraph();
}

 
Is this answer useful? Yes | No

 Related Questions

A goto statement implements a local jump of program execution, and the longjmp() and setjmp() functions implement a nonlocal, or far, jump of program execution. Generally, a jump in execution of any kind 
Latest Answer : using the normal goto statement we can move only within the function. it is not possible to go from one function to another function.using setjmp and longjmp you can move from one function to another function. but it is very bad programming. since the ...

Some operating systems (such as UNIX or Windows in enhanced mode) use virtual memory. Virtual memory is a technique for making a machine behave as if it had more memory than it really has, by using disk 
Latest Answer : Page size you have to choose as per the requirement. If you choose page size big then processing of page fault takes more time but if you choose page size small then there is possibility that more number of page fault occures but processing time of page ...

The register modifier hints to the compiler that the variable will be heavily used and should be kept in the CPU’s registers, if possible, so that it can be accessed faster. There are several restrictions 
Latest Answer : If a variable is defined by using register modifier it tells to the compiler that the variable is used repetedly and that variable executes fastly. Generally register variables are defined in loop counters. This variable stored in CPU registers and access ...

The volatile modifier is a directive to the compiler’s optimizer that operations involving this variable should not be optimized in certain ways. There are two special cases in which use of the 

A type cast should not be used to override a const or volatile declaration. Overriding these type modifiers can cause the program to fail to run correctly. A type cast should not be used to turn a pointer 
Latest Answer : we should not cast the big datatype to smaller one. Like from double to float long to integer. TIn these cases there will be chance of loosing the valuable data itself. ...

A sorting program that sorts items that are on secondary storage (disk or tape) rather than primary storage (memory) is called an external sort. Exactly how to sort large data depends on what is meant 
Latest Answer : Any how after merging that it will create the same problem to sort out. Will you please explain about that? ...

Most operating systems, including DOS, provide a means to redirect program input and output to and from different devices. This means that rather than your program output (stdout) going to the screen; 
Latest Answer : By using the operators "" we can redirect the standard input and out streams.example : d:> jinto.exe > outputredirected                d:> ...

The preceding example showed how you can redirect a standard stream from within your program. But what if later in your program you wanted to restore the standard stream to its original state? By using 
Tags : Restore

Your C compiler library contains a low-level file function called sopen() that can be used to open a file in shared mode. Beginning with DOS 3.0, files could be opened in shared mode by loading a special 

By using the sopen() function you can open a file in shared mode and explicitly deny reading and writing permissions to any other program but yours. This task is accomplished by using the SH_DENYWR shared 


 Sponsored Links

 
Related Articles

Concepts of Object-Oriented Programming

Object Oriented JavaScript In this chapter you ll learn about OOP Object Oriented Programming and how it relates to JavaScript As an ASP NET developer you probably have some experience working with objects and you may even be familiar with concepts such as inheritance However unless you re already a
 

How to develop compile and run a C program

The steps involved in building a C program are: 1. First program is created by using any text editor and the file is stored with extension as .c 2. Next the program is compiled. There are many compilers available&nbsp;like GNU C compiler called as gcc, Sun compiler, Borland compiler which is pop
 

SQL Programming

SQL Programming Overview Anybody who has done something for a long time has probably wanted to change how things work at some point or another. A worker at a mill might have found a more efficient way of cutting logs, or a mathematics teacher might have had a hand in changing a school&rsquo;s al
 

The Interview Snafu

How to turn someone else&rsquo;s mistake to your advantage Your dream job is about to become reality. A recruiter gave you the heads up about the perfect position at Humungous Conglomerate, Inc. You went through five interviews as well as a battery of psychological tests mandated by their HR de
 

Winning a Job Interview with a Winning Resume

Does your resume unlock your potential, take your skills to the highest level and win you the interview and the job you want now? The job market today is highly competitive and even if you think you have what it takes to get an interview you won&rsquo;t get over the line without a polished, prof
 

WinRunner Programming Concepts

If you want to create WinRunner scripts that are highly efficient, there are important programming concepts that you will want to become familiar with. Understanding these concepts will provide you with a large number of key benefits. In addition to understanding these concepts, you must also learn
 

Programming Languages Certification

IT Certification programs have several options that will offer you the best knowledge.&nbsp; By learning everything that you need to know about information technology you will be able to open new doors to your career and personal business desires.&nbsp; IT Certification offers several vari
 

Neuro-linguistic Programming Methods

Neuro linguistic Programming Methods There are several methods used for performing Neuro linguistic Programming on an individual for obtaining insights into the psyche of the person in order to correct to modify certain patterns of behavior These techniques are also used for Neuro linguistic trainin
 

Importance of Proper English during Job Interview

Importance of Proper English during Job Interview Your job interview is crucially important and it will determine whether or not you will get the job Depending on the type of job you re going for it is very important for you to use proper English In most cases jobs which offer higher salaries will h
 

The Difficult Past of Neuro-linguistic programming

The Difficult Past of Neuro linguistic programming Neuro linguistic programming has had a rocky past with a number of lawsuits rivalry unsystematic development and intermittent progress During the 1980s the two founders separated after the lawsuit filed by Bandler Bandler went on to file several law
 

Sponsored Links

 




About Us  |   Privacy Policy  |   Terms and Conditions  |   Contact  |   Site Map  |   Add Question  |   Propose Category  |   RSS Feeds  |   Articles Sitemap  |   Site Updates  |   Add Resource

Copyright © 2005 - 2008 GeekInterview.com. All Rights Reserved
Page copy protected against web site content infringement by Copyscape