Example #1
0
setuplevel()
{
        int y,x;
        char *ptr,*ptr2;
        ptr2=board;
        ptr=levels+(level*38);
/* ptr points to start of level now */
/* First two bytes are the ball and the boxes position */
        balloffset=*ptr++;
        boxoffset=*ptr++;

/* Now, decompress level into board */
        for (y=0; y!=9; y++) {
                for (x=0; x !=4; x++) {
                        *ptr2++=((*ptr)>>6)&3;
                        *ptr2++=((*ptr)>>4)&3;
                        *ptr2++=((*ptr)>>2)&3;
                        *ptr2++=(*ptr)&3;
                        ptr++;
                }
        }
/* Now, plot the ball and box into the internal map */
        ptr2=board;
        *(ptr2+balloffset)=BALL;
        *(ptr2+boxoffset)=BOX;
        drawboard();
}
Example #2
0
/*
 * Here when the game is over.
 * Show where the mines are, and give the results.
 */
static void
gameover(void)
{
    POS	pos;
    CELL	cell;

    playing = GR_FALSE;
    switch (legs) {
    case 0:
        games0[index]++;
        steps0[index] += steps;
        break;
    case 1:
        games1[index]++;
        steps1[index] += steps;
        break;
    case 2:
        games2[index]++;
        steps2[index] += steps;
        break;
    }

    for (pos = 0; pos < (FULLSIZE * FULLSIZE); pos++) {
        cell = board[pos];
        if (isseen(cell))
            cell = (cell & F_FLAGS) | F_WRONG;
        if (ismine(cell))
            cell = (cell & F_FLAGS) | F_REMEMBER;
        board[pos] = cell;
    }

    drawboard();
    drawstatus();
}
Example #3
0
/*
 * Handle exposure events.
 */
