代做Assignment 3: Painting a Winner, Part 2: The Controller调试Java编程

Assignment 3: Painting a Winner, Part 2: The Controller

Due dates:

.  Implementation: Tuesday 10/08 at 8:59pm

.  Self-evaluation: Wednesday 10/09 at 11:59pm

Starter files: code.zip

1  Purpose

The goal of this assignment is to practice writing a controller. While the model in a program represents the game state, the controller “runs” the program, effectively facilitating it through a sequence of operations.

This assignment mimics the style. of the previous assignment, in that you are provided an interface that you must implement and adequately test. The class you implement will act as the controller and work with the   model that you created in the previous assignment. This controller will “run” a game of Solo Red, asking for  input and outputting the game state. Since the game will still be text-based and the input/output will be

limited to the console and keyboard, the notion of a “view” will be minimal in this assignment.

There will be two submissions for this assignment:

.  Your actual implementation of the controller and full test suite

· A self-evaluation, due one day plus three hours later than the actual implementation, where we will ask you to rezecton your implementation and testing choices.

The same late-day policy as on the previous homework applies: each of these three submissions

independently may use up to one late day, and you are still able to submit your self-evaluation on time even if you submit your implementation late.

You are expected to use your code from the previous assignment as the starting point for this assignment. However, please ensure all of your new code is in the cs3500 ● solo red ● controller package.

Additionally, your code from the previous assignment should remain in the cs3500 · solo red model hw02 and cs3500 .solo red .view .hw02 packages.

2  Preliminaries: Fixing the model

In HW2, the method getCanvas was documented as throwing an exception when the game is over. In the controller, this is ahindrance. You must edit the interface to remove that exception and then remove the  relevant code from the implementation. Otherwise the client can never see theynal state of the game.

3  Preliminaries: Improving your view

In the previous assignment, you implemented a SoloRedGameTextView class, such that its toString

method provided the desired output. This was not ideal design, but it was convenient at the time. For this assignment, you will reyne that view to be slightly more zexible. Enhance your class such that it now

implements the following interface, which should replace the one given in the previous assignment:

public interface RedGameView {

/**

* Renders a model in some manner (e .g . as text , or as graphics , etc .) .

* @throws IOException if the rendering fails for some reason

*/


void render() throws IOException;

}

This view interface is tiny, but it abstracts away the idea that views are intrinsically String-based.

You should then add a second constructor to your SoloRedGameTextView class, that takes in both a model

and an Appendable (see below), and implement render such that it appends the current textual output to that Appendable. You should preserve your toString method, since it is useful, but you should also

implement this render method — it should be very short!

4  The Controller interface

The interface for the Solo Red controller must support the following functionality (as an interface RedGameController that you should place in the cs3500 .solored .controller package):

1 ¯ A method void playGame(RedGameModel model , List deck , boolean shuffle , int numPalettes , int handSize). This method should play a new game of Solo Red

using the provided model, using the startGame method on the model. It should throw an

IllegalArgumentException if the provided model is null. It should throw an

IllegalStateException only if the controller is unable to successfully receive input or transmit

output. The nature of input/output will bean implementation detail (see below). It should also throw an IllegalArgumentException if the game cannot be started.

Before you implement your controller (see The Controller implementation below), you should yrst work through examples for it.

A suggestion about workload management: You should spend a reasonable amount of effort trying to test your controller. If you ynd yourself getting stuck, switchgears and start working on the implementation, and maybe new testing ideas will occur to you as you work through that implementation. For your own    learning, keep notes of which ideas occurred to you before implementing anything, vs which ideas only    occurred as a result of trying to implement the controller: is there a pattern of “things you only noticed   later” that you might try to deliberately look for sooner, on future projects?

5  The Controller implementation

Design a class SoloRedTextController that implements the RedGameController interface above (also in the cs3500 .solored .controller package). You will need to:

1. Think about which additional fields and types it needs to implement the promised functionality.

2. Design a constructor SoloRedTextController(Readable rd, Appendable ap) throws IllegalArgumentException. Recall from Lecture 8: Controllers and Mock Objects that Readable and Appendable are two existing interfaces in Java that abstract input and output respectively. The constructor should throw the IllegalArgumentException if and only if either of its arguments are null. Your controller should accept and store these objects for doing input and output. Any input coming from the user will be received via the Readable object, and any output sent to the user should be written to the Appendable object by way of a RedGameView. Hint: Look at the Readable and Appendable interfaces to see how to read from and write to them. Ultimately you must figure out a way to transmit a String to an Appendable and read suitable data from a Readable object. The Scanner class will likely be useful, as will the lecture notes on controllers.

3. playGame method should play a game. It should “run” the game in the following sequence until the game is over. Note: Each transmission described below should end with a newline.

