Description: Description: Description: Description: Description: Description: Description: Description: Breaking News! Click here for details.

 CSC 131 - Introduction to Computer Science

Homework 8 – Due Thursday, November 2, 11:59pm

Submitted on Blackboard (learn.uncw.edu)

Programs based on material from Chapter 5 and 6.

 

Program 1: Colored Bouncing Balls

Modify the bouncing balls program we did in class so that it creates balls with randomly generated colors.  Each ball should have its own randomly generated color.  This will require generating some random Red, Green, Blue values and then setting the turtle’s color.   The following is needed to use RGB values:

 

turtle.colormode(255)

 

And the following sets the turtle’s color to something like magenta:

 

newBall.color(200, 40, 100)

 

You’ll use random values instead of 200, 40 and 100.

 

 

Program 2: Tic-Tac-Toe

Do not use Turtle graphics for this program.  Just do everything by reading and writing text to the console.

 

Now that you have a method to determine whether a board is a win for a tic-tac-toe player (from the last homework), develop a program that lets two human players play the game.  Figure out some way of having them enter where they want to place their symbol.   Then, after each move, print out the board so that it looks nice.   If one player wins, announce the winner and do not allow them to place any more symbols.  

 

Here’s one way to implement this:

 

 

 1 | 2 | 3

-----------

 4 | 5 | 6

-----------

 7 | 8 | 9

 

X, where would you like to play? 5

 

 1 | 2 | 3

-----------

 4 | X | 6

-----------

 7 | 8 | 9

 

O, where would you like to play? 9

 

 1 | 2 | 3

-----------

 4 | X | 6

-----------

 7 | 8 | O

 

X, where would you like to play? 1

 

 X | 2 | 3

-----------

 4 | X | 6

-----------

 7 | 8 | O

 

O, where would you like to play? 5

That spot is taken. Try again.

 

 X | 2 | 3

-----------

 4 | X | 6

-----------

 7 | 8 | O

 

O, where would you like to play? 3

 

 X | 2 | O

-----------

 4 | X | 6

-----------

 7 | 8 | O