Lec12 - Lecture 12: Scope & Functions PIC 10A Todd...

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

View Full Document Right Arrow Icon
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.
Background image of page 1

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

View Full DocumentRight Arrow Icon
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; }
Background image of page 2
3 Rewrite the Tic-Tac-Toe Program Again c Now play Tic-Tac-Toe again, this time declaring the winner. c
Background image of page 3

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

View Full DocumentRight Arrow Icon
Image of page 4
This is the end of the preview. Sign up to access the rest of the document.

Page1 / 7

Lec12 - Lecture 12: Scope &amp; Functions PIC 10A Todd...

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

View Full Document Right Arrow Icon
Ask a homework question - tutors are online