1. We have moved from vBulletin to XenForo and you are viewing the site in the middle of the move. Though the functional aspect of everything is working fine, we are still working on other changes including the new design on Xenforo.
    Dismiss Notice

game improvement

Discussion in 'C++' started by thapchi, Mar 13, 2010.

  1. thapchi

    thapchi New Member

    Joined:
    Mar 9, 2010
    Messages:
    11
    Likes Received:
    0
    Trophy Points:
    0
    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
     
  2. xpi0t0s

    xpi0t0s Mentor

    Joined:
    Aug 6, 2004
    Messages:
    3,012
    Likes Received:
    203
    Trophy Points:
    0
    Occupation:
    Senior Support Engineer
    Location:
    England
    What doesn't it do that you want it to? We can't read your mind.
     
  3. techgeek.in

    techgeek.in New Member

    Joined:
    Dec 20, 2009
    Messages:
    572
    Likes Received:
    17
    Trophy Points:
    0
    Occupation:
    EOC (exploitation of computers)..i m a Terminator.
    Location:
    Not an alien!! for sure
    Home Page:
    I think u r trying to verify the "A", "S", "W", and "D" movement for a game...but what are r trying to build???
     
  4. thapchi

    thapchi New Member

    Joined:
    Mar 9, 2010
    Messages:
    11
    Likes Received:
    0
    Trophy Points:
    0
    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
     
  5. virxen

    virxen New Member

    Joined:
    Nov 24, 2009
    Messages:
    387
    Likes Received:
    90
    Trophy Points:
    0
    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;
    }
    
    
     

Share This Page