CSE 115 Week 12 March 31 – April 4, 2008

advertisement
CSE 115
Week 12
March 31 – April 4, 2008
Announcements




March 31 – Exam 8
April 6 – Last day to turn in Lab 7 for a max
grade of 100%, last dayt to turn in Lab 8 for
a 20% bonus.
April 7 – Exam 9
April 10 – Last day to turn in Lab 7 for any
credit, last day to turn in Lab 8 for extra
credit presentations, Milestone build 1 for
Lab 9 due
Week’s Topics


Created code to look in a row of a Tic
Tac Toe board to see if there was
exactly one X, one O and one blank.
Repetition using a for-loop
Week’s Topics
 For-loop syntax
for(declaration/initialization; boolean
expression; increment) {
//loop body
}
Declaration/initialization of the loop counter
variable (usually)
Boolean expression that tells when the loop
should stop
Increment the loop counter variable (usually)
Week’s Topics



The initialization/declaration happens
first.
Then, the boolean expression is
evaluated. If true, the loop body is
executed, and then the increment is
executed. (Now loop back to the
beginning of this bullet).
If false, the loop ends.
Week’s Topics



If-statements
Way to select code to execute on the
result of a boolean expression.
Can be evaluation of an expression
that returns a boolean or a method
that returns a boolean value.
Week’s Topics

Syntax:
if(boolean expression) {
//code to be executed if b.e.
//is true
}
Week’s Topics


Two choices – if/else
Syntax:
if(boolean expression) {
//code to be executed if b.e. is true
}
else {
//code to be executed if b.e.is false
}
Week’s Topics


Building the game memory
Take a moment to think about what
are the important aspects/tasks we
will need to build to create this game.
List of Tasks for Memory








Cells with mouse click listeners
Hash map
Something to put into the hash map
(images)
2 hash maps, why?
Cell and symbol
Symbol and location
Random number generator to assign the
location of the cards (shuffling)
Switch turns
List of Tasks for Memory






Counter for knowing turns
Keep randomizer from putting 2 cards in the
same place
Graphics
Row and columns need to be even
numbered, even number of cards
What about jokers?/ wild cards?
Odd number of pairs so one person can win
(maybe)
List of Tasks for Memory





When 2 images are visible, check to see if
they are same, and flip over if not same (on
a delay)
How turns are taken
If cards are same, remove them form the
board
Check to see if board is clear, determine
who won
Number of players
What do we do first?


Get a window appearing on the screen
that has a place for the cards (no
cards yet) and a menu for selecting to
start the game (no listener yet).
This code was checked into the
repository.
Download