1 / 4

Four Way Connect Four Fall

Four Way Connect Four Fall. Alicia Korpi. The purpose of the game is to get four of your color circles in a row. Unlike traditional ‘Connect Four’ games, the pieces can fall from each side of the board.

chloris
Download Presentation

Four Way Connect Four Fall

An Image/Link below is provided (as is) to download presentation Download Policy: Content on the Website is provided to you AS IS for your information and personal use and may not be sold / licensed / shared on other websites without getting consent from its author. Content is provided to you AS IS for your information and personal use only. Download presentation by click this link. While downloading, if for some reason you are not able to download a presentation, the publisher may have deleted the file from their server. During download, if you can't get a presentation, the file might be deleted by the publisher.

E N D

Presentation Transcript


  1. Four Way Connect Four Fall Alicia Korpi

  2. The purpose of the game is to get four of your color circles in a row. • Unlike traditional ‘Connect Four’ games, the pieces can fall from each side of the board. • The circles will ‘fall’ to the other side of the board, unless they hit into another circle or they meet the ‘rocks.’ • The ‘rocks’ are four randomly placed roadblocks in each game so that the pieces can’t move past them. • The game is over when a player gets four of their circles in a row, and they win or there are no more spaces on the board and it is a tie.

  3. for(int r= 0; r<10; r++) { int c = 0; while(c<10) { if (board[r][c]==1) { count1++; count2=0; } if(board[r][c]==2) { count2++; count1=0; } if(board[r][c]==0 || board[r][c]==3) { count1=0; count2=0; } if (count1==4) { isaWinner(1); returntrue; } if (count2==4) { isaWinner(2); returntrue; } c++; r++; } } • One of the more difficult aspects of this game was finding a simple way to check if there was a winner. • Unlike tic-tac-toe, it would be very complicated to check separately for any diagonal wins. • I used several for-loops in effort to reduce the amount code needed to determine if there was a winner.

  4. if (r==0) { while(true) { int row = 0 + i; if (row==10) return; if(board[c-1][row]==0 && row==0) { board[c-1][row] = playerId; if (playerId==1) StdDraw.setPenColor(StdDraw.BLUE); if (playerId==2) StdDraw.setPenColor(StdDraw.RED); StdDraw.filledCircle(c+.5, row+1.5, .40); } elseif(board[c-1][row]==0 && row!=0) { //clear previous StdDraw.setPenColor(StdDraw.BLACK); StdDraw.filledSquare(c+.5, row+.5, .47); board[c-1][row-1]=0; board[c-1][row] = playerId; if (playerId==1) StdDraw.setPenColor(StdDraw.BLUE); if (playerId==2) StdDraw.setPenColor(StdDraw.RED); StdDraw.filledCircle(c+.5, row+1.5, .40); } elseif(board[c-1][row]!=0) { return; } StdDraw.show(500); i++; } • To make the circles ‘fall’ to the other side, I made a while loop for the animation. • When they were falling, before they could move to the next spot, I had to check to make sure that there were no other circles or ‘rocks’ in the next open spot.

More Related