static void
doexposure(GR_EVENT_EXPOSURE *ep)
{
    if (ep->wid == boardwid) {
        drawboard();
        return;
    }

    if (ep->wid == statwid) {
        drawstatus();
        return;
    }

    if (ep->wid == quitwid) {
        drawbutton(quitwid, "QUIT");
        return;
    }

    if (ep->wid == savewid) {
        drawbutton(savewid, "SAVE GAME");
        return;
    }

    if (ep->wid == newgamewid) {
        drawbutton(newgamewid, "NEW GAME");
        return;
    }
}
Example #4
0
/* la oss lage et 8x8 rutenett som dekker hele skjermen. Vi bruker to forskjellige farger. Hver brikketype har en enkel form (en tilfeldig sammensetning av piksler som representerer hver brikke). Hver brikke er angitt med en "offset" adresse relativt til en blokk ( relativ addresse angitt innenfor en range av høyde/8, bredde/8). Offset adressen blir da konstant, og den totale adressen vil da bare være en utskrift av 8x8 matrisen.*/
int main(int argc, char *argv[])
{
    rect.dx=0;
    rect.dy=0;
    rect.width=64;
    rect.height=32;

    printf("Hello World, I'm game!!!! 1\n");
    int  fd = open(FILEPATH, O_RDWR);
    if (fd == -1) {
        perror("Error opening file for reading");
        exit(EXIT_FAILURE);
    }

    short*  map = mmap(0, FILESIZE, PROT_WRITE, MAP_SHARED, fd, 0);

    /* screenclear(map,fd); */
    drawboard(map, fd);

    munmap(map,FILESIZE);

    init_gamepad();
    while(1) pause();

    exit(EXIT_SUCCESS);
}
Example #5
0
void playgame (void) {
  int c, numpl;

  for (c = 0; c < 13; c++) board[c] = 3;
  board[6] = board [13] = memory[memory[0]] = numpl = 0;
  do {
    printf ("\nHow many players (1 - 2) ? ");
    scanf ("%d", &numpl);
    if (numpl < 1 || numpl > 2) {
      printf ("Please input either 1 or 2.\n");
      numpl = 0;
    }
  } while (!numpl);
  turn = 0;
  do {
    drawboard ();
    if (domove (playermove (0), 6))
      if (!endgame()) {
        drawboard ();
        printf ("Again.\n");
        domove (playermove (0), 6);
      }
    drawboard ();
    if  (!endgame ()) {
      if (domove ((numpl - 1) ? playermove (1) : computermove (), 13))
        if (!endgame()) {
          drawboard ();
          printf ("Again.\n");
          domove ((numpl - 1) ? playermove (1) : computermove (), 13);
        }
      printf("\n");
    }
  } while (!endgame ());
  drawboard ();
  printf ("\nGame Over.\n");
  c = board[6]-board[13];
  if (c < 0) printf ("%s by %d points.\n",
    (numpl - 1) ? "Player 2 wins" : "I win", (-c));
  else {
    if (!(numpl - 1) && memory[0] < 50) memory[0]++;
    if (c == 0) printf ("Drawn game.\n");
    else printf ("Player 1 wins by %d points.\n", c);
  }
}
Example #6
0
static void moved()
{
    reset();
    selected = 0;
    highlight(cy, cx, arena[cy][cx]);
    if ( selected < 2 ) {
        reset();
    }
    drawboard();
}
Example #7
0
File: xs.c Project: npe9/harvey
int
horiz(void)
{
    int lev[MAXN];
    int i, j, h;
    Rectangle r;

    h = 0;
    for(i=0; i<NY; i++) {
        for(j=0; board[i][j]; j++)
            if(j == NX-1) {
                lev[h++] = i;
                break;
            }
    }
    if(h == 0)
        return 0;
    r = rboard;
    newscreen = 0;
    for(j=0; j<h; j++) {
        r.min.y = rboard.min.y + lev[j]*pcsz;
        r.max.y = r.min.y + pcsz;
        draw(screen, r, display->white, whitemask, ZP);
        flushimage(display, 1);
    }
    for(i=0; i<3; i++) {
        pause(250);
        if(newscreen) {
            drawboard();
            break;
        }
        for(j=0; j<h; j++) {
            r.min.y = rboard.min.y + lev[j]*pcsz;
            r.max.y = r.min.y + pcsz;
            draw(screen, r, display->white, whitemask, ZP);
        }
        flushimage(display, 1);
    }
    r = rboard;
    for(j=0; j<h; j++) {
        i = NY - lev[j] - 1;
        score(250+10*i*i);
        r.min.y = rboard.min.y;
        r.max.y = rboard.min.y+lev[j]*pcsz;
        draw(screen, rectaddpt(r, Pt(0,pcsz)), screen, nil, r.min);
        r.max.y = rboard.min.y+pcsz;
        draw(screen, r, display->white, nil, ZP);
        memcpy(&board[1][0], &board[0][0], NX*lev[j]);
        memset(&board[0][0], 0, NX);
    }
    flushimage(display, 1);
    return 1;
}
Example #8
0
File: xs.c Project: npe9/harvey
void
suspend(int s)
{
    suspended = s;
    if (suspended)
        setcursor(mousectl, &whitearrow);
    else
        setcursor(mousectl, nil);
    if (!suspended)
        drawpiece();
    drawboard();
    flushimage(display, 1);
}
Example #9
0
right(char *ptr)
{
        char *locn;

        while(1) {
                locn=*(ptr)+board;
                if (standardmiddle(*(locn+1)) ) return;
                *(locn+1)=*locn;
                *locn=0;
                (*ptr)++;
                drawboard();
        }
}
Example #10
0
void drawgamescreen_1p()
{
	drawboard(1);
	refreshwin(0);
	if (game_paused)
		clearboard_paused();
	else
		redrawboard(&player1, 19);
	drawpanel_1p();
	print_top_scores();
	print_tetr_stats();
	refreshwin(WIN_PANEL);
}
Example #11
0
up(char *ptr)
{
        char *locn;

        while(1) {
                locn=*(ptr)+board;
                if ( standardmiddle(*(locn-16)) ) return;
                *(locn-16)=*locn;
                *locn=0;
                (*ptr)-=16;
                drawboard();
        }
}
Example #12
0
left(char *ptr)
{
        char *locn;

        while(1) {
                locn=*(ptr)+board;
                if (standardmiddle(*(locn-1)) ) return;
                *(locn-1)=*locn;
                *locn=0;
                (*ptr)--;       /* ptr is the location of blob */
                drawboard();    /* Draw screen */
        }
}
Example #13
0
void Board::displayBoard() {
    //Board
    glPushMatrix();
    //  glEnable(GL_TEXTURE_2D);
    glTranslated(0, 2.1, 1.7);
    glRotated(90, 1, 0, 0);
    glRotated(90, 0, 1, 0);
    glRotated(180, 1, 0, 0);
    drawboard();
//    glDisable(GL_TEXTURE_2D);
    glPopMatrix();
    //Ring
	newRing->drawRing();
    //Pole
    glPushMatrix();
    glColor4d(0.6, 0.6, 0.6,0.9);
    glRotated(90, 0, 1, 0);  glRotated(90, 1, 0, 0);
    glTranslated(-1.0, 0, -2.0);
    glutSolidCone(0.5, 5.5, 10, 10);
    glPopMatrix();
//    drawCourt();
}
Example #14
0
newwave()
{
	register monster *mptr;
	addscore(FLUSHSCORE);
	Wave++;
	mvprintf(WAVEROW,WAVECOL+10,"%D",Wave);
	if ( Wave&1 ) {
		for ( mptr=Monster ; mptr < &Monster[MAXMONSTER] ; mptr++ )
			if ( mptr->time > MINMONTIME )
				mptr->time = max(mptr->time-MONDELTA,MINMONTIME);
		if ( Pacman.time > MINPACTIME )
			Pacman.time = max(Pacman.time-PACDELTA,MINPACTIME);
	}
	newboard();
	drawboard();
	Dotsrem = DOTS;
	Seekprob += Seekinc;
	elinit();
	pacinit();
	moninit();
	fruitinit(TRUE);
}
Example #15
0
void
drawscreen(void)
{
	Point l1, l2;
	int i;

	draw(screen, screen->r, brdr, nil, ZP);
	draw(screen, insetrect(screen->r, Border), background, nil, ZP);
	for(i = 0; i < Brdsize; i++) {
		l1 = addpt(screen->r.min, Pt(i*Square, Square));
		l2 = addpt(screen->r.min, Pt(i*Square, Maxy));
		line(screen, l1, l2, Endsquare, Endsquare, (i%3) == 0 ? Thickline : Line, brdr, ZP); 
		l1 = addpt(screen->r.min, Pt(0, (i+1)*Square));
		l2 = addpt(screen->r.min, Pt(Maxx, (i+1)*Square));
		line(screen, l1, l2, Endsquare, Endsquare, (i%3) == 0 ? Thickline : Line, brdr, ZP); 
	}
	for(i = 1; i < 10; i++) {
		drawbar(i, (selected == i) ? 1 : 0);
	}
	drawboard();
	flushimage(display, 1);
}
Example #16
0
void playgame(void)
{
  int height = glutGet(GLUT_WINDOW_HEIGHT);
  int width = glutGet(GLUT_WINDOW_WIDTH);

  /* Draw the quit button */
  drawquit(7.0, 9.0, 0.4, 1.0);
  /* Quit */
#if 0
  //  glColor3f(1.0, 1.0, 1.0);  /* white */
  //  text(0.78*width, 0.88*height, 0.1*height, "Quit");
#endif
  
  /* Draw the current scores */
  /* Draw the total # of pegs */
  glPushMatrix();
    glColor3f(1.0, 1.0, 0.0);     /* yellow */
    glTranslatef(-7.8, 8.8, 0.0);
    drawpeg();
    text(0.1*width, 0.9*height, 0.07*height, ": %02d", pegs);
  glPopMatrix();

  if (playdone)
    text(0.2*glutGet(GLUT_WINDOW_WIDTH),
	 0.75*glutGet(GLUT_WINDOW_HEIGHT),
	 0.08*glutGet(GLUT_WINDOW_HEIGHT),
	 "No moves left.");

  /* do the trackball rotation. */
  glPushMatrix();
  glRotatef(45.0, 1.0, 0.0, 0.0);
  tbMatrix();

  drawboard();
  drawpegs();
  glPopMatrix();
}
Example #17
0
void selectboard(void)
{
  int height=glutGet(GLUT_WINDOW_HEIGHT);
  int width=glutGet(GLUT_WINDOW_WIDTH);
  static float spin=0.0;

  /* Eventually make it spin */
  /* Display the buttons */
  displaybuttons();
  /* Draw the quit button */
  drawquit(7.0, 9.0, 0.4, 1.0);
  /* Quit */
  glColor3f(1.0, 1.0, 1.0);  /* white */
  /*  text(0.78*width, 0.89*height, 0.1*height, "Quit"); */
  /* Select message */
  glColor3f(0.0, 1.0, 0.0);
  text(0.3*width, 0.9*height, 0.07*height, "Select a board");

  /* Draw the total # of pegs */
  glPushMatrix();
    glColor3f(1.0, 1.0, 0.0);     /* yellow */
    glTranslatef(-7.8, 8.8, 0.0);
    drawpeg();
    text(0.1*width, 0.9*height, 0.07*height, ": %02d", totalpegs);
  glPopMatrix();
  
  /* do the trackball rotation. */
  glPushMatrix();
  /*    tbMatrix(); */
    glRotatef(45.0, 1.0, 0.0, 0.0);
    glRotatef(spin, 0.0, 1.0, 0.0);
    drawboard();
    drawpegs();
  glPopMatrix();
  spin++;
}
Example #18
0
int main(int argc, char* argv[]) {
    bool finished;
    int ch;
    engine_t engine;
    /* Initialize */
    rand_init();							/* must be called before engine_init () */
    engine_init(&engine, score_function);	/* must be called before using engine.curshape */
    finished = shownext = FALSE;
    memset(shapecount, 0, NUMSHAPES * sizeof(int));
    shapecount[engine.curshape]++;
    parse_options(argc,argv);				/* must be called after initializing variables */
    if (level < MINLEVEL) {
        choose_level();
    }
    io_init();
    drawbackground();
    in_timeout(DELAY);
    /* Main loop */
    do {
        /* draw shape */
        showstatus(&engine);
        drawboard(engine.board);
        out_refresh();
        /* Check if user pressed a key */
        if ((ch = in_getch ()) != ERR) {
            switch (ch) {
            case 'j':
            case KEY_LEFT:
                engine_move(&engine,ACTION_LEFT);
                break;
            case 'k':
            case '\n':
                engine_move(&engine,ACTION_ROTATE);
                break;
            case 'l':
            case KEY_RIGHT:
                engine_move(&engine,ACTION_RIGHT);
                break;
            case ' ':
            case KEY_DOWN:
                engine_move(&engine,ACTION_DROP);
                break;
                /* show next piece */
            case 's':
                shownext = TRUE;
                break;
                /* toggle dotted lines */
            case 'd':
                dottedlines = !dottedlines;
                break;
                /* next level */
            case 'a':
            case KEY_UP:
                if (level < MAXLEVEL) {
                    level++;
                    in_timeout(DELAY);
                }
                else out_beep();
                break;
                /* quit */
            case 'q':
                finished = TRUE;
                break;
                /* pause */
            case 'p':
                out_setcolor(COLOR_WHITE,COLOR_BLACK);
                out_gotoxy((out_width() - 34) / 2,out_height() - 2);
                out_printf("Paused - Press any key to continue");
                while ((ch = in_getch ()) == ERR) ;	/* Wait for a key to be pressed */
                in_flush();							/* Clear keyboard buffer */
                out_gotoxy((out_width() - 34) / 2, out_height() - 2);
                out_printf("                                  ");
                break;
                /* unknown keypress */
            default:
                out_beep();
            }
            in_flush();
        } else {
            switch (engine_evaluate(&engine)) {
            /* game over (board full) */
            case -1:
                if ((level < MAXLEVEL) && ((engine.status.droppedlines / 10) > level)) level++;
                finished = TRUE;
                break;
                /* shape at bottom, next one released */
            case 0:
                if ((level < MAXLEVEL) && ((engine.status.droppedlines / 10) > level)) {
                    level++;
                    in_timeout(DELAY);
                }
                shapecount[engine.curshape]++;
                break;
                /* shape moved down one line */
            case 1:
                break;
            }
        }
    } while (!finished);
    /* Restore console settings and exit */
    io_close();
    /* Don't bother the player if he want's to quit */
    if (ch != 'q') {
        showplayerstats(&engine);
        savescores(GETSCORE(engine.score));
    }
    exit(EXIT_SUCCESS);
}
void twoChessBoard::mousePressEvent(QMouseEvent *event)
{
    if (event->button() != Qt::LeftButton)
        return;

    // ui->label_2->clear();
    // ui->label_3->clear();


    int x = event->x();
    int y = event->y();

    ui->label->setText("Mouse pressed");

    //the following code is used to find which square is clicked.
    int square = 0;
    if((x>10 && x<490 ) && (y>130 && y<610))
    {
        int xaxis = ( (x-10)/60 );
        int yaxis = (y-130)/60;
        square = (yaxis*8)+xaxis;
        QString str2= QString::number(yaxis);
        ui->label_3->setText(str2);



        if(select==0)//enters this if statement if no piece is selected
                {
                    selectx = xaxis;
                    selecty = yaxis;
                    if(turn==1)//used to make sure that the player selects only his/her pieces
                    {
                        if(boardvalues[selecty][selectx]>0&&boardvalues[selecty][selectx]<=6)
                        {
                            select = 1;
                        }
                    }
                    if(turn==2)
                    {
                        if(boardvalues[selecty][selectx]>6&&boardvalues[selecty][selectx]<=12)
                        {
                            select = 1;
                        }
                    }


                }
                else
                {
                    //enters this if a piece is already selected
                    int changedvalue = 16;//used to store the values that has been eliminated, I used the intial value as 16 because no pieces has this as their boardvalue

                    if((boardvalues[yaxis][xaxis]>=7 && boardvalues[yaxis][xaxis]<=12)||boardvalues[yaxis][xaxis]==0)//this if statement is to make sure that the player doesnot eliminate his/her own pieces
                    {
                    if(boardvalues[selecty][selectx]==1)
                    {//if the selected pieces is black pawn
                        if((yaxis==selecty+1)&&(selectx==xaxis))
                        {//to check that the new position is one step down in the board
                            changedvalue = boardvalues[yaxis][xaxis];
                            boardvalues[yaxis][xaxis] = boardvalues[selecty][selectx];
                            select = 0;
                            boardvalues[selecty][selectx] = 0;
                            turn = 2;//changes the turn

                        }
                        if(((yaxis==selecty+1)&&(selectx==xaxis+1))||((yaxis==selecty+1)&&(selectx==xaxis-1)))
                        {
                            if(boardvalues[yaxis][xaxis]>=7 && boardvalues[yaxis][xaxis]<=12)
                            {
                                changedvalue = boardvalues[yaxis][xaxis];
                                boardvalues[yaxis][xaxis] = boardvalues[selecty][selectx];
                                select = 0;
                                boardvalues[selecty][selectx] = 0;
                                turn = 2;

                            }
                        }
                    }
                    //the following code is similar but for other pieces rules
                    if(boardvalues[selecty][selectx]==2)
                    {

                        if((yaxis==selecty)||(xaxis==selectx))
                        {
                                    changedvalue = boardvalues[yaxis][xaxis];
                                    boardvalues[yaxis][xaxis] = boardvalues[selecty][selectx];
                                    select = 0;
                                    boardvalues[selecty][selectx] = 0;
                                    turn = 2;

                         }

                    }
                    if(boardvalues[selecty][selectx]==3)
                    {
                        int xchange = fabs(selectx-xaxis);
                        int ychange = fabs(selecty-yaxis);
                        int totalchange = xchange+ychange;
                        if((totalchange==3))
                        {
                            changedvalue = boardvalues[yaxis][xaxis];
                            boardvalues[yaxis][xaxis] = boardvalues[selecty][selectx];
                            select = 0;
                            boardvalues[selecty][selectx] = 0;
                            turn = 2;

                        }
                    }
                    if(boardvalues[selecty][selectx]==4)
                    {
                        int xchange = fabs(selectx-xaxis);
                        int ychange = fabs(selecty-yaxis);
                        if(xchange==ychange)
                        {
                            changedvalue = boardvalues[yaxis][xaxis];
                            boardvalues[yaxis][xaxis] = boardvalues[selecty][selectx];
                            select = 0;
                            boardvalues[selecty][selectx] = 0;
                            turn = 2;

                        }


                    }
                    if(boardvalues[selecty][selectx]==5)
                    {
                        int xchange = fabs(selectx-xaxis);
                        int ychange = fabs(selecty-yaxis);
                        if(xchange==1 && ychange==1)
                        {
                            changedvalue = boardvalues[yaxis][xaxis];
                            boardvalues[yaxis][xaxis] = boardvalues[selecty][selectx];
                            select = 0;
                            boardvalues[selecty][selectx] = 0;
                            turn = 2;

                        }
                        if(((yaxis==selecty+1)&&(selectx==xaxis))||((yaxis==selecty-1)&&(selectx==xaxis)))
                        {
                            changedvalue = boardvalues[yaxis][xaxis];
                            boardvalues[yaxis][xaxis] = boardvalues[selecty][selectx];
                            select = 0;
                            boardvalues[selecty][selectx] = 0;
                            turn = 2;

                        }
                        if(((yaxis==selecty)&&(selectx==xaxis+1))||((yaxis==selecty)&&(selectx==xaxis-1)))
                        {
                            changedvalue = boardvalues[yaxis][xaxis];
                            boardvalues[yaxis][xaxis] = boardvalues[selecty][selectx];
                            select = 0;
                            boardvalues[selecty][selectx] = 0;
                            turn = 2;

                        }


                    }
                    if(boardvalues[selecty][selectx]==6)
                    {
                        int xchange = fabs(selectx-xaxis);
                        int ychange = fabs(selecty-yaxis);
                        if(xchange==ychange)
                        {
                            changedvalue = boardvalues[yaxis][xaxis];
                            boardvalues[yaxis][xaxis] = boardvalues[selecty][selectx];
                            select = 0;
                            boardvalues[selecty][selectx] = 0;
                            turn = 2;

                        }
                        if((yaxis==selecty)||(xaxis==selectx))
                        {
                                    changedvalue = boardvalues[yaxis][xaxis];
                                    boardvalues[yaxis][xaxis] = boardvalues[selecty][selectx];
                                    select = 0;
                                    boardvalues[selecty][selectx] = 0;
                                    turn = 2;

                         }

                    }
                    }
                    if((boardvalues[yaxis][xaxis]>=0 && boardvalues[yaxis][xaxis]<=6))
                    {
                    if(boardvalues[selecty][selectx]==7)
                    {
                        if((yaxis==selecty+-1)&&(selectx==xaxis))
                        {
                            changedvalue = boardvalues[yaxis][xaxis];
                            boardvalues[yaxis][xaxis] = boardvalues[selecty][selectx];
                            select = 0;
                            boardvalues[selecty][selectx] = 0;
                            turn = 1;

                        }
                        if(((yaxis==selecty-1)&&(selectx==xaxis+1))||((yaxis==selecty-1)&&(selectx==xaxis-1)))
                        {
                            if(boardvalues[yaxis][xaxis]>=1 && boardvalues[yaxis][xaxis]<=6)
                            {
                                changedvalue = boardvalues[yaxis][xaxis];
                                boardvalues[yaxis][xaxis] = boardvalues[selecty][selectx];
                                select = 0;
                                boardvalues[selecty][selectx] = 0;
                                turn = 2;

                            }
                        }
                    }
                    if(boardvalues[selecty][selectx]==8)
                    {

                        if((yaxis==selecty)||(xaxis==selectx))
                        {
                            changedvalue = boardvalues[yaxis][xaxis];
                                    boardvalues[yaxis][xaxis] = boardvalues[selecty][selectx];
                                    select = 0;
                                    boardvalues[selecty][selectx] = 0;
                                    turn = 1;

                         }

                    }
                    if(boardvalues[selecty][selectx]==9)
                    {
                        int xchange = fabs(selectx-xaxis);
                        int ychange = fabs(selecty-yaxis);
                        int totalchange = xchange+ychange;
                        if((totalchange==3))
                        {
                            changedvalue = boardvalues[yaxis][xaxis];
                            boardvalues[yaxis][xaxis] = boardvalues[selecty][selectx];
                            select = 0;
                            boardvalues[selecty][selectx] = 0;
                            turn = 1;

                        }
                    }
                    if(boardvalues[selecty][selectx]==10)
                    {
                        int xchange = fabs(selectx-xaxis);
                        int ychange = fabs(selecty-yaxis);
                        if(xchange==ychange)
                        {
                            changedvalue = boardvalues[yaxis][xaxis];
                            boardvalues[yaxis][xaxis] = boardvalues[selecty][selectx];
                            select = 0;
                            boardvalues[selecty][selectx] = 0;
                            turn = 1;

                        }


                    }
                    if(boardvalues[selecty][selectx]==11)
                    {
                        int xchange = fabs(selectx-xaxis);
                        int ychange = fabs(selecty-yaxis);
                        if(xchange==1 && ychange==1)
                        {
                            changedvalue = boardvalues[yaxis][xaxis];
                            boardvalues[yaxis][xaxis] = boardvalues[selecty][selectx];
                            select = 0;
                            boardvalues[selecty][selectx] = 0;
                            turn = 1;

                        }
                        if(((yaxis==selecty+1)&&(selectx==xaxis))||((yaxis==selecty-1)&&(selectx==xaxis)))
                        {
                            changedvalue = boardvalues[yaxis][xaxis];
                            boardvalues[yaxis][xaxis] = boardvalues[selecty][selectx];
                            select = 0;
                            boardvalues[selecty][selectx] = 0;
                            turn = 1;

                        }
                        if(((yaxis==selecty)&&(selectx==xaxis+1))||((yaxis==selecty)&&(selectx==xaxis-1)))
                        {
                            changedvalue = boardvalues[yaxis][xaxis];
                            boardvalues[yaxis][xaxis] = boardvalues[selecty][selectx];
                            select = 0;
                            boardvalues[selecty][selectx] = 0;
                            turn = 1;

                        }



                    }
                    if(boardvalues[selecty][selectx]==12)
                    {
                        int xchange = fabs(selectx-xaxis);
                        int ychange = fabs(selecty-yaxis);
                        if(xchange==ychange)
                        {
                            changedvalue = boardvalues[yaxis][xaxis];
                            boardvalues[yaxis][xaxis] = boardvalues[selecty][selectx];
                            select = 0;
                            boardvalues[selecty][selectx] = 0;
                            turn = 1;

                        }
                        if((yaxis==selecty)||(xaxis==selectx))
                        {
                            changedvalue = boardvalues[yaxis][xaxis];
                                    boardvalues[yaxis][xaxis] = boardvalues[selecty][selectx];
                                    select = 0;
                                    boardvalues[selecty][selectx] = 0;
                                    turn = 1;

                         }
                    }
                    }
                    if(changedvalue==0)
                    {
                        deletepieces();
                        drawboard();
                    }
                    //the following code is used to delete the piece that has been elimiated
                    if(changedvalue==1)
                    {
                        delete blackPawns[blackPawnsLeft-1];
                        blackPawnsLeft = blackPawnsLeft-1;
                        deletepieces();//this method is to delete all the remaining pieces on the board. I am deleteing all because if not when we change the color of the pieces to highlight the  turn there are copies of pieces with the old colors
                        drawboard();// to place all the pieces in their new locations
                    }
                    else if(changedvalue==2)
                    {
                        delete blackRooks[blackRooksLeft-1];
                        blackRooksLeft = blackRooksLeft-1;
                        deletepieces();
                        drawboard();
                    }
                    else if(changedvalue==3)
                    {
                        delete blackKnights[blackKnightsLeft-1];
                        blackKnightsLeft = blackKnightsLeft-1;
                        deletepieces();
                        drawboard();
                    }
                    else if(changedvalue==4)
                    {
                        delete blackBishops[blackBishopsLeft-1];
                        blackBishopsLeft = blackBishopsLeft-1;
                        deletepieces();
                        drawboard();
                    }
                    else if(changedvalue==5)
                    {
                        delete blackKing;
                        blackKingLeft =  0;
                        deletepieces();
                        drawboard();
                    }
                    else if(changedvalue==6)
                    {
                        delete blackQueen;
                        blackQueenLeft = 0;
                        deletepieces();
                        drawboard();

                    }
                    else if(changedvalue==7)
                    {
                        delete whitePawns[whitePawnsLeft-1];
                        whitePawnsLeft = whitePawnsLeft-1;
                        deletepieces();
                        drawboard();

                    }
                    else if(changedvalue==8)
                    {
                        delete whiteRooks[whiteRooksLeft-1];
                       whiteRooksLeft = whiteRooksLeft-1;
                       deletepieces();
                       drawboard();

                    }
                    else if(changedvalue==9)
                    {
                        delete whiteKnights[whiteKnightsLeft-1];
                        whiteKnightsLeft = whiteKnightsLeft-1;
                        deletepieces();
                        drawboard();
                    }
                    else if(changedvalue==10)
                    {
                        delete whiteBishops[whiteBishopsLeft-1];
                        whiteBishopsLeft = whiteBishopsLeft-1;
                        deletepieces();
                        drawboard();
                    }
                    else if(changedvalue==11)
                    {
                     delete whiteKing;
                     whiteKingLeft = 0;
                     deletepieces();
                     drawboard();
                    }
                    else if(changedvalue==12)
                    {
                        delete whiteQueen;
                        whiteQueenLeft = 0;
                        deletepieces();
                        drawboard();
                    }
                    select = 0;
                }

            }
}
int play(int round, char player1[15], char player2[15]){
    /*fungsi play berfungsi untuk menjalankan algoritma permainan,
    terutama dalam memindahkan bidak-bidaknya.*/
    char square[10] = {'o','1','2','3','4','5','6','7','8','9'};
	int player=1,i,choice,choice2,turn=1, flag_salah=0, flag_salah1=0;
	char mark;
	do { //dilakukan selama kondisi win tidak terpenuhi
		drawboard(square, player1, player2, round);
		player=(player%2)?1:2;

		if(turn<=6) //algoritma saat ketiga bidak belum keluar
		{
			cout << "Player " << player << ", enter a number:  ";
			cin >> choice;

			mark=(player == 1) ? 'X' : 'O';

			if (choice == 1 && square[1] == '1') square[1] = mark;
			else if (choice == 2 && square[2] == '2') square[2] = mark;
			else if (choice == 3 && square[3] == '3') square[3] = mark;
			else if (choice == 4 && square[4] == '4') square[4] = mark;
			else if (choice == 5 && square[5] == '5') square[5] = mark;
			else if (choice == 6 && square[6] == '6') square[6] = mark;
			else if (choice == 7 && square[7] == '7') square[7] = mark;
			else if (choice == 8 && square[8] == '8') square[8] = mark;
			else if (choice == 9 && square[9] == '9') square[9] = mark;
			else
			{
				cout << endl <<"Kesalahan langkah awal, permainan harus diulang dari awal";
				Sleep(4000);
				system("cls");
				main();
				player--;
				cin.ignore();
				cin.get();
			}
		}
		else //algoritma saat ketiga bidak sudah keluar
		{
			cout << "Player " << player << ", hapus:  ";
			cin >> choice;
	        cout << "Player " << player << ", ke:  ";
			cin >> choice2;
			mark=(player == 1) ? 'X' : 'O';
			if (choice == 1 && square[1] == 'X' && player == 1) square[1] = '1';
			else if (choice == 2 && square[2] == 'X' && player == 1) square[2] = '2';
			else if (choice == 3 && square[3] == 'X' && player == 1) square[3] = '3';
			else if (choice == 4 && square[4] == 'X' && player == 1) square[4] = '4';
			else if (choice == 5 && square[5] == 'X' && player == 1) square[5] = '5';
			else if (choice == 6 && square[6] == 'X' && player == 1) square[6] = '6';
			else if (choice == 7 && square[7] == 'X' && player == 1) square[7] = '7';
			else if (choice == 8 && square[8] == 'X' && player == 1) square[8] = '8';
			else if (choice == 9 && square[9] == 'X' && player == 1) square[9] = '9';
			else{
	            if(player == 1)flag_salah = 1;
			}

			if (choice == 1 && square[1] == 'O' && player == 2)	square[1] = '1';
			else if (choice == 2 && square[2] == 'O' && player == 2) square[2] = '2';
			else if (choice == 3 && square[3] == 'O' && player == 2) square[3] = '3';
			else if (choice == 4 && square[4] == 'O' && player == 2) square[4] = '4';
			else if (choice == 5 && square[5] == 'O' && player == 2) square[5] = '5';
			else if (choice == 6 && square[6] == 'O' && player == 2) square[6] = '6';
			else if (choice == 7 && square[7] == 'O' && player == 2) square[7] = '7';
			else if (choice == 8 && square[8] == 'O' && player == 2) square[8] = '8';
			else if (choice == 9 && square[9] == 'O' && player == 2) square[9] = '9';
			else{
	            if(player == 2) flag_salah1 = 1;
			}

			if (choice2 == 1 && square[1] == '1' && flag_salah == 0 && flag_salah1 == 0) //&& square[1] != 'X' && square[1] != 'O')
				square[1] = mark;
			else if (choice2 == 2 && square[2] == '2' && flag_salah == 0 && flag_salah1 == 0) //&& square[2] != 'X' && square[2] != 'O'
				square[2] = mark;
			else if (choice2 == 3 && square[3] == '3' && flag_salah == 0 && flag_salah1 == 0) //&& square[3] != 'X' && square[3] != 'O')
				square[3] = mark;
			else if (choice2 == 4 && square[4] == '4' && flag_salah == 0 && flag_salah1 == 0) //&& square[4] != 'X' && square[4] != 'O')
				square[4] = mark;
			else if (choice2 == 5 && square[5] == '5' && flag_salah == 0 && flag_salah1 == 0) //&& square[5] != 'X' && square[5] != 'O')
				square[5] = mark;
			else if (choice2 == 6 && square[6] == '6' && flag_salah == 0 && flag_salah1 == 0) //&& square[6] != 'X' && square[6] != 'O')
				square[6] = mark;
			else if (choice2 == 7 && square[7] == '7' && flag_salah == 0 && flag_salah1 == 0) //&& square[7] != 'X' && square[7] != 'O')
				square[7] = mark;
			else if (choice2 == 8 && square[8] == '8' && flag_salah == 0 && flag_salah1 == 0) //&& square[8] != 'X' && square[8] != 'O')
				square[8] = mark;
			else if (choice2 == 9 && square[9] == '9' && flag_salah == 0 && flag_salah1 == 0) //&& square[9] != 'X' && square[9] != 'O')
				square[9] = mark;
			else // kondisi invalid move pada langkah lebih dari 6
			{
				cout<<"Invalid move ";
				if(flag_salah == 0 && flag_salah1 == 0)
				{
					if(player == 1) square[choice] = 'X';
					else square[choice] = 'O';
				}
				player--;
				cin.ignore();
				cin.get();
			}
		}
		i = checkconditionwin(square); // cek kondisi menang
        flag_salah = 0;
		flag_salah1 = 0;
		player++;
		turn++;
	}while(i==-1); // cek kondisi loop, harus belum ada yang menang
Example #21
0
int objdesign (int dx, int dy) {				// Returns 1 if need redraw
	static int lastobj=0;
	int n;
	int fontnum;
	int objnum=-1;
	int editobj=0;
	char *ourobjname;
	char tempstr[64];

	dx = dx*16; dy = dy*16+disy;

	for (n=0; n<numobjs; n++) {
		if ((objs[n].x==dx)&&(objs[n].y==dy)) {
			objnum=n;
			ourobjname=kindname[objs[n].objkind];
			};
		};
	if (objnum==-1) ourobjname="NONE";

	fontcolor (&statvp,6,0);
	clearvp (&statvp);
	wprint (&statvp,2,1,2,  "Obj: Add Oov");
	wprint (&statvp,2,11,2, "     Del Paste");
	wprint (&statvp,2,21,2, "     Kopy Mod");
	wprint (&statvp,102,1,2,"Kind: ");
	fontcolor (&statvp,3,0);
	wprint (&statvp,102,11,2,ourobjname);
	fontcolor (&statvp,6,0);
	key=toupper (wgetkey(&statvp,102,21,2));
	clearvp (&statvp);
	switch (key) {
		case 'A':
			objnum=numobjs;
			addobj (obj_killme,dx,dy,0,0);
			editobj=1; break;
		case 'D':
			if (objnum>0) objs[objnum].objkind=obj_killme;
			return (1);
		case 'P':
			addobj (objs[lastobj].objkind,dx,dy,0,0);
			memcpy (&(objs[numobjs-1]),&(objs[lastobj]),
				sizeof(objs[lastobj]));
			objs[numobjs-1].x=dx;
			objs[numobjs-1].y=dy;
			return (1);
		case 'O':										// mOov object
			objs[lastobj].x=dx;
			objs[lastobj].y=dy;
			drawboard();
			return (1);
		case 'K':
			if (objnum>=0) lastobj=objnum; break;
		case 'M':
			if (objnum>=0) editobj=1; break;
		};

	if (editobj) {
		printobjinfo (objnum);
		strcpy (tempstr,kindname[objs[objnum].objkind]);
		winput (&statvp,38,1,2,tempstr,12);
		strupr (tempstr);
		for (n=0; n<numobjkinds; n++) {
			if (strcmp (tempstr,kindname[n])==0) {
				objs[objnum].objkind=n;	break;
				};
			};

		printobjinfo (objnum);
		itoa (objs[objnum].state,tempstr,10);
		winput (&statvp,38,11,2,tempstr,12);
		if (tempstr[0]!='\0') objs[objnum].state=atoi(tempstr);

		printobjinfo (objnum);
		itoa (objs[objnum].xd,tempstr,10);
		winput (&statvp,38,21,2,tempstr, 12);
		if (tempstr[0]!='\0') objs[objnum].xd=atoi(tempstr);

		printobjinfo (objnum);
		itoa (objs[objnum].yd,tempstr,10);
		winput (&statvp,140,1,2,tempstr, 12);
		if (tempstr[0]!='\0') objs[objnum].yd=atoi(tempstr);

		printobjinfo (objnum);
		itoa (objs[objnum].counter,tempstr,10);
		winput (&statvp,140,11,2,tempstr, 12);
		if (tempstr[0]!='\0') objs[objnum].counter=atoi(tempstr);

		objs[objnum].xl=kindxl[objs[objnum].objkind];
		objs[objnum].yl=kindyl[objs[objnum].objkind];

		if (kindflags[objs[objnum].objkind]&f_inside) {
			printobjinfo (objnum);
			if (objs[objnum].objkind==obj_text8) fontnum=1;
			else fontnum=2;
		if (objs[objnum].inside==NULL) tempstr[0]='\0';
		else strcpy (tempstr,(char*)objs[objnum].inside);

		fontcolor (&gamevp,objs[objnum].xd,objs[objnum].yd);
		winput (&gamevp,objs[objnum].x,objs[objnum].y,fontnum,tempstr, 64);

		if (objs[objnum].inside!=NULL) free (objs[objnum].inside);
		objs[objnum].inside=malloc (strlen(tempstr)+1);
		strcpy (objs[objnum].inside, tempstr);
		setobjsize (objnum);
		};
		printobjinfo (objnum);

		shm_want[kindtable[objs[objnum].objkind]]=1;
		shm_do();
		return (1);
		};
	return (0);
	};
Example #22
0
void design (void) {
	int updflag=0;
	int dx,dy,tempx,n;
	int lastcell=1;
	int tempint;
	int drawmode=0;
	char tempstr[32];
	char tempfname[32];
	char tempstr2[12];
	char tempstr3[32];
	int new_col=0;
	int bc_x=0,bc_y=0,bc_w=0,bc_h=0;		// Block copy x,y and width,height
	int tx,ty;

	disy=0;
	designflag=1;
	gamecount=0;
	tempstr[0]='\0';
	tempfname[0]='\0';
	setorigin();
	dx=objs[0].x/16;
	dy=objs[0].y/16;
	drawboard();
	fontcolor (&statvp,1,0);
	clearvp (&statvp);

	do {
		if (drawmode) {
			setboard (dx,dy,lastcell);
			drawcell (dx,dy);
			updflag=1;
			}
		fontcolor (&statvp,3,0);						// memory usage
		wprint (&statvp,248,1,2,"       ");
		ultoa (coreleft(),tempstr3,10);
		wprint (&statvp,290-(1+strlen(tempstr3)*6),1,2,tempstr3);
		tempstr3[0]='\0';

		fontcolor (&statvp,1,0);
		wprint (&statvp,248,21,2, "# objs: ");
		fontcolor (&statvp,3,0);
		wprint (&statvp,296,21,2,itoa(numobjs,tempstr2,10));

		drawshape (&gamevp,0x0100,dx*16+4,dy*16+4);
		do {
			checkctrl(0);
			} while ((dx1==0)&&(dy1==0)&&(key==0)&&(updflag==0));
		updflag=0;
		modboard(dx,dy);
		upd_objs(0);
		refresh(0);
		purgeobjs();
		if ((dx1!=0)||(dy1!=0)) {
			dx+=dx1*(1+fire1*(scrnxs/2-1));
			dy+=dy1*(1+fire1*(scrnys/2-1));
			if (dx<0) dx=0;
			if (dx>=boardxs) dx=boardxs-1;
			if (dy<0) dy=0;
			if (dy>=boardys) dy=boardys-1;
			if ((dx*16)<gamevp.vpox) {
				gamevp.vpox-=scrnxs*8;
				if (gamevp.vpox<0) gamevp.vpox=0;
				drawboard();
				};
			if ((dx*16)>=(gamevp.vpox+16*scrnxs-16)) {
				gamevp.vpox+=scrnxs*8;
				if (gamevp.vpox>=(16*(boardxs-scrnxs)+8))
					gamevp.vpox=16*(boardxs-scrnxs)+8;
				drawboard();
				};
			if ((16*dy)<gamevp.vpoy) {
				gamevp.vpoy-=scrnys*8;
				if (gamevp.vpoy<0) gamevp.vpoy=0;
				drawboard();
				};
			if ((16*dy)>=(gamevp.vpoy+16*(scrnys-1))) {
				gamevp.vpoy+=scrnys*8;
				if (gamevp.vpoy>=(16*(boardys-scrnys+1)))
					gamevp.vpoy=(boardys-scrnys+1)*16;
				drawboard();
				};
			};

		switch (toupper(key)) {
			case k_f1:					// Mark top left corner of block
				bc_x=dx; bc_y=dy; break;
			case k_f2:
				// Mark bottom right corner of block and copy
				//	block of tile numbers into temp array bc_array
				if(dx<bc_x) break;
					// 0-width or negative width rectangle	(can't do that)
				if(dy<bc_y) break;
					// 0-height or negative height rectangle (can't do that)
				bc_w=(dx-bc_x)+1; bc_h=(dy-bc_y)+1;
				if((bc_w>normxs)||(bc_h>normys)) {			// Too big!!
					bc_w=0; bc_h=0; break;
					};
				for(ty=0; ty<bc_h; ty++) {
					for(tx=0; tx<bc_w; tx++) {
						bc_array[(ty*bc_w)+tx]=board(bc_x+tx,bc_y+ty);
						};
					};	break;
			case k_f3:
				for(ty=0; ty<bc_h; ty++) {
					for(tx=0; tx<bc_w; tx++) {
						setboard(dx+tx, dy+ty, bc_array[(ty*bc_w)+tx]);
						};
					};	updflag=1; break;
			case k_f4:
				do {
					upd_colors (); gamecount++; checkctrl0(0);
					} while (key==0); break;
			case enter:
				clearvp (&statvp);
				wprint (&statvp,2,1,1,"Put:");
				fontcolor (&statvp,6,0);
				winput (&statvp,2,11,1,tempstr,16);
				strupr (tempstr);
				for (tempint=0; tempint<numinfotypes; tempint++) {
					if (strcmp (tempstr,info[tempint].na)==0) {
						lastcell=tempint;
						setboard(dx,dy,tempint);
						shm_want[(info[tempint].sh>>8)&0x3f]=1;
						shm_do(); break;
						};
					};
				updflag=1; break;
			case 9: drawmode=!drawmode; break;				// tab
			case 'K': lastcell=board(dx,dy); break;
			case ' ':
				setboard(dx,dy,lastcell);
				updflag=1; break;
			case 'I':
				pl.score=1000;
				printhi (1);
				pl.score=0; break;
			case 'V':
				if (pl.numinv==0) addinv (inv_hero);
				else {
					pl.numinv=0;
					init_inv();
					};
				pl.score=0;
				pl.level=0; break;
			case 'H':
				tempint=board(dx,dy);
				tempx=dx;
				while (board(tempx,dy)==tempint) {
					setboard(tempx,dy,lastcell);
					drawcell (tempx,dy);
					tempx--;
					};
				tempx=dx+1;
				while (board(tempx,dy)==tempint) {
					setboard(tempx,dy,lastcell);
					drawcell (tempx,dy);
					tempx++;
					}; break;
			case 'O': updflag=objdesign(dx,dy); break;	// Object Mgmt
			case 'U':
				for (n=0; n<numobjs; n++) {
//					if (((kindflags[objs[n].objkind]&f_inside)==0)&&
//						(objs[n].inside!=NULL)) {
//						objs[n].inside=NULL;
//						sound(240);
//						delay(500);
//						nosound();
//						};
					setobjsize (n);
					}; break;
			case 'Z':
				infname ("Clear?",tempfname);
				if (toupper(tempfname[0])=='Y') {
					init_brd();
					init_objs();
					drawboard();
					}; break;
			case 'L':
				infname ("Load:",tempfname);
				if (tempfname[0]!='\0') {
					loadboard (tempfname);
					setorigin();
					dx=objs[0].x/16; dy=objs[0].y/16;
					drawboard();
					}; break;
			case 'Y':												// Disalign Y
				clearvp (&statvp);
				wprint (&statvp,2,1,1,"Dis Y:");
				itoa (disy,tempstr,10);
				winput (&statvp,2,11,1,tempstr,16);
				disy=atoi (tempstr);
				strupr (tempstr); break;
			case 'N':
				infname ("New board?",tempfname);
				if (toupper (tempfname[0])=='Y') {
					zapobjs();
					init_brd();
					}; break;
			case 'S':
				infname ("Save:",tempfname);
				if (tempfname[0]!='\0') saveboard (tempfname); break;
			case 'C':
				clearvp (&statvp);
				wprint (&statvp,2,1,1,"New Color:");
				fontcolor (&statvp,6,0);
				itoa (new_col,tempstr,10);
				winput (&statvp,2,11,1,tempstr,16);
				new_col=atoi (tempstr);

				switch (new_col) {
					case 0: setcolor (250,0,0,0);
						setcolor (251,0,0,0); break;				// reset all
					case 1: setcolor (251,0,0,0); break;		// reset #251
					case 2: setcolor (250,0,0,32);		 		// dk. blue sky
						setcolor (251,0,0,32); break;
					case 3:												// lt. blue sky
						setcolor (176,8,16,25); setcolor (177,8,20,29);
						setcolor (178,12,24,33); setcolor (179,16,28,41);
						setcolor (180,20,32,45); setcolor (181,24,40,49);
						setcolor (182,28,44,57); setcolor (183,36,48,60);
						setcolor (250,36,48,60); setcolor (251,36,48,60); break;
					case 4:												// yellow sky
						setcolor (176,32,0,0); setcolor (177,40,0,0);
						setcolor (178,52,0,0); setcolor (179,60,0,0);
						setcolor (180,60,28,0); setcolor (181,60,40,0);
						setcolor (182,60,52,0); setcolor (183,60,60,0);
						setcolor (250,60,60,0);	setcolor (251,60,60,0); break;
					case 5:												// emerald sky
						setcolor (176,0,12,12); setcolor (177,0,18,17);
						setcolor (178,0,25,23); setcolor (179,0,32,27);
						setcolor (180,0,39,32); setcolor (181,0,46,35);
						setcolor (182,0,53,38); setcolor (183,0,60,40);
						setcolor (250,0,60,40); setcolor (251,0,60,40); break;
					case 6: setcolor (250,32,32,24);				// olive green
						setcolor (251,32,32,24); break;
					case 7:												// violet sky
						setcolor (176,13,5,22); setcolor (177,18,8,27);
						setcolor (178,23,13,33); setcolor (179,29,19,39);
						setcolor (180,35,25,45); setcolor (181,42,32,51);
						setcolor (182,49,40,57); setcolor (183,57,50,63);
						setcolor (250,57,50,63); setcolor (251,57,50,63); break;
					case 8: setcolor (250,23,23,23);				// factory grey
						setcolor (251,23,23,23); break;
					case 9: setcolor (250,12,23,63);		 		// royal blue
						setcolor (251,12,23,63); break;
					case 10: setcolor (250,20,20,23);			// factory grey v3
						setcolor (251,20,20,23); break;
					};
			};
		} while (key!=escape);
Example #23
0
int main(int argc, char* argv[])
{
    //make window
    if(!init())
    {
        cout<<"Init failed";
    }
    
    //loads buttons and sprites
    loadMedia();
    
    bool quit=false;
    
    int menubutton=0;
    
    SDL_Event e;
    
    
    while(quit!=true)
    {
        while(SDL_PollEvent(&e)!=0)
        {
            //quits game
            if(e.type==SDL_QUIT)
            {
                quit=true;
            }
            
            //clears board during game
            if(e.key.keysym.sym==SDLK_SPACE)
            {
                clearBoard();
            }
            
            //returns to menu
            if(e.key.keysym.sym==SDLK_ESCAPE)
            {
                if(startgame==true)
                {
                    gamecontinue=true;
                }
                startgame=false;
                aboutstate=false;
            }

            //click during game to play
            if(e.type==SDL_MOUSEBUTTONDOWN && startgame==true)
            {
                if(checkGameOver()==true)
                {
                    clearBoard();
                }
                
                else
                {
                    SDL_GetMouseState( &x, &y );
                    
                    tile=whichButton(x,y);
                }
            }
            
            //click either start or about
            if(e.type==SDL_MOUSEBUTTONDOWN && startgame==false)
            {
                SDL_GetMouseState( &x, &y );
                
                menubutton=whichButton(x,y);
                
                if(menubutton==0)
                {
                    startgame=true;
                }
                else if(menubutton==1)
                {
                    aboutstate=true;
                }
                
            }
        }
        
        if(startgame==false && aboutstate==false)
        {
            menu();
        }
        
        else if(startgame==false && aboutstate==true)
        {
            about();
        }
        
        else if(startgame==true && aboutstate==false)
        {
            SDL_SetRenderDrawColor( gRenderer, 0xFF, 0xFF, 0xFF, 0xFF );
            SDL_RenderClear(gRenderer);
            
            play();
            drawboard();

            if(checkGameOver()==true)
            {
                announceWinner();
            }
            
        }

        SDL_RenderPresent(gRenderer);
        
        SDL_Delay(100);
        
    }
    
    close();
    
    return 0;
}
Example #24
0
void draw() {
	drawboard();
	drawknight();
}
Example #25
0
//--------------------------------------------------------------
void testApp::draw(){
    ofBackground(128,128,128); //gray
    drawboard();
    drawSpares();
}