CS1 Studio Project: Connect Four

Similar documents
Chapter 11 Paper Practice

public static void negate2(list<integer> t)

CS201 - Assignment 3, Part 2 Due: Wednesday March 5, at the beginning of class

/** * Tests for a class that converts scores to letter grades Merlin * */ public class PaperTest {

public static boolean isoutside(int min, int max, int value)

Program Submission Guidelines CIS/CMSC 274

Global Gomoku Lab 4 in D0010E

IT115: Introduction to Java Programming 1. IT115: Introduction to Java Programming. Tic Tac Toe Application. Trina VanderLouw

CS159 Midterm #1 Review

2D Array Practice. Lecture 26

Design of my planned contribution to the PDFBox Project

CS 201 Advanced Object-Oriented Programming Lab 6 - Sudoku, Part 2 Due: March 10/11, 11:30 PM

Project 2 - A Simple Chat Program

EECS 1001 and EECS 1030M, lab 01 conflict

ASSIGNMENT 3 Object Oriented Programming

CS 134 Programming Exercise 9:

Project 2 - MapQuest Routing Problem

Inheritance. Lecture 11 COP 3252 Summer May 25, 2017

INHERITANCE. Spring 2019

Class definition. complete definition. public public class abstract no instance can be created final class cannot be extended

Methods Common to all Classes

IBS Software Services Technical Interview Questions. Q1. What is the difference between declaration and definition?

CS161: Introduction to Computer Science Homework Assignment 10 Due: Monday 11/28 by 11:59pm

CMPSCI 187 / Spring 2015 Hangman


Class BinarySemaphore

Tic Tac Toe Game! Day 8

Programming Project: Game of Life

The class Object. Lecture CS1122 Summer 2008

D - Tic Tac Toe. Let's use our 9 sparkles to build a tic tac toe game! 2017 courses.techcamp.org.uk/ Page 1 of 9

Com S 227 Spring 2018 Assignment points Due Date: Thursday, September 27, 11:59 pm (midnight) "Late" deadline: Friday, September 28, 11:59 pm

Project 1 - Battleship Game

CONTENTS. PART 1 Structured Programming 1. 1 Getting started 3. 2 Basic programming elements 17

Be sure check the official clarification thread for corrections or updates to this document or to the distributed code.

Java Enum Java, winter semester ,2018 1

ios Tic Tac Toe Game John Robinson at Rowan University

Programming Exercise

COMP 250. Lecture 32. polymorphism. Nov. 25, 2016

CS 112 Introduction to Computing II. Wayne Snyder Computer Science Department Boston University

Solutions to Quiz 1 (March 14, 2016)

Inheritance. Transitivity

SYSC Come to the PASS workshop with your mock exam complete. During the workshop you can work with other students to review your work.

Inheritance (Extends) Overriding methods IS-A Vs. HAS-A Polymorphism. superclass. is-a. subclass

CS 177 Recitation. Week 8 Methods

ATAPI Java Reference Documentation

CSE 131 Introduction to Computer Science Fall Exam II

CS100M November 30, 2000

CSE 142, Autumn 2018 Programming Assignment #9: Critters (20 points) Due Tuesday, December 4th, 9:00 PM

Programming Project 1

CS 315 Software Design Homework 1 First Sip of Java Due: Sept. 10, 11:30 PM

Mobile Application Programming: ios

Prototyping a Swing Interface with the Netbeans IDE GUI Editor

Java GUI Test #1 Solutions 7/10/2015

Session 8.2. Finding Winners Using Arrays

CS 201 Advanced Object-Oriented Programming Lab 5 - Sudoku, Part 1 Due: March 3/4, 11:30 PM

Introduction to Bumpers

Mobile Application Programming: Android

CS 2316 Homework 9b GT Thrift Shop Due: Wednesday, April 20 th, before 11:55 PM Out of 100 points. Premise

Question 1 [20 points]

CS-140 Fall 2017 Test 2 Version A Nov. 29, 2017

MCS 2514 Fall 2012 Programming Assignment 3 Image Processing Pointers, Class & Dynamic Data Due: Nov 25, 11:59 pm.

Class definition. complete definition. public public class abstract no instance can be created final class cannot be extended

CS 170 Java Programming 1. Week 12: Creating Your Own Types

Project #1 Seam Carving

CMPSC 111 Introduction to Computer Science I Fall 2016 Lab 8 Assigned: October 26, 2016 Due: November 2, 2016 by 2:30pm

Canonical Form. No argument constructor Object Equality String representation Cloning Serialization Hashing. Software Engineering

Proctors are unable to respond to queries about the interpretation of exam questions. Do your best to answer exam questions as written.

CS211 Computers and Programming Matthew Harris and Alexa Sharp July 9, Boggle

CSE 214 Computer Science II Java Classes and Information Hiding

CS 2510 Exam 3 SOLUTION Spring 2011

Senet. Language Reference Manual. 26 th October Lilia Nikolova Maxim Sigalov Dhruvkumar Motwani Srihari Sridhar Richard Muñoz

Object Oriented Programming: In this course we began an introduction to programming from an object-oriented approach.

CSE 8B Programming Assignments Spring Programming: You will have 5 files all should be located in a dir. named PA3:

Java Classes, Inheritance, and Interfaces

CMP 326 Midterm Fall 2015

Polymorphism. return a.doublevalue() + b.doublevalue();

CS108, Stanford Handout #3. HW1 CodeCamp

University of Cape Town ~ Department of Computer Science. Computer Science 1015F ~ 2007

CS 463 Project 1 Imperative/OOP Fractals

E V R O A A I O D L N P T

Inheritance. Inheritance

The Object Class. java.lang.object. Important Methods In Object. Mark Allen Weiss Copyright 2000

Topic 5 Polymorphism. " Inheritance is new code that reuses old code. Polymorphism is old code that reuses new code.

Java Programming Training for Experienced Programmers (5 Days)

Declaring and ini,alizing 2D arrays

Assignment A7 BREAKOUT CS1110 Spring 2011 Due Fri 6 May 1

Critters. Critter #2 Attack.ROAR Attack.POUNCE Attack.SCRATCH. Critter #1

AP Computer Science Homework Set 5 2D Arrays

More on Classes. The job of this method is to return a String representation of the object. Here is the tostring method from the Time class:

AP Computer Science Lists The Array type

Binary Serialization Format

BOREDGAMES Language for Board Games

Lab Exercise 6: Abstract Classes and Interfaces CS 2334

CS 305j Midterm 1 Fall 2006

CS 170 Java Programming 1. Week 13: Classes, Testing, Debugging

Cisco Unified JTAPI Extensions

Chapter 6: Inheritance

P2: Advanced Java & Exam Preparation

Lab 1: Silver Dollar Game 1 CSCI 2101B Fall 2018

getcount getitem getitemid getview com.taxi Class MainActivity drawerlayout drawerleft drawerright...

Transcription:

CS1 Studio Project: Connect Four Due date: November 8, 2006 In this project, we will implementing a GUI version of the two-player game Connect Four. The goal of this project is to give you experience in several important areas: Writing a larger software system that involves several interacting classes. Passing objects around as parameters. Using 2-dimensional arrays. Developing classes from Javadocs. Connect Four is a simple game played by two players (we will call them "Red" and "Blue"). They take turns dropping pieces of their color into a grid-like playing board. Several web-based versions are available, click here to play one. This picture shows a game in progress in our GUI: Note that when a piece is played in a particular column, it drops as far down the column as possible, perhaps all the way to the bottom. If a column is full, a piece may not be played in that column. The winner is the first person to get four pieces of their color in a row, across, down or diagonally (thus the name of the game!). For the project, we provide you with the classes ConnectFour and ConnectFour$PlayBox that contains the main GUI and allows for two human players to play the game against each other. Download the jar file here and save it in your project directory. To unarchive the jar file, run this command to extract the supplied classes:

jar xvf project.jar Once the other required classes (listed below) have been created, in the same directory, you will be able to run the program by typing java ConnectFour (this will make a default 5x7 board). You can also make a game of any size by typing java ConnectFour [width] [height] where [width] and [height] are replaced by the size of the board you want to play. You will be writing three classes that perform all of the other work of the game. Namely: Piece.java will represent a single playing piece, with class constants for the two colors. GameBoard.java is the major class you will write. It stores the current state of the board, allows the GUI to drop pieces into it, and can tell the GUI when one player has won. Statistics.java keeps track of some simple statistics for reporting in the GUI. The GameBoard class will contain sufficient information to keep track of the board as the game is played. You should use a two-dimensional array to keep track of which pieces are at which location. Dropping pieces will result in checking the appropriate column in the array to see where the piece ends up. Then, to decide if one player has won, you will need to search through this array in all the possible directions (being careful not to go out of bounds!) and look for four in a row present and of the same color. Important information To submit your project, you will use the following command: try 231-grd project1 Piece.java GameBoard.java Statistics.java The project will be due on Wednesday, November 8, at 11:59 PM. Last modified: Mon Oct 2 13:42:12 EDT 2006 by zjb

Package Class Tree Deprecated Index Help Class Piece java.lang.object extended by Piece public class Piece extends java.lang.object Objects of this class represents a single piece in the game. Field Summary static int BLUE static int RED Class constant for representing a blue piece Class constant for representing a red piece Constructor Summary Piece(int c) Constructor Method Summary boolean isred() Returns true if and only if the piece is red. Methods inherited from class java.lang.object clone, equals, finalize, getclass, hashcode, notify, notifyall, tostring, wait, wait, wait Field Detail BLUE public static int BLUE

Class constant for representing a blue piece RED public static int RED Piece Class constant for representing a red piece Constructor Detail public Piece(int c) isred Constructor Parameters: c - a color (Piece.BLUE or Piece.RED) Method Detail public boolean isred() Returns true if and only if the piece is red. redness Package Class Tree Deprecated Index Help

Package Class Tree Deprecated Index Help Class GameBoard java.lang.object extended by GameBoard public class GameBoard extends java.lang.object This class holds the current state of the gameboard and performs a few useful functions for the GUI. Constructor Summary GameBoard(int w, int h) Constructs a game board of the given size and initializes its statistics. Method Summary int drop(piece p, int col) Drops the given piece on the board at the given location. Statistics getstats() Returns an object carrying the accumulated stats for the game. void reset() Clears the game board and increments the number of games played. boolean winner() Checks the board and reports if either player has won the game. Methods inherited from class java.lang.object clone, equals, finalize, getclass, hashcode, notify, notifyall, tostring, wait, wait, wait Constructor Detail GameBoard public GameBoard(int w,

drop int h) Constructs a game board of the given size and initializes its statistics. Parameters: w - Width of the board h - Height of the board Method Detail public int drop(piece p, int col) Drops the given piece on the board at the given location. The return value is defined as the distance the piece has fallen: 0 means it has stopped in the highest row, up to height-1 if it falls to the bottom. Attempting to drop a piece in a full column should result in a return value of -1. Parameters: p - Piece to be dropped col - Column (0 to width-1) in which the piece is dropped Distance dropped winner public boolean winner() Checks the board and reports if either player has won the game. Also must update its statistics to reflect the win. Do we have a winner? reset public void reset() Clears the game board and increments the number of games played. getstats

public Statistics getstats() Returns an object carrying the accumulated stats for the game. Note that this should include the current game in progress (if any). a Statistics object Package Class Tree Deprecated Index Help

Package Class Tree Deprecated Index Help Class Statistics java.lang.object extended by Statistics public class Statistics extends java.lang.object Holds the statistics for a ConnectFour game. There will only be one Statistics object used through the run of the program, since it is designed to keep track over multiple games played. Constructor Summary Statistics() Constructor Method Summary void gamewon(piece winner) Increments the win total for the given player. void newgame() Increments the number of games played. int numbluewins() Returns the number of games won by blue. int numgames() Returns the number of games played. int numredwins() Returns the number of games won by red. Methods inherited from class java.lang.object clone, equals, finalize, getclass, hashcode, notify, notifyall, tostring, wait, wait, wait Constructor Detail

Statistics public Statistics() newgame Constructor Method Detail public void newgame() Increments the number of games played. gamewon public void gamewon(piece winner) Increments the win total for the given player. Parameters: winner - A piece from the player that won numgames public int numgames() Returns the number of games played. number of games played numbluewins public int numbluewins() Returns the number of games won by blue. number of games won by blue

numredwins public int numredwins() Returns the number of games won by red. number of games won by red Package Class Tree Deprecated Index Help