473,413 Members | 1,718 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,413 software developers and data experts.

how to make it possible for my ball to move in a line till it reaches the empty space

i am having problem while making this game similar to rapid roll it is a basic concept what i want is at the end of this code where an the logic of detecting the space by the ball to fall down when it reaches an empty space is written here is my code move the ball my pressing a and d the code is written in visual studio 10 c++ file.there is a lot of problem in the end where if statement is written that i==5 etc kindly help me correcting this.


Expand|Select|Wrap|Line Numbers
  1. #include<conio.h>
  2. #include<time.h>
  3. #include<windows.h>
  4. #include<iostream>
  5. using namespace std;
  6.  
  7. void gotoxy (int x,int y){
  8.     COORD coord; // coordinates
  9.     coord.X = x; coord.Y = y; // X and Y coordinates
  10.     SetConsoleCursorPosition(GetStdHandle(STD_OUTPUT_HANDLE), coord);} // moves to the coordinates
  11.  
  12. int main()
  13. {
  14.     srand(time(0));
  15.     int i, now , max, min, score,h,count,n,roll1,x1,x,print,num;
  16.     //int arr[4]={0};
  17.     int arr[24]={0};
  18.    num=0;
  19.     count = 0;
  20.     print=0;
  21.         x1=0;
  22.     h=3;
  23.     n=0;
  24.     score=0;
  25.     min = 2;
  26.     max = 22;
  27.      i = now = 3;
  28.      char search='w';
  29.  
  30.      now = (clock()/1000);
  31.  
  32.      while(now<=59 && search!=27){
  33.             now = (clock()/1000);
  34.  
  35.  
  36.             system("cls");
  37.  
  38.             cout<<"********************\n";
  39.             cout<<"******BALL GAME*****\n";
  40.             cout<<"********************\n";
  41.  
  42.  
  43.             if (i==19)
  44.                 {
  45.                     i=3;
  46.                     score+=10;
  47.  
  48.             }
  49.  
  50.  
  51.  
  52.  
  53.  
  54.  
  55.             if(i==3)
  56.             {i=5;
  57.                 for(int num1=0;num1<6;num1++)
  58.                 {
  59.                     for(int num3=0;num3<4;num3++)
  60.                         {
  61.                 roll1=(rand()%2);
  62.                 arr[count]=roll1;
  63.                 count++;                
  64.                 if(count==24)
  65.                     count=0;
  66.                     }
  67.                 }
  68.             }
  69.  
  70.                 for(int num1=0;num1<6;num1++)
  71.                 {    
  72.                     cout<<endl<<endl;
  73.               x1=0;
  74.             for(int num3=0;num3<4;num3++)
  75.             {
  76.  
  77.                 x1=x1+arr[print];
  78.  
  79.                 if(arr[print]==0)
  80.                 {
  81.                     cout<<"     ";
  82.                         print++;
  83.                 }
  84.                 else if(arr[print]==1)
  85.                 {
  86.                     cout<<"_____";
  87.                         print++;
  88.                 }
  89.                 }if(print==24)
  90.                     print=0;
  91.                 /*else if (x1>=3)
  92.                 {cout<<"    ";}*/
  93.             }
  94.  
  95.  
  96.             //Sleep(1000);
  97.  
  98.             gotoxy(h,i);
  99.            cout<<"O";
  100.  
  101.             gotoxy(0,19);
  102.             cout<<"_________________________";
  103.  
  104.             gotoxy(0,19);
  105.             cout<<"\nScore:"<<score;
  106.  
  107.             gotoxy(16,20);
  108.             cout<<"Esc(QUIT)";
  109.  
  110.             gotoxy(16,21);
  111.             cout<<"Time:"<<(now)<<"secs";
  112.  // Sleep(300);
  113.  
  114. //            Sleep(1080);    
  115.  
  116.             if(i==5||(i==7)||(i==9)||(i==11)||(i==13)||(i==15)||(i==17))
  117.             {
  118.  
  119. if(arr[num]==1 && 0<h && h<=5)
  120.  
  121.         {    {
  122.             Sleep(33);
  123.  
  124.             search=getch();
  125.             if (search=='a' && h>1 )
  126.             { h--;
  127.             }
  128.             else if(search=='d' &&h<21 )
  129.                     { h++;
  130.             }num++;}
  131.             }
  132.  
  133.          else if (arr[num]==0 &&  0<=h && h<=5) 
  134.                        { 
  135.                 Sleep(127);
  136.                 i++;
  137.                 num++;
  138.             if(n==18)
  139.                 n=0;}
  140.  
  141.             if(arr[num]==1 && (5<=h<=10))
  142.                 {    {
  143.             Sleep(3);
  144.  
  145.             search=getch();
  146.             if (search=='a' && h>1 )
  147.             { h--;
  148.             }
  149.             else if(search=='d' &&h<21 )
  150.                     { h++;
  151.             }num++;}
  152.             }
  153.  
  154.          else if (arr[num]==0 ) 
  155.                        { 
  156.                 Sleep(7);
  157.                 i++;
  158.                 num++;
  159.             if(n==18)
  160.                 n=0;}
  161.     }
  162.  
  163.  
  164.             else if(i!=5)
  165.                 i++;
  166.  
  167.             }
  168.  
  169. return 0;
  170. }
