你能帮我用C ++设计一个飞机模拟程序吗? [英] Can you help me design a air craft simulation program using C++

查看:101
本文介绍了你能帮我用C ++设计一个飞机模拟程序吗?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述



(注意:我是新手)。你能帮我设计一个使用C ++的飞行器模拟程序吗,我认为使用随机而不是固定是完美的,你能帮帮我吗?

[/编辑]



问题是设计,它是固定的,但我希望飞机是随机的,通过随机飞机随机时间去。



我尝试过:




(Note: I'm a newbie). Can you help me design a air craft simulation program using C++, im thinking it would be perfect to use random instead of fixed, can you help me out?
[/EDIT]

The problem is the design, Its fixed, but i would like the aircraft to be random, by means of random the aircraft would go at random time.

What I have tried:

#include<iostream>
#include<windows.h>
#define p printf
#define s scanf

using namespace std;

int main(){
    
    const WORD colors[] = {
          0xA,0xB,0xC,0xD,0xE,0xF };
          HANDLE hstdout = GetStdHandle (STD_OUTPUT_HANDLE);
          WORD index = 3;
          
          CONSOLE_SCREEN_BUFFER_INFO csbi;
          GetConsoleScreenBufferInfo(hstdout,&csbi);

    int trty=1;
    int loop = 0; 
    int direction = 1; // direction kung pataaa, paleft, pababa, etc.
    int size = 2;
	int marks[size];
	int ctr;
	
	for(ctr=1;ctr<size;ctr++)>
	{
        p("Enter Number for the time of Air Craft take of :");
		s("%d\n", &marks[ctr]);
	}
	for(ctr=0;ctr<size;ctr++)>
	{
		p("Airplane %d arrives at %d\n", ctr,marks[ctr]);
	}
    while(loop == 0){  // for infinite loop only
    
               
    for(int a = 0; a <10; a ++){  // loop ng bilang paggalaw ng asterisk, 
                                std::cout<<"\n\tPresented By : Shaira Elsenique and JV Austria";
                                std::cout<<"\n\t\t\t\t\1\1\1";
                                std::cout<<"\n\tAir Craft Simulation for Calamba Airport";
                                std::cout<<"\nLegends:";
                                std::cout<<"\n_______________________________________";
                                std::cout<<"\n| Arriows \30,\31,\32,\33 = Air Craft         |";
                                std::cout<<"\n| Asterisk ** = Runways               |";
                                std::cout<<"\n| |\30  | = Take off                    |"; 
                                std::cout<<"\n|                                     |";
                                std::cout<<"\n_______________________________________";
            cout<< "\n\n*********************************";
            cout<< "\n";
            cout<< endl;
            
            
            
            
            if(direction == 1){  // set as pataas
                         cout << endl;    // space para sa dadaanan ng asterisk na paright
                         cout << "*********************************";
                         cout << endl;
                         
                         for(int c = 10; c >= a; c--){  // loop base sa main loop, habang tumataas ung value nung main loop,
                                                        // umiiksi ung loop.
                    cout <<"\n";
                    if(a == 9){  // pag tapos na ung 9 steps pataas, lilipat n sya ng direction, paright naman kaya papaltan ung direction ng 2
                   
                         if (trty==1){
                                            direction=2;                                      
                            }else if(trty==2){
                                            direction=4;
                                            }
                         }
                    }
                    //for the Up and Down arrow
                    //Yung else if para sa Down .
                    if(trty==1){
                                SetConsoleTextAttribute(hstdout,colors[1]);
                                std::cout<<"|  \30 |";
                                }
                                else if(trty==2){
                                      cout << "                                |  \30 |";
                  }
            
            cout << endl << endl;
                         
                         }
            
            
            
            else if(direction  == 2){  // paright
                   
            
            for(int b = 0; b < a; b++){  // loop based sa value ng mainloop, habang tumataasa value ng main loop,
                                         // dumadami din loop para iprint ung spaces, kaya umuusot paright ung asterisk dahil dumadami spaces
                    cout << "   ";  // print the spaces
                    if(a == 9){  // pag nareach na ung 9 steps paleft, balik na ulit pa-up, set as 1.
                         direction = 3;
                    
                         }
                    }
                       cout << "    \32";
                       cout << endl << "*********************************";
                 }
                     
                     
                     else if(direction  == 3){  // pabootom
                       cout << endl;    // space para sa dadaanan ng asterisk na paright
                         cout << "*********************************";
                         cout << endl;
                         
                         for(int c = 0; c <= a; c++){  // loop base sa main loop, habang tumataas ung value nung main loop,
                                                        // umiiksi ung loop.
                    
                    if(a == 9){  // pag tapos na ung 9 steps pataas, lilipat n sya ng direction, paright naman kaya papaltan ung direction ng 2
                         direction = 1;
                         trty=2;
                         }
                         cout << endl;
                    }
                    if(trty==1){
                                cout << "                                 \31";
                                
                    }else if(trty==2){
                                      cout << " \31";
      
                                      }            
        
  //ilil            
            cout << endl << endl;
                         
                         }
             else if(direction ==4){
                         
            
            for(int b = 10; b > a; b--){  // loop based sa value ng mainloop, habang tumataasa value ng main loop,
                                         // dumadami din loop para iprint ung spaces, kaya umuusot paright ung asterisk dahil dumadami spaces
                    cout << "   ";  // print the spaces
                    if(a == 9){  // pag nareach na ung 9 steps paleft, balik na ulit pa-up, set as 1.
                         direction = 3;
                    
                         }
                    }
            cout << "    \33";
            cout << endl << "*********************************";
                 }
            
            Sleep(100);
            system("cls");
//                      direction = 1;
               

               }
}
cout<<"\n*\n*\n*\n*\n*\n*\n*\n*";

 return 0;   
}

推荐答案

您可以使用 rand - C ++参考 [ ^ ]获取随机数的函数。请参阅上面链接中的示例。
You can use the rand - C++ Reference[^] function to get random numbers. See the example in the above link.


这篇关于你能帮我用C ++设计一个飞机模拟程序吗?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