a. Transmit game state to the Appendable object exactly as the view of the model provides it.

b. Transmit "Number of cards in deck: N", replacing N with the actual number of cards left in the deck.

c. If the game is ongoing (i.e. there is more user input and the user hasn’t quit yet), obtain the next user input from the Readable object. Do not prompt them with a message. A user input consists of a “move” specified by a move command followed by a sequence of values (separated by any type of whitespace): palette followed by two natural numbers.

The first number is the index of the palette you want to paint to; and the second number is the index of the card in the hand you want to play. For example, an input of palette 1 3 should cause the controller to call the playToPalette method on your model with appropriate inputs to try and play the third card to the first palette. If the game is not over, the controller should draw until the hand is full or the deck is empty (see note below). canvas followed by one natural number. The number represents the index of the card

in the hand you want to play. For example, canvas 2 should cause your controller to call the playToCanvas method on your model to play the second card from the hand.

d. If the game is over, the method should do the following transmit the message "Game lost." if the player lost or the message "Game won." if the player won. transmit the final game state one last time transmit the message "Number of cards in deck: N" as before The method should then end.

Key points:

.  User input numbering: To make the inputs more user-friendly, all indices in the user provided input begin from 1. This will affect the inputs that your controller passes along to your model.

.  Quitting: If at any point, the next value is either the letter  'q ' or the letter  'Q ', the controller should transmit the following in order: the message "Game quit!", the message "State of game when

quit:", the current game state, and the message "Number of cards in deck : N" with N replaced by the remaining number of cards left in the deck. The method should then end. For example:

Game quit !

State of game when quit:

Canvas: R

P1: R1

> P2: O2 R7

P3: V2

Hand: V1 I2 O6 R3

Number of cards in deck: 4

.  Bad inputs: If any individual value is unexpected (i.e. something other than  'q ',  'Q ' or a number) it

should wait for the user tore-enter that value again. For example, if the user is trying to play to a

palette , and has entered the palette index correctly, but entered the card index incorrectly, th

controller should continue attempting to read a value for the card index before continuing. For another example, if the user is trying to play to a palette and has entered the palette index incorrectly, the

controller should continue attempting to read a value for the palette index before moving on to reading for the card index. The controller should behave similarly for the other commands. Once all the numbers are successfully read, if the model indicates the move is invalid, the controller should transmit a message to the Appendable object saying "Invalid move . Try again . X" where X is any

informative message about why the move was invalid (all on one line), and resume waiting for valid

input. Hint: You should probably design a helper method to retry reading inputs until you get a number   or a  'q '/ 'Q '. Using that helper consistently will make it much easier to implement the desired retrying

behavior. described here. That helper probably should not be responsible for determining if a number is avalid coordinate — that’sthe model’s job — but that helper does need to return either the user’s

number or their desired to quit the game. Think carefully about the signature of this method before you start implementing it...

If an input is not a valid command for the game (i.e. something other than  'q ',  'Q ',  'palette ', or

'canvas '), the controller should transmit a message to the Appendable object saying "Invalid

command . Try again . X" where X is some helpful message (all in one line). Then the controller should try reading the next value for a command.

.  Error handling: The playGame method should throw an IllegalArgumentException if a null model is passed to it. If the Appendable object is unable to transmit output or the Readable object is unable to   provide inputs (for whatever reason), the playGame method should throw an IllegalStateException  to its caller. The playGame method must not throw any other exceptions, nor should it propagate any exceptions thrown by the model.

.  Write sufycient tests to beconydent that your code is correct. Note: once the model has been tested thoroughly (which you hopefully did in the previous assignment), all that remains to be tested is

whether the controller works correctly in all cases. Lecture 8:Controllers and Mock Objects will prove to be helpful.

Be sure to properly document your code with Javadoc as appropriate. Method implementations that inherit Javadoc need not provide their own unless their contract differs from the inherited documentation. Finally, no method in your implementation should exceed 50 lines. This hampers clarity of your code.

If you had to change your implementation from the previous assignment, please document your changes in a README yle (aplaintext yle) that explains what you changed and why. This doesn’t have to belong;  a simple bullet-point list will sufyce. But having this documentation will make your TAs’ grading job a

lot easier!

6  Testing

You will need to add additional tests to assess whether your controller works regardless of whether your

model works. (Again, if you’ve sufyciently tested your model in the previous assignment, then you can rely   on your model working here.) You will likely need to use the techniques in Lecture 8:Controllers and Mock Objects.

You should create your primary test class in the cs3500 .solored package. This testis outside your

controller package, and so can only test the public-facing behaviors of your controller. If you want to test internal implementation details as well, you should create one more test class in the

cs3500 .solored .controller package, so that you can check protected and package-private implementation details if needed.