May 26 '13 #1
2 1453
weaknessforcats
9,208 Expert Mod 8TB
There is not a single comment describing what your algorithm is or what your game board looks like.

Usually, you clear the screen and display your game board, then move your token and redisplay the game board. If you do this in a loop you get images in succession as in the movies.

The game board is an array that is displayed.

The array is usually an array of structs where one member has a value for blank/not blank. So you sense a non-blank position by the value of the struct member and not by it's position in the array.
May 26 '13 #2
donbock
2,426 Expert 2GB
Do you want to have true-to-life motion?
  • x- and y-axis motion is independent.
  • y-axis motion is subject to acceleration due to gravity
May 29 '13 #3

Sign in to post your reply or Sign up for a free account.

Similar topics

2
by: SP | last post by:
I've production sql server 7 sp3 on windows NT. I had a 8GB data file of which 5GB were used and 3GB were unused. I wanted to take back the unused 3GB. So I did the following with EM GUI: 1. I...
3
by: Clark Spencer | last post by:
I have built a small integration app using VS .NET 2003 that extracts orderinformation from a 'webshop'. Extracting the orderinformation works fine. Appending the order elements in the...
4
by: Andrei Pociu | last post by:
I use a Repeater which displays values from a DataReader (which gets them from a SQL DB). Everytime I'm using: <%#DataBinder.Eval(Container.DataItem, "ColumnName")%> ....in the HTML code to...
3
by: Husam | last post by:
Hi EveryBody: I made project by Vb.Net which consist the following items: 1\ Textbox 2\Button 3\Listbox When you write any thing in the textbox and press the button any text written in...
1
by: Rico | last post by:
Hello, I have a database in 2005 that I'd like to copy and attach in 2000. Is this possible? if so, how do I do it? I've tried doing a number of things from just trying to attach to the db...
2
TMS
by: TMS | last post by:
Schools over!!! Now its time to play. I would like to learn how to make objects move from one location to the next on a canvas widget. For example: from Tkinter import * class square:...
0
by: Blue203 | last post by:
I am trying to make a div scroll box that holds code for a "banner" in text form (so that other people can copy it and repost it). I have the box made and the code inside works, however the problem...
3
by: Raj Kumar | last post by:
hi i am a begineer in javascript... is it possible to move image one page to next page using drag and drop
2
by: Smurfas | last post by:
Hi, I have another problem. I char converter to string = variable; , and now string text end is empty place. I must new string(variable) plus word: "end"; Very simple: a = variable + "end"; But...
1
by: Kelly K | last post by:
I am trying to send out letters. PhysicianName PrimaryHospital Address1 Address2 Address3 CityStateZipCode Some of the fields are blank (example: address3 tends to be blank unless there is...
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...
0
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However,...
0
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can...
0
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers,...
0
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows...
0
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each...
0
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing,...
0
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome a new...
0
by: conductexam | last post by:
I have .net C# application in which I am extracting data from word file and save it in database particularly. To store word all data as it is I am converting the whole word file firstly in HTML and...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.