Go4Expert

Go4Expert (http://www.go4expert.com/)
-   C++ (http://www.go4expert.com/forums/cpp/)
-   -   game improvement (http://www.go4expert.com/forums/game-improvement-t21345/)

thapchi 13Mar2010 15:30

game improvement
 
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

xpi0t0s 14Mar2010 14:30

Re: game improvement
 
What doesn't it do that you want it to? We can't read your mind.

techgeek.in 14Mar2010 15:58

Re: game improvement
 
I think u r trying to verify the "A", "S", "W", and "D" movement for a game...but what are r trying to build???

thapchi 14Mar2010 16:07

Re: game improvement
 
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

virxen 16Mar2010 02:00

Re: game improvement
 
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;
}



All times are GMT +5.5. The time now is 16:49.