game improvement

thapchi's Avatar, Join Date: Mar 2010
Go4Expert Member
Well i was just reading a book named c++ primer and got bored so i just wanted to create a c++ consol game

just for some fun

I have created this thing any more idea and some repair in code?

Code:
void welcome()
{
        cout<<"Welcome to the simplest game by thapchi corporations limited";
                cout<<"\n \t \t press enter to continue....";
                getchar();
                system("cls");
                
                
}

int main()
{
        welcome();
        char move;
        char map[49]="**********\n*****j****\n**********\n********** \n";
        cout<<map;
                                         cin>>move;
                                         
                                         
                        if(move=='w')
                        {
                                system("cls");
                                cout<<"****j*****\n**********\n**********\n**********";
                  getchar();
                        }
                        cin>>move;
                        if(move=='a')
                        {   system("cls");
                                cout<<"**j******\n**********\n**********\n**********";
                                getchar();
                        }
                        cin>>move;
                        if(move=='s')
                        {
                                system("cls");
                                cout<<"**********\n**j******\n**********\n**********";
                                getchar();
                        }
                        cin>>move;
                        if(move=='d')
                        {
                                system("cls");
                                cout<<"**********\n******j***\n**********\n**********";
                                getchar();
                        }
                        getchar();
        return 0;
}
well i am a new man in this so any small big help will be appreciated
0
xpi0t0s's Avatar, Join Date: Aug 2004
Mentor
What doesn't it do that you want it to? We can't read your mind.
0
techgeek.in's Avatar, Join Date: Dec 2009
Skilled contributor
I think u r trying to verify the "A", "S", "W", and "D" movement for a game...but what are r trying to build???
0
thapchi's Avatar, Join Date: Mar 2010
Go4Expert Member
i know u cant read my mind LOL

i asked for some improvement

well lets say if i want to move my player with w,a,s,d.

what should i do

this my game just do what i have and it just only moves those four squares does not go anywhere else?

any suggetions
0
virxen's Avatar, Join Date: Nov 2009
Pro contributor
a better way to do this is

Code:
#include <iostream>
#define M 4
#define N 10
using namespace std;
char map[M][N];
int x,y;

void welcome()
{
        cout<<"Welcome to the simplest game by thapchi corporations limited";
                cout<<"\n \t \t press enter to continue....(x=exit)";
                getchar();
                system("cls");
                
                
}
void print_game_board(){
    system("cls");
    for (int i=0;i<M;i++){
           for(int j=0;j<N;j++){
             if (x==i && y==j)
                 cout<<"j";
             else 
                 cout<<map[i][j];
           }
    printf("\n");
    }
}

void create_map(){
    for (int i=0;i<M;i++)
           for(int j=0;j<N;j++)
                   map[i][j]='*';
}
void moveRight(){
    y++;
    if (y>N-1) y=N-1;
    print_game_board();
}
void moveLeft(){
    y--;
    if (y<0) y=0;
    print_game_board();
}
void moveDown(){
    x++;
    if (x>M-1) x=M-1;
   print_game_board() ;
}
void moveUp(){
    x--;
    if (x<0) x=0;
    print_game_board();
}
int main(){
    
        welcome();
        char move='0';
        create_map();
        x=1;y=4;//first position of our character
        print_game_board();
        while (move!='x'){
            cout<<"your move:(w,a,s,d,x):";cin>>move;
            switch(move){
                case 'w':moveUp();
                         break;
                case 'a':moveDown();
                         break;
                case 's':moveLeft();
                         break;
                case 'd':moveRight();
                         break;
            }
            
        }                                 
              cout<<"\nprogram exits!";                           
        return 0;
}