#include <iostream> //for input & output
#include <ctime> //to use time in c++
#include <cstdlib> //to use system ("cls")
using namespace std;
const int MAX=6; //maxmimum of the array 6 fields
//--------------------------------------------
char grid [MAX][MAX]; //initialize a tow dimentional array 6*6
int wall = 0;
/******************************************************
Wall has to be implemented in a struct or in a position class to check the
validity of processing forward in the same row or jumbing to another row
******************************************************/
void waitTimeInSeconds ( int seconds ); //define the function
void print (); //define the function
void reversePrint(); //print the grid
//========================================
int main ()
{
//fill the grid with the feed "syöte" '*'
for (int i=1; i <= MAX; i++)
{
for (int j=1; j <= MAX; j++)
{
grid [i][j]= '*';
}
}
print();
int TimeToLaunch= MAX; //Make time steps equal to the grid field amount
//cout<<"Enter how many seconds to launch > ";
//cin>>TimeToLaunch;
int cordX=1; //initialize x-axis of the grid
int cordY = 1; //initialize y axis of the grid
while (cordX==1, cordY < MAX-1) //while going through the grid not finished yet
{
for (int i=0; TimeToLaunch>i; TimeToLaunch--) // start count untill finish
{
//cout<<TimeToLaunch <<endl;
waitTimeInSeconds (1); //directs/pause output to wait for 1 second
//try to change the int to double to use time fraction
system("cls"); //clear the screen after every print
grid[cordX][cordY] = '<'; //fill the array
/*if (cordY>0)
{
grid[cordX][cordY-1]=' ';
}*/
print(); //print the grid
grid[cordX][cordY] = ' '; //unfill the array
//cout<<"i: "<<i<<", cordX: "<<cordX<<", cordY: "<<cordY<<endl;
cordY++; //fill the row
}
}
//**************************************
int verseCordY = MAX; //initialize y axis of the grid
int verseTimeToLaunch= MAX;
int reversecordX = 2;
while (reversecordX==2, verseCordY >1) //while going through the grid not finished yet
{
for (int i=0; verseTimeToLaunch>i; verseTimeToLaunch--) // start count untill finish
{
// cout<<"Time loop starts"<<endl;
waitTimeInSeconds (1); //directs/pause output to wait for 1 second
//try to change the int to double to use time fraction
system("cls"); //clear the screen after every print, use clear when using unix
if (i==0){
grid[reversecordX-1][verseCordY]=' ';
}
/*if (verseCordY<MAX)
{
grid[reversecordX][verseCordY+1]=' ';
}*/
grid[reversecordX][verseCordY] = '>'; //fill the array
print(); //print the grid
grid[reversecordX][verseCordY] = ' '; //unfill the array
verseCordY--; //fill the row
}
}
waitTimeInSeconds (1); //directs/pause output to wait for 1 second
system("cls"); //clear the screen after every print, use clear when using unix
print(); //print the grid
//***************************************
cout<<"LAUNCH!!!"<<endl;
//------------------------------
return 0; //return success
} //end of main
//-------------------------------------- *
void print() //print the game grid
{
for (int i=1; i<=MAX; i++){ //count from 1>6: length of the grid array
//------------------
cout<<" _"; //fill the upper ceiling of the grid
}
cout<<endl; //make a new line to start building the walls and floors of grid
for (int i=1; i<=1; i++){ //printing the rest of the grid
for(int j=1; j<=MAX; j++){
//grid[i][j]='_'; //print the ceiling
cout<<"|"<< grid[i][j]; //print the walls inside the grid
//
}//end of for y
//**************************
cout<<"|"; //to print the right out door
cout<<endl; //make a new line
}//end of for i
/*for(int i =1; i<=MAX; i++){
cout<<" _"; //print the walls inside the grid
}*/
//**************************************
for (int i =1; i<=MAX;i++) //draw the ceiling of the grid
{
cout<<"|_"; //consists of a space and underscore character _ _ _ _ _ _ _ _ _ _ _
} //end of for
cout<<"|"; //print the right wall of the grid
//*************************************
cout<<endl;
//***************************************
for (int i=2; i<=2; i++){ //printing the rest of the grid
for(int j=1; j<=MAX; j++){
//grid[i][ j]='_'; //print the ceiling
cout<<"|"<< grid[i][j]; //print the walls inside the grid
}//end of for y
cout<<"|"; //to print the right out door
cout<<endl;
for (int i =1; i<=MAX;i++) //draw the ceiling of the grid
{
cout<<"|_"; //consists of a space and underscore character _ _ _ _ _ _ _ _ _ _ _
} //end of for
cout<<"|"; //print the right wall of the grid
cout<<endl; //make a new line
}//end of for i
//***************************************
} //end of the
//---------------------------------------
void reversePrint() //print toinen rivi in the grid
{
for (int i=2; i<=MAX; i++){ //count from 1>6: length of the grid array
//------------------
cout<<" _"; //fill the upper ceiling of the grid
}
cout<<endl; //make a new line to start building the walls and floors of grid
for (int i=2; i<=2; i++){ //printing the rest of the grid
for(int j=1; j<=MAX; j++){
//grid[i][ j]='_'; //print the ceiling
cout<<"|"<< grid[i][j]; //print the walls inside the grid
}//end of y
cout<<"|"; //to print the right out door
cout<<endl; //make a new line
}//end of for i
}
//--------------------------------------
void waitTimeInSeconds ( int seconds ) //function
{
clock_t countDown; //clock_t represents clock tick
countDown = clock () + seconds * CLOCKS_PER_SEC ;
//Function clock() returns the processor time consumed by the program.
//CLOCKS_PER_SEC: representing the number of clock ticks per second.
while (clock() < countDown) {} //count desendingly
}//End of the programsystem("cls"); voi aiheuttaa ettei ohjelma toimi, pitäisi korjata se jos käytät linuxin käyttöjärjestelmää, system("clean")
Laita jatkossa aina koodien ympärille kooditagit. Lue keskustelun ohjeet.
Kaikkia harjoituksia ei ole pakko lähettää nettiin.
Aihe on jo aika vanha, joten et voi enää vastata siihen.