{[ promptMessage ]}

Bookmark it

{[ promptMessage ]}

Lec12

# Lec12 - Lecture 12 Scope Functions PIC 10A Todd Wittman...

This preview shows pages 1–4. Sign up to view the full content.

1 Lecture 12: PIC 10A Todd Wittman Planning the Tic-Tac-Toe Program c Draw grid. c Repeat the following for 9 turns On turn 1,3,5,7,9 c Get mouse click for X c Draw X at the point On turn 2,4,6,8 c Get mouse click for O c Draw O at that point c Ask the user if they want to play again. c If yes, clear the screen and go back to drawing the grid.

This preview has intentionally blurred sections. Sign up to view the full version.

View Full Document
2 Rewrite the Tic-Tac-Toe Program with Functions c The process we just went through is called writing pseudocode . You plan the program out, but it’s not really written in C++ or any other programming language. c Now let’s go from pseudocode to code. c Suppose we have the following functions: void DrawGrid ( ) Point getClickX ( ) Point getClickO ( ) void DrawX ( Point p ) void DrawO ( Point p ) c You actually coded up all these steps for HW3, but you may not have put them into functions. c Let's write these functions together. .. int ccc_win_main ( ) { string response = "y"; int turn; while ( response == "y" ) { DrawGrid ( ); turn = 1; while ( turn <= 9) { if (turn%2 == 1) DrawX ( getClickX( ) ); else DrawO ( getClickO( ) ); turn++; } response = cwin.get_string ( "Do you want to play again? (y/n)" ); cwin.clear( ); } return 0; }
3 Rewrite the Tic-Tac-Toe Program Again c Now play Tic-Tac-Toe again, this time declaring the winner. c

This preview has intentionally blurred sections. Sign up to view the full version.

View Full Document
This is the end of the preview. Sign up to access the rest of the document.

{[ snackBarMessage ]}

### Page1 / 7

Lec12 - Lecture 12 Scope Functions PIC 10A Todd Wittman...

This preview shows document pages 1 - 4. Sign up to view the full document.

View Full Document
Ask a homework question - tutors are online