SYSC 2004 Lecture Notes - Lecture 3: Tic-Tac-Toe

135 views2 pages

Document Summary

* a class modelling a tic-tac-toe (noughts and crosses, xs and os) game. * constructs a new tic-tac-toe board. public tictactoe() board = new string[3][3]; * sets everything up for a new game. Marks all squares in the tic tac toe board as empty, * plays one game of tic tac toe. public void playgame() int row, col; // loop until the game ends while (winner==empty) { // game still in progress. // get input (row and column) while (true) { // repeat until valid input. System. out. print("enter row and column of chosen square (0, 1, 2 for each): "); sc = new scanner(system. in); row = sc. nextint(); col = sc. nextint(); if (row>=0 && row<=2 && col>=0 && col<=2 && board[row] System. out. println("invalid selection, try again. board[row][col] = player; // fill in the square with player numfreesquares--; // decrement number of free squares.

Get access

Grade+20% off
$8 USD/m$10 USD/m
Billed $96 USD annually
Grade+
Homework Help
Study Guides
Textbook Solutions
Class Notes
Textbook Notes
Booster Class
40 Verified Answers
Class+
$8 USD/m
Billed $96 USD annually
Class+
Homework Help
Study Guides
Textbook Solutions
Class Notes
Textbook Notes
Booster Class
30 Verified Answers

Related Documents