Last active
August 29, 2015 14:09
-
-
Save hamoungh/8e378adbf284dfcf710f to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
-the lab practice should be submitted to bb | |
-This program draws a spacecraft that can travel and an array of fixed asteroids. | |
-include the following header files: | |
#include <cmath> | |
#include <iostream> | |
#include <string> | |
#include<conio.h> | |
#include <Windows.h> | |
if adding windows.h makes your program not compile use vs2013. | |
-Import the std namespace | |
-define a global integer constant called astroids_num to store the number of astroids. | |
-define two global float variables xVal and yVal to store the coordinates of the spacecraft. | |
-define two global integer arrays arrayAsteroidsX,arrayAsteroidsY each having astroids_num elements to store the coordinates of the asteroids. | |
-write a void method called setup() that initializes arrayAsteroidsX with random variable between 1 and 40 and initializes arrayAsteroidsY with random numbers between 1 and 20. | |
-copy the following definition for the function gotoxy(...) if you're on Windows: | |
void gotoxy( int x, int y ) | |
{ | |
COORD p = { x, 100-y }; | |
SetConsoleCursorPosition( GetStdHandle( STD_OUTPUT_HANDLE ), p ); | |
} | |
this code needs windows.h | |
-write a method void drawScene(char ch) that prints each astroid using the following 2 statements: | |
gotoxy(arrayAsteroidsX[j]-xVal, arrayAsteroidsY[j]-yVal); | |
cout << ch; | |
- you need a for loop that goes over all asteroids and uses the variable asteroids_num as the upper bound. | |
- test your program using the following main method: | |
void main() | |
{ | |
setup(); | |
drawScene('o'); | |
} | |
-add a keyboard input processing function called: | |
void keyInputf(unsigned char key): | |
switch(key) | |
{ | |
case 'W': | |
case 'w': | |
yVal++; | |
break; | |
case 27: | |
exit(0); | |
break; | |
default: | |
break; | |
} | |
} | |
-the idea is to use the wasd keys to control the navigation. I left the code for the asd keys to you. | |
include the following header file: | |
#include<conio.h> | |
-change the main method to the following: | |
void main() | |
{ | |
char ch=0; | |
setup(); | |
do | |
{ | |
drawScene('o'); | |
gotoxy(20, 10 ); | |
cout << "+"; | |
ch = _getch(); | |
drawScene(' '); | |
keyInputf(ch); | |
}while (ch != 'Q' && ch!='q'); | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment