help with moving

Mar 14, 2013 at 7:14pm

here is my question
I want to make a ball move anywhere on the map but I can only make it move forward can anyone write a step back,left and right so that i can make it move everywhere here is the code:


1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
#include <cstdlib>
#include <iostream>

using namespace std;

int main(int argc, char *argv[])
{
int a
//all up movement begining
;cout<<"\nI\nI\nI\nI\nI\nI\nI\nI\nI\nI o\n"
;cin>>a        
;if(a==1){
cout<<"\nI\nI\nI\nI\nI\nI\nI\nI\nIo\nI \n"
;cin>>a
;if(a==1){
cout<<"\nI\nI\nI\nI\nI\nI\nI\nIo\nI\nI \n"
;cin>>a
;if(a==1){
cout<<"\nI\nI\nI\nI\nI\nI\nIo\nI\nI\nI \n"
;cin>>a
;if(a==1){
cout<<"\nI\nI\nI\nI\nI\nIo\nI\nI\nI\nI \n"
;cin>>a
;if(a==1){
cout<<"\nI\nI\nI\nI\nIo\nI\nI\nI\nI\nI \n"
;cin>>a
;if(a==1){
cout<<"\nI\nI\nI\nIo\nI\nI\nI\nI\nI\nI \n"
;cin>>a
;if(a==1){
cout<<"\nI\nI\nIo\nI\nI\nI\nI\nI\nI\nI \n"
;cin>>a
;if(a==1){
cout<<"\nI\nIo\nI\nI\nI\nI\nI\nI\nI\nI \n"
;cin>>a
;if(a==1){
cout<<"\nIo\nI\nI\nI\nI\nI\nI\nI\nI\nI \n"
;}
;}
;}
;}
;}
;}
;}
;}
;}

//all up movement end
    system("PAUSE");
    return EXIT_SUCCESS;
}
Mar 14, 2013 at 7:29pm
Your code is too static. Using this code, if you used variable 'a' as a determining factor of where the ball is at some point in time, this would be extremely inefficient.

You need to assign a multidimensional array with each axis of movement in space. Have one for X (horizontal) y (verticle), you don't need depth for non 3D project, I'm assuming. This will allow for up down left and right movement.

 
char ballCourt[10] [10];


Then just use for loops to assign the correct character to ballCourt (looks like your using 'O') for where the position of the ball is suppose to be, and blank spaces or a symbol (it looks like your using I) to represent each unit of space for the field of play or "ballCourt"
Last edited on Mar 14, 2013 at 7:33pm
Mar 14, 2013 at 7:42pm
You can us an empty space as well like ' '
Last edited on Mar 15, 2013 at 6:42am
Mar 14, 2013 at 8:31pm
TZ3x. Don't hijack somebody's thread.
Mar 15, 2013 at 10:26am
@RACAST how do I assing an array whats an array? Yes i am using O as the ball and I as an unit of space
Mar 15, 2013 at 3:06pm
http://www.cplusplus.com/doc/tutorial/arrays/

I suggest you read up on array's. They are a powerful type of variable that allows you to store an almost endless amount of values, separated by creating an inner element for each one, in which all can be accessed by a unique index number or name
Last edited on Mar 15, 2013 at 3:07pm
Mar 15, 2013 at 6:41pm
yeah but how do I use them in this program?
Mar 15, 2013 at 8:32pm
Look at this: http://www.cplusplus.com/forum/general/94461/
It is different from your code, but you should be able to understand everything :)
Topic archived. No new replies allowed.