int main(void)
{		XInitThreads();
      int gd = DETECT, gm;
      int dx, dy, p, end;
      float x1, x2, y1, y2, x, y;
      initgraph(&gd, &gm, NULL);
      printf("Enter Value of X1: ");
      scanf("%f", &x1);
      printf("Enter Value of Y1: ");
      scanf("%f", &y1);
      printf("Enter Value of X2: ");
      scanf("%f", &x2);
      printf("Enter Value of Y2: ");
      scanf("%f", &y2);
      dx = abs(x1 - x2);
      dy = abs(y1 - y2);
      p = 2 * dy - dx;
      if(x1 > x2)
      {
            x = x2;
            y = y2;
            end = x1;
      }
      else
      {
            x = x1;
            y = y1;
            end = x2;
      }
      putpixel(x, y, 10);
      while(x < end)
      {
            x = x + 1;
            if(p < 0)
            {
                  p = p + 2 * dy;
            }
            else
            {
                  y = y + 1;
                  p = p + 2 * (dy - dx);
            }
            putpixel(x, y, 10);
      }
       wait_for_char();

      getch();
      
      
       wait_for_char();
    
      closegraph();
      return 0;
}
Esempio n. 2
0
/**
* Main game cycle, handles user interaction and checks if game is over
*/
void Game::play() {

	// run indefinitely
	while (1) {
		auto b1 = new Board();
		auto b2 = new Board();
		srand(time(NULL)); //random seed set as current time

		int game_over = 0;
		int winner;

		while (!game_over) {
			display_help();
			display_score(b1, b2);

			// if any board needs a piece, add it
			if (b1->needs_piece) {
				int next = rand() % 7;
				Piece new_piece(next);
				if (b1->is_collision(new_piece)) {
					game_over = 1;
					winner = 2;
				}
				b1->set_curr_piece(new_piece);
			}

			if (b2->needs_piece) {
				int next = rand() % 7;
				Piece new_piece(next);
				if (b2->is_collision(new_piece)) {
					game_over = 1;
					winner = 1;
				}
				b2->set_curr_piece(new_piece);
			}

			Piece current1 = b1->get_curr_piece(), potential1;
			Piece current2 = b2->get_curr_piece(), potential2;
			char move;

			// draw boards
			b1->draw(b2);

			move = wait_for_char(WAIT_TIME); // wait for input

			// quit immediatly
			if (move == 'q') {
				winner = 1;
				break;
			}

			if (move == 'w') {
				current1.move(UP);
				if (!b1->is_collision(current1))
					b1->set_curr_piece(current1);
				continue;
			}
			else if (move == 's') {
				current1.move(DOWN);
				if (!b1->is_collision(current1))
					b1->set_curr_piece(current1);
				continue;
			}
			else if (move == 'a') {
				current1.rotate();
				if (!b1->is_collision(current1))
					b1->set_curr_piece(current1);
				continue;
			}

			else if (move == 'i') {
				current2.move(UP);
				if (!b2->is_collision(current2))
					b2->set_curr_piece(current2);
				continue;
			}
			else if (move == 'k') {
				current2.move(DOWN);
				if (!b2->is_collision(current2))
					b2->set_curr_piece(current2);
				continue;
			}
			else if (move == 'l') {
				current2.rotate();
				if (!b2->is_collision(current2))
					b2->set_curr_piece(current2);
				continue;
			}

			// check if current piece of the boards has completely fallen
			potential1 = current1;
			potential2 = current2;


			potential1.move(RIGHT);
			if (!b1->is_collision(potential1))
				b1->set_curr_piece(potential1);
			else {
				b1->add_piece(current1);
				b1->needs_piece = true;
			}

			potential2.move(RIGHT);
			if (!b2->is_collision(potential2))
				b2->set_curr_piece(potential2);
			else {
				b2->add_piece(current2);
				b2->needs_piece = true;
			}

			int adjust1 = b1->delete_needed_lines();
			int adjust2 = b2->delete_needed_lines();

			// for each deleted line adjust the base of the boards accordingly 
			for (int i = 0; i < adjust1; i++)
			{
				b1->adjust_middle(DOWN);
				b2->adjust_middle(UP);
			}

			for (int i = 0; i < adjust2; i++)
			{
				b2->adjust_middle(DOWN);
				b1->adjust_middle(UP);
			}
		}

		// ask for input, if input is 'y' start another game
		cout << "\nPlayer " << winner << " WINS!\n\n";
		cout << "Play again? (Y or N)\n";
		char resume = getch();
		if (resume == 'n')
			break;

	}
}
Esempio n. 3
0
int wait_for_rx_not_empty() {

  DBG("Waiting for an event on the read-ring\n");
  return wait_for_char(singleton_screen->socketfd, 'R');

}
Esempio n. 4
0
int wait_for_tx_not_full() {

  DBG("Waiting for an event on the transmit ring\n");
  return wait_for_char(singleton_screen->socketfd, 'T');

}