Be mindful of which testcases you place in which test class! Technically, you could run all the tests from a single class. But using multiple classes like this helps convey to the reader of your code some of your

thought processes behind each test: the reader should understand the examplesyrst, then look at the tests of public behavior, and ynally look at implementation-speciycyddly details.

Note: When you submit your full implementation, you will see automated tests that I wrote and run against your code. I gave some of my test methods mnemonic names, so that you can try to deduce what my tests are checking for. Just because I have a test for a given scenario, though, does not mean that you shouldn’t write your own test case to conyrm your understanding!

7  What to submit

.  For your implementation: submit aproperly-structured zip containing at minimum o   The model interface (RedGameModel.java)

o   Your implementation of the model (SoloRedGameModel.java) o   The view interface (RedGameView.java)

o   Your implementation of the view (SoloRedGameTextView.java) o   The controller interface (RedGameController.java)

o   Your implementation of the controller (SoloRedTextController.java) o   Any additional classes necessary to compile your code

o   All your tests for all your implementations in one or more JUnit test classes. You should include at least all your tests from the previous assignment, and add to them...

o   A brief README yle (aplaintext yle) explaining what changes from the previous assignment you made, and why.

As with the previous assignment, please submit a zip containing only the s rc/ and test/ directories with no surrounding directories, so that the autograder recognizes your package structure. Please do not

include your output/, out, or .idea/ directories — they’re not useful and we will deduct points if you do!

8  Grading standards

For this assignment, you will be graded on

.  Whether your interfaces specify all necessary operations with appropriate method signatures, .  Whether your code implements the speciycations (functional correctness),

.  the clarity of your code, including length of your methods as established in this assignment and documentation

.  How well your code follows the design principles discussed so far and the relevant principles in the Design Principles Masterlist,

.  The comprehensiveness of your test coverage, and

· How well you follow the style. guide.





热门主题

课程名

mktg2509 csci 2600 38170 lng302 csse3010 phas3226 77938 arch1162 engn4536/engn6536 acx5903 comp151101 phl245 cse12 comp9312 stat3016/6016 phas0038 comp2140 6qqmb312 xjco3011 rest0005 ematm0051 5qqmn219 lubs5062m eee8155 cege0100 eap033 artd1109 mat246 etc3430 ecmm462 mis102 inft6800 ddes9903 comp6521 comp9517 comp3331/9331 comp4337 comp6008 comp9414 bu.231.790.81 man00150m csb352h math1041 eengm4100 isys1002 08 6057cem mktg3504 mthm036 mtrx1701 mth3241 eeee3086 cmp-7038b cmp-7000a ints4010 econ2151 infs5710 fins5516 fin3309 fins5510 gsoe9340 math2007 math2036 soee5010 mark3088 infs3605 elec9714 comp2271 ma214 comp2211 infs3604 600426 sit254 acct3091 bbt405 msin0116 com107/com113 mark5826 sit120 comp9021 eco2101 eeen40700 cs253 ece3114 ecmm447 chns3000 math377 itd102 comp9444 comp(2041|9044) econ0060 econ7230 mgt001371 ecs-323 cs6250 mgdi60012 mdia2012 comm221001 comm5000 ma1008 engl642 econ241 com333 math367 mis201 nbs-7041x meek16104 econ2003 comm1190 mbas902 comp-1027 dpst1091 comp7315 eppd1033 m06 ee3025 msci231 bb113/bbs1063 fc709 comp3425 comp9417 econ42915 cb9101 math1102e chme0017 fc307 mkt60104 5522usst litr1-uc6201.200 ee1102 cosc2803 math39512 omp9727 int2067/int5051 bsb151 mgt253 fc021 babs2202 mis2002s phya21 18-213 cege0012 mdia1002 math38032 mech5125 07 cisc102 mgx3110 cs240 11175 fin3020s eco3420 ictten622 comp9727 cpt111 de114102d mgm320h5s bafi1019 math21112 efim20036 mn-3503 fins5568 110.807 bcpm000028 info6030 bma0092 bcpm0054 math20212 ce335 cs365 cenv6141 ftec5580 math2010 ec3450 comm1170 ecmt1010 csci-ua.0480-003 econ12-200 ib3960 ectb60h3f cs247—assignment tk3163 ics3u ib3j80 comp20008 comp9334 eppd1063 acct2343 cct109 isys1055/3412 math350-real math2014 eec180 stat141b econ2101 msinm014/msing014/msing014b fit2004 comp643 bu1002 cm2030
联系我们
EMail: 99515681@qq.com
QQ: 99515681
留学生作业帮-留学生的知心伴侣!
工作时间:08:00-21:00
python代写
微信客服:codinghelp
站长地图