Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- /* Vanna Quon
- ENGR101: Section 305
- Date: 3.28.12
- Project 6.1
- GSI: Jeff
- hwk6.cpp
- */
- #include <iostream>
- using namespace std;
- const int NROWS = 52;
- const int NCOLS = 72;
- void printrace(const char a[][NCOLS])
- {
- for (int i = 0; i < NROWS; i++)
- {
- for (int j = 0; j < NCOLS; j++)
- {
- cout << a[i][j];
- }
- cout << endl;
- }
- return;
- }
- void initrace(char b[][NCOLS])
- {
- for (int i = 0; i < NROWS; i++)
- {
- for (int j = 0; j < NCOLS; j++)
- {
- b[1][1] = 'O'; //car
- if(j==0) b[i][j] = 'X'; //first left column
- else if(j==71) b[i][j] = 'X'; // last right column
- else if ((j>=10 && j<=29)&& (i >=0 && i <=34)) b[i][j] = 'X'; //first block
- else if ((j>=40 && j<=64)&& (i >=18 && i <=51)) b[i][j] = 'X'; //second block
- else if ((i==0)&& j<=(NCOLS-1)) b[i][j] = 'X'; //top row
- else if ((i==(NROWS-1))&&(j>=0 && j<=40)) b[i][j] = 'X'; //bottom row
- else if ((i==(NROWS-1))&&(j>=55 && j<=(NCOLS-2))) b[i][j] = 'F'; //finish line
- else b[i][j] = ' ';
- }
- }
- return;
- }
- int main(void)
- {
- //initrace sets up the grid
- //print race prints out the grid
- char grid[NROWS][NCOLS];
- //grid[1][1] = 'O';
- //printrace(grid);
- //initrace(grid);
- int xAcceleration = 0;
- int yAcceleration = 0;
- bool ask = true;
- //int scoretime = 0;
- //int currentPlayer = 1;
- initrace(grid);
- int xPosition = 1;
- int yPosition = 1;
- int xVelocity = 0;
- int yVelocity = 0;
- int count = 0;
- while(ask)
- {
- printrace(grid);
- cout << "Horizontal and vertical acceleration (-1,0,1): ";
- cin >> xAcceleration >> yAcceleration;
- cout << endl;
- count = count + 1;
- if(xAcceleration > 1 || yAcceleration > 1)
- {
- cout << "Crashed after " << count << " secs\n";
- ask = false;
- }
- else if (xAcceleration < -1 || yAcceleration < -1)
- {
- cout << "Crashed after " << count << " secs\n";
- ask =false;
- }
- xVelocity = xVelocity + xAcceleration;
- yVelocity = yVelocity + yAcceleration;
- xPosition = xPosition + xVelocity;
- yPosition = yPosition + yVelocity;
- if ((xPosition <= 0) || (xPosition >= 72))
- {
- cout << "Crashed after " << count << " secs\n";
- ask = false;
- }
- else if ((yPosition <=0) || (yPosition >= 52))
- {
- cout << "Crashed after " << count << " secs\n";
- ask = false;
- }
- else if ((xPosition >= 10 && xPosition <= 29) && (yPosition < 34))
- {
- cout << "Crashed after " << count << " secs\n";
- ask = false;
- }
- else if ((xPosition >= 40 && xPosition <= 64) && (yPosition >= 35))
- {
- cout << "Crashed after " << count << " secs\n";
- ask = false;
- }
- else if ((xPosition >= 65) && (xPosition <= 70))
- {
- cout << "You won! You just crossed the finish line!\n";
- ask = false;
- }
- grid[yPosition][xPosition] = '0';
- //manipulate grid array
- //then the loop will continue which calls the printrace
- //which will display your new changes to grid array
- //############## - 2 PLAYER - #########################################//
- //when player crosses finish line
- // store time in scoretime
- // maybe put this into an array and
- //also store currentPlayer
- //after that happens reset scoretime to 0 and set currentPlayer to next player
- //then for a two player game
- //if player 1 or 2 crashes whoever crashes loses and display winner
- // if both players didn't crash
- //then loop thru array and see who has smalles scoretime
- //lowest score time and associated currentPlayer value is your winner
- //display those
- //############## - 2 PLAYER - #########################################//
- }
- return 0;
- }
- /* Vanna Quon
- ENGR101: Section 305
- Date: 3.28.12
- Project 6.1
- GSI: Jeff
- hwk6.cpp
- */
- #include <iostream>
- using namespace std;
- const int NROWS = 52;
- const int NCOLS = 72;
- void printrace(const char a[][NCOLS])
- {
- for (int i = 0; i < NROWS; i++)
- {
- for (int j = 0; j < NCOLS; j++)
- {
- cout << a[i][j];
- }
- cout << endl;
- }
- return;
- }
- void initrace(char b[][NCOLS])
- {
- for (int i = 0; i < NROWS; i++)
- {
- for (int j = 0; j < NCOLS; j++)
- {
- b[1][1] = 'O'; //car
- if(j==0) b[i][j] = 'X'; //first left column
- else if(j==71) b[i][j] = 'X'; // last right column
- else if ((j>=10 && j<=29)&& (i >=0 && i <=34)) b[i][j] = 'X'; //first block
- else if ((j>=40 && j<=64)&& (i >=18 && i <=51)) b[i][j] = 'X'; //second block
- else if ((i==0)&& j<=(NCOLS-1)) b[i][j] = 'X'; //top row
- else if ((i==(NROWS-1))&&(j>=0 && j<=40)) b[i][j] = 'X'; //bottom row
- else if ((i==(NROWS-1))&&(j>=55 && j<=(NCOLS-2))) b[i][j] = 'F'; //finish line
- else b[i][j] = ' ';
- }
- }
- return;
- }
- int main(void)
- {
- //initrace sets up the grid
- //print race prints out the grid
- char grid[NROWS][NCOLS];
- //grid[1][1] = 'O';
- //printrace(grid);
- //initrace(grid);
- int xAcceleration = 0;
- int yAcceleration = 0;
- bool ask = true;
- //int scoretime = 0;
- //int currentPlayer = 1;
- initrace(grid);
- int xPosition = 1;
- int yPosition = 1;
- int xVelocity = 0;
- int yVelocity = 0;
- int count = 0;
- while(ask)
- {
- printrace(grid);
- cout << "Horizontal and vertical acceleration (-1,0,1): ";
- cin >> xAcceleration >> yAcceleration;
- cout << endl;
- count = count + 1;
- if(xAcceleration > 1 || yAcceleration > 1)
- {
- cout << "Crashed after " << count << " secs\n";
- ask = false;
- }
- else if (xAcceleration < -1 || yAcceleration < -1)
- {
- cout << "Crashed after " << count << " secs\n";
- ask =false;
- }
- xVelocity = xVelocity + xAcceleration;
- yVelocity = yVelocity + yAcceleration;
- xPosition = xPosition + xVelocity;
- yPosition = yPosition + yVelocity;
- if ((xPosition <= 0) || (xPosition >= 72))
- {
- cout << "Crashed after " << count << " secs\n";
- ask = false;
- }
- else if ((yPosition <=0) || (yPosition >= 52))
- {
- cout << "Crashed after " << count << " secs\n";
- ask = false;
- }
- else if ((xPosition >= 10 && xPosition <= 29) && (yPosition < 34))
- {
- cout << "Crashed after " << count << " secs\n";
- ask = false;
- }
- else if ((xPosition >= 40 && xPosition <= 64) && (yPosition >= 35))
- {
- cout << "Crashed after " << count << " secs\n";
- ask = false;
- }
- else if ((xPosition >= 65) && (xPosition <= 70))
- {
- cout << "You won! You just crossed the finish line!\n";
- ask = false;
- }
- grid[yPosition][xPosition] = '0';
- //manipulate grid array
- //then the loop will continue which calls the printrace
- //which will display your new changes to grid array
- //############## - 2 PLAYER - #########################################//
- //when player crosses finish line
- // store time in scoretime
- // maybe put this into an array and
- //also store currentPlayer
- //after that happens reset scoretime to 0 and set currentPlayer to next player
- //then for a two player game
- //if player 1 or 2 crashes whoever crashes loses and display winner
- // if both players didn't crash
- //then loop thru array and see who has smalles scoretime
- //lowest score time and associated currentPlayer value is your winner
- //display those
- //############## - 2 PLAYER - #########################################//
- }
- return 0;
- }
Add Comment
Please, Sign In to add comment