Project 1 - Tic Tac Toe - Hampden-Sydney Tic Tac Toe Functions Strategy Introduction In this project

download Project 1 - Tic Tac Toe - Hampden-Sydney Tic Tac Toe Functions Strategy Introduction In this project

If you can't read please download the document

  • date post

    19-Apr-2020
  • Category

    Documents

  • view

    16
  • download

    0

Embed Size (px)

Transcript of Project 1 - Tic Tac Toe - Hampden-Sydney Tic Tac Toe Functions Strategy Introduction In this project

  • Project 1

    Robb T. Koether

    Introduction

    Drawing the Game Board

    Handling Resizing Events

    Handling Mouse Events

    The Game Logic

    Tic Tac Toe Functions

    Strategy

    Project 1 Tic Tac Toe

    Robb T. Koether

    Hampden-Sydney College

    Fri, Sep 9, 2011

  • Project 1

    Robb T. Koether

    Introduction

    Drawing the Game Board

    Handling Resizing Events

    Handling Mouse Events

    The Game Logic

    Tic Tac Toe Functions

    Strategy

    Outline

    1 Introduction

    2 Drawing the Game Board

    3 Handling Resizing Events

    4 Handling Mouse Events

    5 The Game Logic

    6 Tic Tac Toe Functions

    7 Strategy

  • Project 1

    Robb T. Koether

    Introduction

    Drawing the Game Board

    Handling Resizing Events

    Handling Mouse Events

    The Game Logic

    Tic Tac Toe Functions

    Strategy

    Outline

    1 Introduction

    2 Drawing the Game Board

    3 Handling Resizing Events

    4 Handling Mouse Events

    5 The Game Logic

    6 Tic Tac Toe Functions

    7 Strategy

  • Project 1

    Robb T. Koether

    Introduction

    Drawing the Game Board

    Handling Resizing Events

    Handling Mouse Events

    The Game Logic

    Tic Tac Toe Functions

    Strategy

    Introduction

    • In this project you will write a program that displays a tic tac toe board and lets the user play the game.

    • I have provided all the tic-tac-toe logic. • You will access that logic through a set of functions.

  • Project 1

    Robb T. Koether

    Introduction

    Drawing the Game Board

    Handling Resizing Events

    Handling Mouse Events

    The Game Logic

    Tic Tac Toe Functions

    Strategy

    The User Interface

    • The user presses X to start a new game where he goes first.

    • He presses O to start a new game where the computer goes first.

    • The user clicks in the cell where he wants to move. • He presses ESC when he wants to quit.

  • Project 1

    Robb T. Koether

    Introduction

    Drawing the Game Board

    Handling Resizing Events

    Handling Mouse Events

    The Game Logic

    Tic Tac Toe Functions

    Strategy

    Your Job

    Your job is to • Provide the graphics for

    • The game grid. • The X’s. • The O’s. • The winning line.

    • Handle mouse-clicks in the window. • Handle keystrokes. • Handle resizing events.

  • Project 1

    Robb T. Koether

    Introduction

    Drawing the Game Board

    Handling Resizing Events

    Handling Mouse Events

    The Game Logic

    Tic Tac Toe Functions

    Strategy

    Outline

    1 Introduction

    2 Drawing the Game Board

    3 Handling Resizing Events

    4 Handling Mouse Events

    5 The Game Logic

    6 Tic Tac Toe Functions

    7 Strategy

  • Project 1

    Robb T. Koether

    Introduction

    Drawing the Game Board

    Handling Resizing Events

    Handling Mouse Events

    The Game Logic

    Tic Tac Toe Functions

    Strategy

    Drawing the Game Grid

    • The game grid is the traditional 3× 3 board. • It consists of two horizontal bands and two vertical

    bands on a dark green background (0, 128, 0).

  • Project 1

    Robb T. Koether

    Introduction

    Drawing the Game Board

    Handling Resizing Events

    Handling Mouse Events

    The Game Logic

    Tic Tac Toe Functions

    Strategy

    Drawing the Game Grid

    • The 9 empty squares formed by the grid should have length and width equal to CELL_WIDTH.

    • The thickness of the grid lines should be equal to GRID_WIDTH.

    GRID_WIDTH

    CELL_WIDTH

    (0,0)

  • Project 1

    Robb T. Koether

    Introduction

    Drawing the Game Board

    Handling Resizing Events

    Handling Mouse Events

    The Game Logic

    Tic Tac Toe Functions

    Strategy

    Drawing an X

    • The X should be drawn as a polygons. • The corners should be shaped as shown in the

    diagram.

  • Project 1

    Robb T. Koether

    Introduction

    Drawing the Game Board

    Handling Resizing Events

    Handling Mouse Events

    The Game Logic

    Tic Tac Toe Functions

    Strategy

    Drawing an X

    • The diagonals should be drawn at 45◦ angles. • The thickness of the X should be equal to GRID_WIDTH.

    GRID_WIDTH

  • Project 1

    Robb T. Koether

    Introduction

    Drawing the Game Board

    Handling Resizing Events

    Handling Mouse Events

    The Game Logic

    Tic Tac Toe Functions

    Strategy

    Drawing an O

    • The O should be circular. • The circle will actually be one many-sided polygon

    inside another.

  • Project 1

    Robb T. Koether

    Introduction

    Drawing the Game Board

    Handling Resizing Events

    Handling Mouse Events

    The Game Logic

    Tic Tac Toe Functions

    Strategy

    Drawing an O

    • The thickness of the O should be GRID_WIDTH.

    GRID_WIDTH

  • Project 1

    Robb T. Koether

    Introduction

    Drawing the Game Board

    Handling Resizing Events

    Handling Mouse Events

    The Game Logic

    Tic Tac Toe Functions

    Strategy

    The Cell Padding

    • The space between the X or the O and the grid lines should be equal to CELL_PADDING.

    CELL_PADDING

    CELL_PADDING

  • Project 1

    Robb T. Koether

    Introduction

    Drawing the Game Board

    Handling Resizing Events

    Handling Mouse Events

    The Game Logic

    Tic Tac Toe Functions

    Strategy

    Drawing the Winning Lines

    • Horizontal and vertical winning lines are rectangles with length equal to the size of the game grid and width equal to GRID_WIDTH.

  • Project 1

    Robb T. Koether

    Introduction

    Drawing the Game Board

    Handling Resizing Events

    Handling Mouse Events

    The Game Logic

    Tic Tac Toe Functions

    Strategy

    Drawing the Winning Lines

    • The diagonal winning lines are similar to the diagonals of the X, but they extend from one corner of the game grid to the other.

  • Project 1

    Robb T. Koether

    Introduction

    Drawing the Game Board

    Handling Resizing Events

    Handling Mouse Events

    The Game Logic

    Tic Tac Toe Functions

    Strategy

    Drawing Polygons

    • Keep in mind that OpenGL assumes that all polygons are convex.

    • If you try to draw non-convex polygons, the results are unpredictable.

    • The parameters CELL_WIDTH, GRID_WIDTH, and CELL_PADDING should be built in as constants.

    • I suggest that you create a new constant BOARD_WIDTH that is derived from the others.

    • The GL_POLYGON type has been deprecated. • Use the GL_TRIANGLE_FAN type instead.

  • Project 1

    Robb T. Koether

    Introduction

    Drawing the Game Board

    Handling Resizing Events

    Handling Mouse Events

    The Game Logic

    Tic Tac Toe Functions

    Strategy

    Outline

    1 Introduction

    2 Drawing the Game Board

    3 Handling Resizing Events

    4 Handling Mouse Events

    5 The Game Logic

    6 Tic Tac Toe Functions

    7 Strategy

  • Project 1

    Robb T. Koether

    Introduction

    Drawing the Game Board

    Handling Resizing Events

    Handling Mouse Events

    The Game Logic

    Tic Tac Toe Functions

    Strategy

    Handling Resizing Events

    • The game board should always be centered in the window.

    • It will grow or shrink with the window. • The game board is square. • If the window is wider than it is tall, then the game

    board will occupy the middle 80% vertically. • If the window is taller than it is wide, then the game

    board will occupy the middle 80% horizontally.

  • Project 1

    Robb T. Koether

    Introduction

    Drawing the Game Board

    Handling Resizing Events

    Handling Mouse Events

    The Game Logic

    Tic Tac Toe Functions

    Strategy

    Handling Resize Events

  • Project 1

    Robb T. Koether

    Introduction

    Drawing the Game Board

    Handling Resizing Events

    Handling Mouse Events

    The Game Logic

    Tic Tac Toe Functions

    Strategy

    Handling Resize Events

  • Project 1

    Robb T. Koether

    Introduction

    Drawing the Game Board

    Handling Resizing Events

    Handling Mouse Events

    The Game Logic

    Tic Tac Toe Functions

    Strategy

    Handling Resize Events

    x

    y

    (0, 0)

    BO AR

    D_ WI

    DT H

    (height − BOARD_WIDTH)/2

    (height − BOARD_WIDTH)/2 ymin

    ymax

    Determine ymin and ymax when aspect ratio > 1

  • Project 1

    Robb T. Koether

    Introduction

    Drawing the Game Board

    Handling Resizing Events

    Handling Mouse Even