The world’s Largest Sharp Brain Virtual Experts Marketplace Just a click Away
Levels Tought:
Elementary,Middle School,High School,College,University,PHD
| Teaching Since: | Apr 2017 |
| Last Sign in: | 103 Weeks Ago, 3 Days Ago |
| Questions Answered: | 4870 |
| Tutorials Posted: | 4863 |
MBA IT, Mater in Science and Technology
Devry
Jul-1996 - Jul-2000
Professor
Devry University
Mar-2010 - Oct-2016
Could someone please help me with my code? I want d2 (beat.aiff sound file) to play when a player wins but it won't play for me. I also want the game to return to a new game by pressing the space bar when it's game over and I want to add a small display of fireworks in the background when a player wins. Could someone help me with this? (See code below) int w = 7; int h = 6; int bs = 100; //blockSpace int player = 1; int[][] board = new int[h][w]; void setup() { size(700,600); ellipseMode(CORNER); //draw circles from their top left point } int p(int y, int x) { return (y < 0 || x < 0 || y >= h || x >= w) ? 0 : board[y][x]; } int getWinner() { //loops through rows, columns, diagonals, etc for (int y=0;y= 0;y--) if (board[y][x]==0) return y; return -1; } void mousePressed() { int x = int(mouseX / bs), y = nextSpace(x); if (y >= 0) { board[y][x] = player; //this is not the final solution player = player==1?2:1; //switch to the other player (1->2 2->1) } } void draw() { if (getWinner()==0) { for (int j=0;j0) { fill(board[j][i]==1?255:0, board[j][i]==2?255:0, 0); ellipse(i*bs, j*bs, bs, bs); } } } else { background(0); fill(0,100,180); textSize(30); // Display score information on the screen text("Player "+getWinner()+" wins. ",width/2.85,height/2); if(keyPressed == true) { //keyPressed == ' '; } } }
-----------