|
i wana help in generating the dice in C language
numbers are generating eandomly but the problem is with image
actually i m making a game of ludo
the code is as follows
it is excuteable code
plzzzz any one can help
#include<<stdio.h>>
#include<<conio.h>>
#include<<iostream.h>>
#include<<graphics.h>>
#include<<math.h>>
#include<<stdlib.h>>
#include<<process.h>>
#include<<dos.h>>
#include<<string.h>>
#include<<malloc.h>>
int mx,my,d,c;
int size;
int dice;
void *dot;
void initgraphics();
void images();
void gen_dice();
int get_dice();
void image1();
void play();
void put_rect();
void images()
{
cleardevice();
//BOUNDARY
setcolor(13);
rectangle(0,0,450,475);
//HOMES
setcolor(14);
circle(90,100,70);
setcolor(4);
circle(360,100,70);
setcolor(2);
circle(90,380,70);
setcolor(1);
circle(360,380,70);
//STAY POINTS FOR YELLOW HOME
setcolor(14);
circle(75,277,10);
circle(75,250,10);
circle(45,250,10);
circle(105,250,10);
circle(135,250,10);
circle(165,250,10);
circle(45,223,10);
//STAY POINTS FOR BLUE HOME
setcolor(1);
circle(285,250,10);
circle(315,250,10);
circle(345,250,10);
circle(375,250,10);
circle(405,250,10);
circle(405,277,10);
circle(375,222,10);
//STAY POINTS FOR GREEN HOME
setcolor(4);
circle(225,50,10);
circle(225,85,10);
circle(225,120,10);
circle(225,155,10);
circle(225,190,10);
circle(255,50,10);
circle(195,85,10);
//STAY POINTS FOR GREEN HOME
setcolor(2);
circle(225,305,10);
circle(225,335,10);
circle(225,365,10);
circle(225,395,10);
circle(225,425,10);
circle(195,425,10);
circle(255,395,10);
//vertical lines for upper path
setcolor(3);
line(180, 0, 180, 210);
line(210,0,210,210);
line(240,0,240,210);
line(270,0,270,210);
//horizontal lines for upper path
line(180,0,270,0);
line(180,35,270,35);
line(180,70,270,70);
line(180,105,270,105);
line(180,140,270,140);
line(180,175,270,175);
line(180,210,270,210);
//vertical lines for lower path
line(180,290,180,475);
line(210,290,210,475);
line(240,290,240,475);
line(270,290,270,475);
//horizontal lines for lower path
line(180,290,270,290);
line(180,320,270,320);
line(180,350,270,350);
line(180,380,270,380);
line(180,410,270,410);
line(180,445,270,445);
line(180,476,270,476);
//vertical lines for left path
line(0,210,0,290);
line(30,210,30,290);
line(60,210,60,290);
line(90,210,90,290);
line(120,210,120,290);
line(150,210,150,290);
line(180,210,180,290);
//horizontal lines for left path
line(0,210,180,210);
line(0,235,180,235);
line(0,265,180,265);
line(0,290,180,290);
//vertical paths for right path
line(270,210,270,290);
line(300,210,300,290);
line(330,210,330,290);
line(360,210,360,290);
line(390,210,390,290);
line(420,210,420,290);
line(450,210,450,290);
//horizontal lines for right paths
line(270,210,450,210);
line(270,235,450,235);
line(270,265,450,265);
line(270,290,450,290);
settextstyle(SANS_SERIF_FONT,0,3);
setcolor(19);
outtextxy(200,235,"LUDO");
getch();
}
void gen_dice()
{
switch (get_dice())
{
case 1: //dice output is 1
put_rect();
putimage(535, 165, dot, COPY_PUT);
put_rect();
break;
case 2: //dice output is 2
put_rect();
putimage(515, 145, dot, COPY_PUT);
putimage(555, 185, dot, COPY_PUT);
put_rect();
break;
case 3: //dice output is 3
put_rect();
putimage(515, 145, dot, COPY_PUT);
putimage(535, 165, dot, COPY_PUT);
putimage(555, 185, dot, COPY_PUT);
put_rect();
break;
case 4: //dice output is 4
put_rect();
putimage(515, 145, dot, COPY_PUT);
putimage(555, 145, dot, COPY_PUT);
putimage(515, 185, dot, COPY_PUT);
putimage(555, 185, dot, COPY_PUT);
put_rect();
break;
case 5: //dice output is 5
put_rect();
putimage(515, 145, dot, COPY_PUT);
putimage(555, 145, dot, COPY_PUT);
putimage(535, 165, dot, COPY_PUT);
putimage(515, 185, dot, COPY_PUT);
putimage(555, 185, dot, COPY_PUT);
put_rect();
break;
case 6: //dice output is 6
put_rect();
putimage(515, 145, dot, COPY_PUT);
putimage(515, 165, dot, COPY_PUT);
putimage(515, 185, dot, COPY_PUT);
putimage(555, 145, dot, COPY_PUT);
putimage(555, 165, dot, COPY_PUT);
putimage(555, 185, dot, COPY_PUT);
put_rect();
break;
}
}
int get_dice()
{
dice=random(6);
if(dice==0)
{
dice++;
}
return (dice);
}
void image1()
{
setcolor(0);
setfillstyle(1, 0);
rectangle(535, 165, 545, 175);
floodfill(540, 170, 0);
size=imagesize(535, 165, 545, 175);
dot=malloc(size);
getimage(535, 165, 545, 175, dot);
//cleardevice();
images();
play();
}
void play()
{
int ch;
again:
ch=getche();
if(ch==13)
{
gen_dice();
goto again;
}
else if(ch==27)
{
exit(0);
}
}
void main(void)
{
clrscr();
initgraphics();
image1();
getch();
}
void put_rect()
{
setcolor(WHITE);
setfillstyle(SOLID_FILL, 15);
rectangle(500, 130, 580, 210);
floodfill(510, 140, 15);
}
|
|
|
|
|
So...Waht is your question?
If the Lord God Almighty had consulted me before embarking upon the Creation, I would have recommended something simpler.
-- Alfonso the Wise, 13th Century King of Castile.
This is going on my arrogant assumptions. You may have a superb reason why I'm completely wrong.
-- Iain Clarke
[My articles]
|
|
|
|
|
how the proper image of the dice can be generated properly??
one image is not replaced by the other image
|
|
|
|
|
Why didn't you report also the initgraphics function (you provided only the prototype)?
Is the compiler happy with two implementations of the same function (gen_dice ) that differ just for the return value type?
If the Lord God Almighty had consulted me before embarking upon the Creation, I would have recommended something simpler.
-- Alfonso the Wise, 13th Century King of Castile.
This is going on my arrogant assumptions. You may have a superb reason why I'm completely wrong.
-- Iain Clarke
[My articles]
|
|
|
|
|
hey man
just see the code carefully
and tell either u can solve the problem or not
i just got problem in generating the dice of image
so kindly tell me either u can do any thing r not
|
|
|
|
|
swtlibra wrote: hey man
just see the code carefully
Hey man I've seen again your code and the initgraphics function definition is still missing.
swtlibra wrote: and tell either u can solve the problem or not
Yes, I can. However, when the request is nice like yours, my rate is 150 euro/hour: can you kindly tell me if you're going to pay such a rate?
If the Lord God Almighty had consulted me before embarking upon the Creation, I would have recommended something simpler.
-- Alfonso the Wise, 13th Century King of Castile.
This is going on my arrogant assumptions. You may have a superb reason why I'm completely wrong.
-- Iain Clarke
[My articles]
|
|
|
|
|
The weirdest thing :
compiling the following C code with gcc (no options) on linux64 :
int main ()<br />
{<br />
unsigned int i,j ;<br />
printf("start");<br />
for (i=j=0;i < UINT_MAX ;i++);<br />
printf("end");<br />
}<br />
<br />
produces a faster binary than this next (leaner) code :
int main ()<br />
{<br />
unsigned int i ;<br />
printf("start");<br />
for (i=0;i < UINT_MAX ;i++);<br />
printf("end");<br />
}
Can someone explain ??
The first code takes around 13-14 seconds on average to run on my machine (dual core AMD64)
the second code takes 14-15 seconds ,on average between 1-2 seconds slower
why would the addition of an extra int (namely j) produce faster code ?
Can you reproduce on your machine ?
|
|
|
|
|
With multiple runs, are the difference in times consistent? I would imagine the compiler would optimize the j variable out since it is not used. You might pose this question to Dr. Newcomer (www.flounder.com), an SME on compilers and optimizers.
"Old age is like a bank account. You withdraw later in life what you have deposited along the way." - Unknown
"Fireproof doesn't mean the fire will never come. It means when the fire comes that you will be able to withstand it." - Michael Simmons
|
|
|
|
|
The runs are consistently faster with j included .
What I noticed when printing the pointer adresses of both ints i and j is that they were aligned and differing 4 bytes (the size of an unsigned int) :
fi. i at adres 0x7fff095efa0c , j at adres 0x7fff095efa08
My machine being a 64 bit processor , might it be that both adresses occupy precisely a single machine-word and therefore optimize the assembly ? Instead of just one int taking half of the registers ?
|
|
|
|
|
I do not have an answer but if I was interested in the question, I would compile with the -S option
which will show me the generated assemble code. By comparing the two assemble language listings,
you should be able to figure out what the differences are.
Bob
|
|
|
|
|
Thanks for your suggestion :
running a diff on the results gave me :
27c27,29
< movl $0, -4(%rbp)
---
> movl $0, -8(%rbp)
> movl -8(%rbp), %eax
> movl %eax, -4(%rbp)
, where the bottom half is the faster code (with an extra declared int )
Perhaps it is so that 8 aligned bytes (4+4) are transferred more rapidly than just the 4 bytes (?+4) using these registers and 64 bit words
|
|
|
|
|
On OS X with a 2.4GHz Core 2 Duo, they give the expected result - i.e. repeatably the same time to within < 0.1% (6ms in 12s). gcc = i686-apple-darwin9 4.0.1.
Java, Basic, who cares - it's all a bunch of tree-hugging hippy cr*p
|
|
|
|
|
Look at the assembly.
Sometimes, an extra variable changes what registry is selected or how the loop is constructed is more amenable to the CPU loop prediction. (I've seen counterintuitive results of code changes that boiled down to both.) You may also be seeing artifacts of load times. Larger code may cause segmentation.
(VC++ will optimize the loop out of existence. Thus any alleged differences in speed are errors in the benchmarking utility.)
Anyone who thinks he has a better idea of what's good for people than people do is a swine.
- P.J. O'Rourke
|
|
|
|
|
Hi,
I did a lot of performance analysis on different processors (mostly for embedded systems) including Intel's x86, but not AMD, and lots of C compilers.
My overall conclusion is there are a lot of factors some of which are difficult to control; one of them is code alignment (the address of the first instruction in a loop being at a multiple of 8 or 16 bytes).
Furthermore there is the issue of instruction scheduling: the CPU has different functional units, some in multiple quantities, and depending on minor details, the instructions get dispatched to some or other units, yielding better or worse performance. Adding an instruction may well lead to a faster piece of code.
The bigger issues however are inside the compiler itself; with standard optimization it should:
1. keep values in registers when there are very few involved (here only i and j);
2. figure out the loop does nothing useful and can be discarded;
3. if the net result of the loop would be some final value (i=UINT_MAX), then it should just assign that, but not in the current case since i and j are dead, their value is not used when the loop is done.
4. and for a real loop, with some body, it should consider "loop unroll".
So my advice is:
- start looking at the compiler switches, make sure you use a normal level of optimization (most of the time I apply several switches, the defaults aren't well chosen if you ask me);
- compare compilers for the kind of code that is most relevant to your app;
- only then start looking at the microscopic level. And get ready for a long learning curve.
Luc Pattyn [Forum Guidelines] [My Articles]
The quality and detail of your question reflects on the effectiveness of the help you are likely to get.
Show formatted code inside PRE tags, and give clear symptoms when describing a problem.
|
|
|
|
|
Hello, I'm writing a MFC application to move a picture control when i press the "Next" button. (Please see screen-captures at following links)
http://i238.photobucket.com/albums/ff191/pumbaboy/before-move.jpg[^]
http://i238.photobucket.com/albums/ff191/pumbaboy/after-move.jpg[^]
There is a dialog box on which there are 2 picture controls. When I press the Next button, the left picture control should move on top of the right picture control.
You can see I kept the code for moving the picture control in a for loop because I wanted a sort of animation effect.
As you can see from the attachments, after I move the image there are some vertical lines appearing. How do I make them go away?
Thank you.
void CShabbirDlg::OnBnClickedButton2()
{
if (pageNum <= 10) {
pageNum++;
CRect RRect, LRect;
picPreview2.GetWindowRect(&RRect);
picPreview.GetWindowRect(&LRect);
for (long int i = LRect.left; i > RRect.left; i -= 20) {
picPreview.MoveWindow(i , LRect.top, LRect.Width(), LRect.Height());
}
}
}
|
|
|
|
|
we need 4 class for an sdi application why we need that application class ??and what is the program flow in a doc view program for an sdi appliction??
|
|
|
|
|
See here.
"Old age is like a bank account. You withdraw later in life what you have deposited along the way." - Unknown
"Fireproof doesn't mean the fire will never come. It means when the fire comes that you will be able to withstand it." - Michael Simmons
|
|
|
|
|
if u can't don't make any rubbish ..i hope u got it
|
|
|
|
|
Bisua wrote: if u can't don't make any rubbish ..i hope u got it
Well, this perfeclty applies to you also: if you can't make a valid question and do not bother reading the posting guidelines, don't make any rubbish post like you just did.
|
|
|
|
|
Bisua wrote: .i hope u got it
While you clearly haven't got it.
If the Lord God Almighty had consulted me before embarking upon the Creation, I would have recommended something simpler.
-- Alfonso the Wise, 13th Century King of Castile.
This is going on my arrogant assumptions. You may have a superb reason why I'm completely wrong.
-- Iain Clarke
[My articles]
|
|
|
|
|
Now guys, perhaps we should be nice and answer the questions...
Question 1
Bisua wrote: we need 4 class for an sdi application why we need that application class ??
Answer:
Guess WE really don't need it (you might) - there are many other ways to write a program (although you may have been told to use it).
Question 2
Bisua wrote: and what is the program flow in a doc view program for an sdi appliction??
Answer:
That all depends on how you write the program.
Karl - WK5M
PP-ASEL-IA (N43CS)
PGP Key: 0xDB02E193
PGP Key Fingerprint: 8F06 5A2E 2735 892B 821C 871A 0411 94EA DB02 E193
|
|
|
|
|
You are not just an idiot, you also have a history of abusive behaviour towards people who actually want to help you but you're too stupid to realize that.
Go away and stop polluting this forum.
|
|
|
|
|
Genius!
|
|
|
|
|
Bisua wrote: we need 4 class
You are kidding right?
Why is common sense not common?
Never argue with an idiot. They will drag you down to their level where they are an expert.
Sometimes it takes a lot of work to be lazy
Individuality is fine, as long as we do it together - F. Burns
Help humanity, join the CodeProject grid computing team here
|
|
|
|
|
I am trying to understand how to write an efficient OnPaint routine. That is, I want my routine
to only update the part of the screen that needs to be updated. Therefore I wrote a simple program
that creates a window and displays three lines. Below is the OnPaint routine for that program:
void<br />
CMainWindow::OnPaint()<br />
{<br />
CPaintDC dc(this);<br />
<br />
RECT rect1;<br />
BOOL retValue = GetUpdateRect( &rect1 );<br />
if ( retValue != 0 ) {<br />
char *ptr = 0;<br />
*ptr = 23;<br />
}<br />
dc.BitBlt( 0, 0, maxX, maxY, &m_memDC, 0, 0, SRCCOPY );<br />
}
The code works but the routine GetUpdateRect always returns 0. I am wondering if the only way to
get GetUpdateRect to return non-zero is if the program sends (via something like SendMessage)
the WM_PAINT message.
You should also observe that in the current code, if GetUpdateRect does return a non-zero value
then the program crashes. Currently, the program never crashes.
Bob
|
|
|
|
|