User Tools

Site Tools


joust

This is an old revision of the document!


Joust

A game I learned about from Berkeley's Professor Dan Garcia's GamesCrafters Site Two knights on a chess board that move like chess, but as they leave a square, it is “burned” (uninhabitable for either player). Players alternate moving their knight trying to avoid being the loser who is left with no place to go. Download and run joust_sfhs_2020.jar to see a working version of the game (On macs you have to go to Security and press “Open anyway” to run since it is not prom an Apple identifies developer).

This lab is set up so you can discover how to program conditional statements (more commonly called “if” statements). I have some starter code with graphics and fancy things like arrays and loops (something that we will be learning about formally very soon–think of this as an introduction to see how terribly wonderful and useful they can be). Your job will be to finish writing some vital boolean methods that will make the code work. !Under the hood # @@Square@@ objects start out either black or white (like a chess board) and become red when they are “burned” It draws itself, so it needs to know if it is highlighted. Write the @@isBurned@@ method by checking what the color is.

#Each player has a @@Knight@@ (the player's piece) which needs to keep track of its location, what color it is.

#The game's @@Board@@ has a collection of @@Square@@ objects and two @@Knight@@ objects (one for each player. It also keeps track of whose turn it is, what are legal moves, and whether the game is over (and who the winner is). Here you have to write two methods, both involving the possible moves. You'll need to use the @@isAvailable@@ method. You also need to look at certain squares. The knight can either move one over and two across, or two over and one across. You might get @@indexOutOfBounds@@ runtime errors if you forget to see if you are looking for a square that is off the board. Thank goodness Java uses 'short circut' conditional statements. Consider @@if (c<0 && isAvailable(grid[r][c]) @@ If c is less than 0, it won't go to the isAvailable method. Good thing, since it would cause a runtime error. Once the first part of the && is false, that is enough to know the whole expression is false.

#The @@Joust@@ Applet handles the user's activity. If the user is hovering over a valid move, then that particular @@Square@@ is told it is highlighted. If the user clicks on a valid move, then the current @@Knight@@ burns the current square, and moved to the new location,. If it is not a game winning move, and the current player switches.

Joust.zip

joust.1586550895.txt.gz · Last modified: 2020/04/10 16:34 by frchris

Donate Powered by PHP Valid HTML5 Valid CSS Driven by DokuWiki