From 8e60917fffa80cd202d2bc489ae7405c694b5aca Mon Sep 17 00:00:00 2001 From: jnnsrctr <99033602+jnnsrctr@users.noreply.github.com> Date: Tue, 9 Aug 2022 09:25:20 +0200 Subject: [PATCH] hotfile-v1.3 --- Archer.class | Bin 1702 -> 1672 bytes Archer.ctxt | 10 +- Archer.java | 69 +++++++----- Arrow.class | Bin 1930 -> 1930 bytes Arrow.ctxt | 4 +- Arrow.java | 33 +++--- CanvasBG.class | Bin 4624 -> 4789 bytes CanvasBG.ctxt | 58 +++++++---- CanvasBG.java | 277 +++++++++++++++++++++++++++++++------------------ Game.class | Bin 1573 -> 1573 bytes Game.ctxt | 2 +- Game.java | 4 +- Points.class | Bin 1394 -> 1394 bytes Points.ctxt | 6 +- Points.java | 31 ++++-- Terminal.class | Bin 5362 -> 5396 bytes Terminal.ctxt | 33 +++--- Terminal.java | 223 ++++++++++++++++++++++++++------------- package.bluej | 48 ++++----- 19 files changed, 503 insertions(+), 295 deletions(-) diff --git a/Archer.class b/Archer.class index f36f61330d9ce04605514a443d3b84815a3a20c9..c27cbc66b2b96f383015d6c1a60649a58753385b 100644 GIT binary patch delta 210 zcmZ3++rhiRkCBZvwJ5PTb#oNsWJbou$?uqCB^4N07!(;e8I%~L7?go56$Uj1RR(Pa zwaqHbYK)4y4BQNQ48jZs4C)L<3|(Ba86lWh^3-XECqRS7P7*ia9WdFgP;EF*pNBSB69eH-;7l4~8WSo(#u<=E(w8 x@IdvhX0_uD0y-y@fsY}AL5Lx8@;6p5-bA2C3Q!~+D3USRm(7MTe{vU_3;@ajCH?>a delta 214 zcmeC+UB^cXHM=ub{%k>^xn zU}IopU|_g2xtB$Kas%@bU1Ol3CJb^6W(-CQ77U>bRt%*K)(kTkY#DYi*fHE@uxF43 zs^@{}VzuLS0XoE;fe&bh5QFz*eKyg_Z&^)w1AwBzK+!OuXgE;RhB0n(4x0=B-SZ}d diff --git a/Archer.ctxt b/Archer.ctxt index 7371f26..bb353e9 100644 --- a/Archer.ctxt +++ b/Archer.ctxt @@ -1,17 +1,21 @@ #BlueJ class context comment0.target=Archer -comment0.text=\r\n\ Beschreiben\ Sie\ hier\ die\ Klasse\ Archer.\r\n\ \r\n\ @author\ (Ihr\ Name)\ \r\n\ @version\ v1.2\ (02.06.2022\ 15\:35)\r\n +comment0.text=\r\n\ Class\ Archer\ creates\ and\ draws\ the\ archers\ on\ the\ Canvas.\r\n\ This\ class\ is\ able\ to\ move\ the\ archers\ from\ right\ to\ left\ /\ left\ to\ right.\r\n\r\n\ \r\n\ @author\ \ Johannes\ Richter\r\n\ \ \ \ \ \ \ \ \ \ Simon\ Cirdei\r\n\ \ \ \ \ \ \ \ \ \ Christoph\ Schramm\r\n\ \ \ \ \ \ \ \ \ \ \r\n\ @version\ v1.3\ (02.06.2022\ 16\:45)\r\n comment1.params=inputplayer\ archercolor\ usedcanvas comment1.target=Archer(int,\ java.awt.Color,\ Canvas) +comment1.text=\r\n\ Constructor\ for\ instances\ of\ Archer\r\n\r\n\ @param\ inputplayer\ \ \ \ current\ player\r\n\ @param\ archercolor\ \ \ color\ of\ the\ archer\r\n\ @param\ usedcanvas\ \ canvas\ where\ to\ plot\ the\ arrow\r\n comment2.params= comment2.target=void\ draw() -comment2.text=\r\n\ Es\ wird\ ein\ Archer\ an\ der\ von\ CanvasBG\ vorgegebenen\ Stelle\ und\ Farbe\r\n\ gezeichnet\r\n\ \r\n +comment2.text=\r\n\ The\ archer\ will\ be\ painted\ at\ the\ pre-set-position\ on\ the\ Canvas\r\n comment3.params= -comment3.target=void\ eraseArcher() +comment3.target=void\ erase() +comment3.text=\r\n\ The\ archer\ will\ be\ erased\r\n comment4.params= comment4.target=void\ stepRight() +comment4.text=\r\n\ The\ archer\ moves\ to\ the\ right\r\n comment5.params= comment5.target=void\ stepLeft() +comment5.text=\r\n\ The\ archer\ moves\ to\ the\ right\r\n comment6.params= comment6.target=int\ giveXposition() comment6.text=\r\n\ Supply\ other\ classes\ with\ the\ current\ X\ position\ of\ the\ Archer\r\n diff --git a/Archer.java b/Archer.java index dd560ce..65bd06d 100644 --- a/Archer.java +++ b/Archer.java @@ -3,33 +3,43 @@ import java.lang.*; /** - * Beschreiben Sie hier die Klasse Archer. + * Class Archer creates and draws the archers on the Canvas. + * This class is able to move the archers from right to left / left to right. + * * - * @author (Ihr Name) - * @version v1.2 (02.06.2022 15:35) + * @author Johannes Richter + * Simon Cirdei + * Christoph Schramm + * + * @version v1.3 (02.06.2022 16:45) */ public class Archer extends Game { - private Color color; // color of the arrow - private Canvas screenbg; // canvas where to plot the arrow - private int xPosition, yPosition; //position at the start + private Color color; // color of the archer + private Canvas screenbg; // canvas where to plot the archer + private int xPosition, yPosition; //_position at the start private int playerno; // number of the player + + /** + * Constructor for instances of Archer + * + * @param inputplayer current player + * @param archercolor color of the archer + * @param usedcanvas canvas where to plot the arrow + */ public Archer(int inputplayer, Color archercolor, Canvas usedcanvas) { - playerno = inputplayer; - xPosition = super.archerXpos + (playerno-1)*33; - yPosition = super.archerYpos; + playerno = inputplayer; + xPosition = super.archerXpos + (playerno-1)*33; //x-position Archer: access from super-class + yPosition = super.archerYpos; //y-position Archer: access from super-class color = archercolor; screenbg = usedcanvas; } /** - * Es wird ein Archer an der von CanvasBG vorgegebenen Stelle und Farbe - * gezeichnet - * + * The archer will be painted at the pre-set-position on the Canvas */ - public void draw() { screenbg.setForegroundColor(color); @@ -39,33 +49,37 @@ public void draw() // the body top to bottom screenbg.drawLine(xPosition+15,yPosition+13,xPosition+15,yPosition+53); // the arms - screenbg.drawLine(xPosition, yPosition+8,xPosition+15, yPosition+23); //left arm - screenbg.drawLine(xPosition+15,yPosition+23,xPosition+30,yPosition+8); //right arm + screenbg.drawLine(xPosition, yPosition+8,xPosition+15, yPosition+23); //left arm + screenbg.drawLine(xPosition+15,yPosition+23,xPosition+30,yPosition+8); //right arm // the legs - screenbg.drawLine(xPosition,yPosition+68,xPosition+15,yPosition+53); //left leg + screenbg.drawLine(xPosition,yPosition+68,xPosition+15,yPosition+53); //left leg screenbg.drawLine(xPosition+15,yPosition+53,xPosition+30,yPosition+68); //right leg } - public void eraseArcher() + /** + * The archer will be erased + */ + public void erase() { screenbg.eraseCircle(xPosition+8,yPosition,14); - screenbg.setForegroundColor(super.bgColor); //da keine Methode, um die Linien zu entfernen existiert, weiß machen - // the head - screenbg.fillCircle(xPosition+8,yPosition,14); + screenbg.setForegroundColor(super.bgColor); //no erase-function: redraw with canvas-backgorund-color // the body top to bottom screenbg.drawLine(xPosition+15,yPosition+13,xPosition+15,yPosition+53); // the arms - screenbg.drawLine(xPosition, yPosition+8,xPosition+15, yPosition+23); //left arm - screenbg.drawLine(xPosition+15,yPosition+23,xPosition+30,yPosition+8); //right arm + screenbg.drawLine(xPosition, yPosition+8,xPosition+15, yPosition+23); //left arm + screenbg.drawLine(xPosition+15,yPosition+23,xPosition+30,yPosition+8); //right arm // the legs - screenbg.drawLine(xPosition,yPosition+68,xPosition+15,yPosition+53); //left leg + screenbg.drawLine(xPosition,yPosition+68,xPosition+15,yPosition+53); //left leg screenbg.drawLine(xPosition+15,yPosition+53,xPosition+30,yPosition+68); //right leg } + /** + * The archer moves to the right + */ public void stepRight() { // Erase at current position - eraseArcher(); + erase(); // Calculate new position and decide which direction to walk xPosition += 1; @@ -74,10 +88,13 @@ public void stepRight() draw(); } + /** + * The archer moves to the right + */ public void stepLeft() { // Erase at current position - eraseArcher(); + erase(); // Calculate new position and decide which direction to walk xPosition -= 1; @@ -93,4 +110,4 @@ public int giveXposition() { return xPosition; } -} \ No newline at end of file +} diff --git a/Arrow.class b/Arrow.class index 6a34046366fdfb72b5ab4ab228006312a8313e46..cf08137ed7a08f4ec2b0e111418160a2ee47a172 100644 GIT binary patch delta 208 zcmeC;@8aK3#Nytvl|fibXDfqC4&9=4Q)Knnz!_DmLLn_}w>G}MhjnZcbQl);-Jk-?84m%*Q*j3I!bjvgVGm{BS!iWT7{Xk$+k~JR{_QkY_!Zf`jtmIX9m7 zVmuDX;sx3CqL9OG9Pv`-s4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.2022\ 15\:35)\r\n +comment0.text=\r\n\ The\ class\ CanvasBG\ is\ one\ of\ the\ most\ important\ classes\ for\ the\ game\ 2Darts.\r\n\ The\ class\ is\ able\ to\ draw\:\ \r\n\ \ \ \ \ \ \ \ \ \ -\ the\ target\ of\ the\ dartboard\ \r\n\ \ \ \ \ \ \ \ \ \ -\ the\ two\ archers\r\n\ \ \ \ \ \ \ \ \ \ -\ the\ score\ of\ both\ players\r\n\ \ \ \ \ \ \ \ \ \ \r\n\ CanvasBG\ also\ moves\ the\ arrow\ trough\ the\ dashboard.\ Loops\ calculates\ the\ positions\ and\ points.\r\n\ The\ change\ of\ the\ players\ is\ also\ implemented\ here.\ \r\n\ \r\n\ @author\ \ \ \ \ \ Johannes\ Richter\r\n\ \ \ \ \ \ \ \ \ \ \ \ \ \ Simon\ Cirdei\r\n\ \ \ \ \ \ \ \ \ \ \ \ \ \ Christoph\ Schramm\r\n\ \ \ \ \ \ \ \ \ \ \ \ \ \ \r\n\ @version\ \ \ \ \ v1.3\ (02.06.2022\ 16\:45)\r\n comment1.params=inputa\ starttarget comment1.target=CanvasBG(short,\ int) +comment1.text=\r\n\ Constructor\ for\ instances\ of\ the\ CanvasBG\ (dashboard)\r\n\r\n\ @param\ inputa\ \ \ \ \ \ \ \ input\ from\ user\ for\ target\ size\r\n\ @param\ startarget\ \ \ \ input\ from\ user\ for\ beginning\ of\ target\r\n +comment10.params= +comment10.target=void\ printArcher() +comment10.text=\r\n\ Draw\ the\ two\ Archers\r\n +comment11.params=currentplno +comment11.target=void\ swapArcher(int) +comment11.text=\r\n\ The\ method\ is\ able\ to\ switch\ the\ players.\ \r\n\ First\ the\ position\ of\ the\ archers\ will\ be\ moved.\r\n\ Methods\ from\ Archer\ are\ used.\r\n +comment12.params= +comment12.target=void\ clearField() +comment12.text=\r\n\ Method\ is\ able\ to\ clear\ the\ arrow\ from\ the\ field\r\n +comment13.params=inputscore1\ inputscore2 +comment13.target=void\ printScore(int,\ int) +comment13.text=\r\n\ Draw\ the\ two\ Scores\r\n +comment14.params=state +comment14.target=void\ visible(boolean) +comment14.text=\r\n\ Show\ the\ canvas\r\n comment2.params= comment2.target=int\ shootArrow() -comment2.text=\r\n\ Shoot\ an\ arrow\r\n -comment3.params= -comment3.target=void\ printBG() -comment3.text=\r\n\ Draw\ the\ background\r\n -comment4.params= -comment4.target=void\ printArcher() -comment4.text=\r\n\ Draw\ the\ two\ Archers\r\n -comment5.params=currentplno -comment5.target=void\ swapArcher(int) +comment2.text=\r\n\ The\ method\ is\ able\ to\ shoot\ an\ arrow\ on\ the\ dashboard\ with\ correct\ color\r\n +comment3.params=thisArrow +comment3.target=void\ fly(Arrow) +comment3.text=\r\n\ The\ method\ is\ able\ to\ let\ the\ arrow\ fly.\r\n\ A\ loop\ checks\ the\ position\ at\ all\ times.\ \r\n\ Within\ certain\ limits\ the\ loop\ finishes.\r\n +comment4.params=thisArrow +comment4.target=void\ eval(Arrow) +comment4.text=\r\n\ The\ method\ returns\ the\ final\ position\ of\ the\ arrow.\r\n\ If\ the\ position\ is\ in\ the\ defined\ area\ of\ the\ bullseye,\ \r\n\ the\ position\ blinks\ and\ the\ points\ will\ be\ set.\r\n\ \r\n\ Same\ function\ for\ the\ different\ areas.\r\n +comment5.params= +comment5.target=void\ printWall() +comment5.text=\r\n\ The\ method\ draw\ the\ background\ of\ the\ dartboard\ with\ brown.\r\n comment6.params= -comment6.target=void\ clearField() -comment6.text=\r\n\ Clear\ all\ arrows\r\n -comment7.params=inputscore1\ inputscore2 -comment7.target=void\ printScore(int,\ int) -comment7.text=\r\n\ Draw\ the\ two\ Scores\r\n -comment8.params=state -comment8.target=void\ visible(boolean) -comment8.text=\r\n\ Show\ the\ canvas\r\n -numComments=9 +comment6.target=void\ printTarget() +comment6.text=\r\n\ Draw\ the\ target\r\n +comment7.params= +comment7.target=void\ printBlack() +comment7.text=\r\n\ Draw\ black\r\n +comment8.params= +comment8.target=void\ printGreen() +comment8.text=\r\n\ Draw\ green\r\n +comment9.params= +comment9.target=void\ printRed() +comment9.text=\r\n\ Draw\ red\r\n +numComments=15 diff --git a/CanvasBG.java b/CanvasBG.java index 6ad3bf1..f1cc936 100644 --- a/CanvasBG.java +++ b/CanvasBG.java @@ -2,191 +2,259 @@ import java.awt.geom.*; /** - * Startet Canvas - * {@code Canvas} + * The class CanvasBG is one of the most important classes for the game 2Darts. + * The class is able to draw: + * - the target of the dartboard + * - the two archers + * - the score of both players + * + * CanvasBG also moves the arrow trough the dashboard. Loops calculates the positions and points. + * The change of the players is also implemented here. * - * @author CS, SVC, JR - * @version v1.2 (02.06.2022 15:35) + * @author Johannes Richter + * Simon Cirdei + * Christoph Schramm + * + * @version v1.3 (02.06.2022 16:45) */ public class CanvasBG extends Game { - private Canvas screenbg; - private int targettop; - private int evalscore; //score from the evaluation - private int curplay; // private variant of currentplayer, the Terminal tells which archer switches - private int score1, score2; - private Color arrowcolor; - private short a; - public Archer Archer1, Archer2; //new archers - public Points Score1, Score2; //new scores - private Arrow thisArrow; + private Canvas screenbg; //define a new Canvas + private int targettop; //top of the target (dartboard) + private int evalscore; //score from the evaluation + private int curplay; //private variant of currentplayer, the Terminal tells which archer switches + private int score1, score2; //two scores for two players + private Color arrowcolor; //color of the arrow + private short a; //data-input of the height of bullseye + public Archer Archer1, Archer2; //new archers + public Points Points1, Points2; //new scoretables + private Arrow thisArrow; //new arrow + /** + * Constructor for instances of the CanvasBG (dashboard) + * + * @param inputa input from user for target size + * @param startarget input from user for beginning of target + */ public CanvasBG(short inputa,int starttarget) { - targettop = starttarget; - a = inputa; - curplay = 1; //init local player no + a = inputa; + targettop = starttarget; + curplay = 1; //init local player number one score1 = super.scorePlayer1; score2 = super.scorePlayer2; screenbg = new Canvas("2Darts", super.canvasWidth, super.canvasHeight, super.bgColor); - printBG(); + printWall(); + printTarget(); } - /** - * Shoot an arrow + /** + * The method is able to shoot an arrow on the dashboard with correct color */ public int shootArrow() { screenbg.setVisible(true); + //set color of the arrow for player one if(curplay == 1) { arrowcolor = super.colorPlayer1; } + //set color of the arrow for player two else if(curplay == 2) { arrowcolor = super.colorPlayer2; - } // Create and show the arrow + } + + // Create and show the arrow Arrow thisArrow = new Arrow(arrowcolor, screenbg); thisArrow.draw(); - // Move the arrow + // Let the arrow fly + fly(thisArrow); + + // Result evaluation + eval(thisArrow); + + //get the score for other classes/methods + return evalscore; + } + + /** + * The method is able to let the arrow fly. + * A loop checks the position at all times. + * Within certain limits the loop finishes. + */ + public void fly(Arrow thisArrow) + { boolean done = false; - boolean wallhit; while(!done) { screenbg.wait(20); // kurze Pause thisArrow.move(); // Stop if the arrow hits the ground if(thisArrow.giveYposition() >= (super.canvasHeight - super.arrowHeight)) { done = true; - wallhit = false; } // Stop if the arrow hits the target else if(thisArrow.giveXposition() <= super.wallThickness && thisArrow.giveYposition() >= super.wallStart) { done = true; - wallhit = true; } // Stop if the arrow missed the target else if(thisArrow.giveXposition() <= 0) { - done = true; - wallhit = false; + done = true; } // Stop if the arrow is in the clouds else if(thisArrow.giveYposition() <= 0) { - done = true; - wallhit = false; + done = true; } } - - //Result evaluation. - + } + + /** + * The method returns the final position of the arrow. + * If the position is in the defined area of the bullseye, + * the position blinks and the points will be set. + * + * Same function for the different areas. + */ + public void eval(Arrow thisArrow) + { + // first statement is false boolean evaluated = false; - int blink = 0; + int blink = 0; //init of first blink + + // checking of the boolean while(!evaluated) { + // will set the score to 50, if arrow hits the area of bullseye if(thisArrow.giveYposition() >= targettop + 4 * a && thisArrow.giveYposition() <= targettop + 5 * a) { evalscore = 50; evaluated = true; + + // area which has been hitted would blink for 3 times while(blink < 3) { - screenbg.setForegroundColor(Color.yellow); - Rectangle bullseye = new Rectangle(0, targettop+4*a, super.wallThickness, a); //x, y, width, height - screenbg.fill(bullseye); // draw the bullseye - screenbg.wait(200); - screenbg.setForegroundColor(Color.red); - screenbg.fill(bullseye); // draw the bullseye - screenbg.wait(200); - blink++; + screenbg.setForegroundColor(Color.yellow); + Rectangle bullseye = new Rectangle(0, targettop+4*a, super.wallThickness, a); + screenbg.fill(bullseye); + screenbg.wait(200); // delay for 200ms + printRed(); + screenbg.wait(200); // delay for 200ms + blink++; } } + // will set the score to 25, if arrow hits the green area else if(thisArrow.giveYposition() >= targettop + 3 * a && thisArrow.giveYposition() <= targettop + 6 * a) { evalscore = 25; evaluated = true; while(blink < 3) { - screenbg.setForegroundColor(Color.yellow); - Rectangle greenbox = new Rectangle(0, targettop+3*a, super.wallThickness, 3*a); - screenbg.fill(greenbox); - screenbg.setForegroundColor(Color.red); // draw the green areas - Rectangle bullseye = new Rectangle(0, targettop+4*a, super.wallThickness, a); //x, y, width, height - screenbg.fill(bullseye); // draw the bullseye - - screenbg.wait(200); - - screenbg.setForegroundColor(Color.green); - screenbg.fill(greenbox); - screenbg.setForegroundColor(Color.red); - screenbg.fill(bullseye); - - screenbg.wait(200); - blink++; + screenbg.setForegroundColor(Color.yellow); + Rectangle greenbox = new Rectangle(0, targettop+3*a, super.wallThickness, 3*a); + screenbg.fill(greenbox); + printRed(); + screenbg.wait(200); // delay for 200ms + printGreen(); + printRed(); + screenbg.wait(200); // delay for 200ms + blink++; } } + // will set the score to 10, if arrow hits the black area else if(thisArrow.giveYposition() >= targettop && thisArrow.giveYposition() <= targettop + 9 * a) { evalscore = 10; evaluated = true; while(blink < 3) { - screenbg.setForegroundColor(Color.yellow); - Rectangle blackbox = new Rectangle(0, targettop, super.wallThickness, 9*a); //x, y, width, height - screenbg.fill(blackbox); // draw the black areas - screenbg.setForegroundColor(Color.green); - Rectangle greenbox = new Rectangle(0, targettop+3*a, super.wallThickness, 3*a); - screenbg.fill(greenbox); - screenbg.setForegroundColor(Color.red); // draw the green areas - Rectangle bullseye = new Rectangle(0, targettop+4*a, super.wallThickness, a); //x, y, width, height - screenbg.fill(bullseye); // draw the bullseye - screenbg.wait(200); - screenbg.setForegroundColor(Color.black); - screenbg.fill(blackbox); - screenbg.setForegroundColor(Color.green); - screenbg.fill(greenbox); - screenbg.setForegroundColor(Color.red); - screenbg.fill(bullseye); - screenbg.wait(200); - blink++; + screenbg.setForegroundColor(Color.yellow); + Rectangle blackbox = new Rectangle(0, targettop, super.wallThickness, 9*a); + screenbg.fill(blackbox); + printGreen(); + printRed(); + screenbg.wait(200); // delay for 200ms + printTarget(); + screenbg.wait(200); // delay for 200ms + blink++; } } + // zero points, if previous requirements not true else { evalscore = 0; evaluated = true; } - } - return evalscore; + } } - /** - * Draw the background + /** + * The method draw the background of the dartboard with brown. */ - public void printBG() + public void printWall() { screenbg.setVisible(true); Color brown = new Color(191, 128, 64); // Color brown screenbg.setForegroundColor(brown); - Rectangle brownbox = new Rectangle(0, super.wallStart, super.wallThickness, super.canvasHeight - super.wallStart); //x, y, width, height - screenbg.fill(brownbox); //draw the brown wall + //usage of super variables from superclass + Rectangle brownbox = new Rectangle(0, super.wallStart, super.wallThickness, super.canvasHeight - super.wallStart); + screenbg.fill(brownbox); + } + + /** + * Draw the target + */ + public void printTarget() + { + printBlack(); // draw black area + printGreen(); // draw green area + printRed(); // draw red area + } + + /** + * Draw black + */ + public void printBlack() + { screenbg.setForegroundColor(Color.black); Rectangle blackbox = new Rectangle(0, targettop, super.wallThickness, 9*a); - screenbg.fill(blackbox); // draw the black areas + screenbg.fill(blackbox); + } + + /** + * Draw green + */ + public void printGreen() + { screenbg.setForegroundColor(Color.green); Rectangle greenbox = new Rectangle(0, targettop+3*a, super.wallThickness, 3*a); - screenbg.fill(greenbox); // draw the green areas + screenbg.fill(greenbox); + } + + /** + * Draw red + */ + public void printRed() + { screenbg.setForegroundColor(Color.red); Rectangle bullseye = new Rectangle(0, targettop+4*a, super.wallThickness, a); - screenbg.fill(bullseye); // draw the bullseye + screenbg.fill(bullseye); } - /** + /** * Draw the two Archers */ public void printArcher() { screenbg.setVisible(true); - Archer Archer1 = new Archer(1, super.colorPlayer1, screenbg); + Archer Archer1 = new Archer(1, super.colorPlayer1, screenbg); // init the first archer Archer1.draw(); - Archer Archer2 = new Archer(2, super.colorPlayer2, screenbg); + Archer Archer2 = new Archer(2, super.colorPlayer2, screenbg); // init the second archer Archer2.draw(); } + /** + * The method is able to switch the players. + * First the position of the archers will be moved. + * Methods from Archer are used. + */ public void swapArcher(int currentplno) { screenbg.setVisible(true); boolean swapdone = false; + // If the current player is no 1, the archer one will move to right, and the second move left if(curplay == 1) { Archer1 = new Archer (1, super.colorPlayer1, screenbg); Archer2 = new Archer (2, super.colorPlayer2, screenbg); while(!swapdone) { - screenbg.wait(20); // kurze Pause + screenbg.wait(20); // short waiting time Archer1.stepRight(); Archer2.stepLeft(); // Stop if the arrow hits the ground @@ -195,11 +263,12 @@ public void swapArcher(int currentplno) curplay = 2; } } + // If the current player is no 2, the archer one will move to left, and the second move right } else if(curplay == 2) { Archer1 = new Archer (2, super.colorPlayer1, screenbg); Archer2 = new Archer (1, super.colorPlayer2, screenbg); while(!swapdone) { - screenbg.wait(20); // kurze Pause + screenbg.wait(20); // short waiting time Archer2.stepRight(); Archer1.stepLeft(); // Stop if the arrow hits the ground @@ -211,35 +280,40 @@ public void swapArcher(int currentplno) } } - /** - * Clear all arrows + /** + * Method is able to clear the arrow from the field */ public void clearField() { + screenbg.setForegroundColor(super.bgColor); + // if the arrow hit the target, it will be re painted Rectangle hitarrows = new Rectangle(super.wallThickness, 0, super.arrowWidth, super.canvasHeight); screenbg.fill(hitarrows); - Rectangle lostarrows = new Rectangle(super.wallThickness, super.canvasHeight - super.arrowHeight, super.archerXpos - super.wallThickness, super.arrowHeight); + // if the arrow did not hit the target, it will be re painted + Rectangle lostarrows = new Rectangle(super.wallThickness, super.canvasHeight - super.arrowHeight, + super.archerXpos - super.wallThickness, super.arrowHeight); screenbg.fill(lostarrows); } - /** + /** * Draw the two Scores */ public void printScore(int inputscore1, int inputscore2) { - score1 = inputscore1; - score2 = inputscore2; + score1 = inputscore1; //init of score player one + score2 = inputscore2; //init of score player one screenbg.setVisible(true); screenbg.setForegroundColor(super.bgColor); screenbg.fillRectangle(super.scoreXpos, super.scoreYpos - 20, 200, 50); - Points Score1 = new Points(1, score1, screenbg); - Score1.draw(); - Points Score2 = new Points(2, score2, screenbg); - Score2.draw(); + // set position of the scores and draw them + Points Points1 = new Points(1, score1, screenbg); + Points1.draw(); + Points Points2 = new Points(2, score2, screenbg); + Points2.draw(); } - /** + /** * Show the canvas */ public void visible(boolean state) @@ -247,3 +321,4 @@ public void visible(boolean state) screenbg.setVisible(state); } } + diff --git a/Game.class b/Game.class index 42445d8a6957b077c4494913d3bae549b5d0e22c..e525fb0f3c5943ed10d87983092df5236e69549b 100644 GIT binary patch delta 25 hcmZ3=vy^8-ALG%D{i%$Mjg!AJDl)cg7H8sP0RVp82z&ql delta 25 hcmZ3=vy^8-ALE{l{i%$M6_dX*Dl%4Y7H8sP0RVlO2w?yK diff --git a/Game.ctxt b/Game.ctxt index 2f1bccf..73abad2 100644 --- a/Game.ctxt +++ b/Game.ctxt @@ -1,6 +1,6 @@ #BlueJ class context comment0.target=Game -comment0.text=\r\n\ \r\n\ @author\ JR,\ CS,\ SVC\r\n\ @version\ v1.2\ (02.06.2022\ 15\:35)\r\n +comment0.text=\r\n\ \r\n\ @author\ JR,\ CS,\ SVC\r\n\ @version\ v1.3\ (02.06.2022\ 16\:45)\r\n comment1.params=args comment1.target=void\ main(java.lang.String[]) comment2.params= diff --git a/Game.java b/Game.java index 2757ecf..bee8837 100644 --- a/Game.java +++ b/Game.java @@ -3,12 +3,12 @@ /** * * @author JR, CS, SVC - * @version v1.2 (02.06.2022 15:35) + * @version v1.3 (02.06.2022 16:45) */ public class Game { private Terminal terminal; //Global terminal - protected static final int canvasHeight = 700; //Height of the canvas. Default: 700 + protected static final int canvasHeight = 709; //Height of the canvas. Default: 700 protected static final int canvasWidth = 1000; //Width of the canvas. Default: 1000 protected static final int wallStart = 100; //Start of the wall. Default: 100 protected static final int wallThickness = 20; //Thickness of the wall. Default: 20 diff --git a/Points.class b/Points.class index aa1c5924025c0ffc43eb5b525d25e60899219f65..3c15f5a190d86d26201bca917d50a6d3fb15161c 100644 GI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E_60_#Hs zCW`_KLjfm-{Yf7Y6j*m91zkl!S5we6dCVt|Fy|XGWPS%@EWTeuH+|~kxFoQ}M4fdD z8zQlSt~_ueH6OD=tjd{PjTkv!M~`36e_-4|q`DE~a1%@EX5!2(Sc+Sj!M8DMZ_m?m z&4`wK)`nW17rLN|A_Xd=12|c_$X=9I7ZK6>P$uJ|z0j2rxuTiEQv(FGQrt=5cM%}> zuyF37@9)hMS``WvxQd`)s+=x-PzT~Q-ukEjO<@E?%n*x0(171W=*118DrHjf)241C zuJ=Js57B3o5G#aOF}19IFD8UMrVbH9g-IW(2x^kHvSSEKLh88O!lfh9M1b()F_AOz zM2wJ4F0d(LACg32h#X)8Mgut-S{E6sh zp{=Fa;)ocE4xvUHJE?pODg5U_;10gC3i$>16RPc3?SN_r{|Ec7@l*f+ diff --git a/Terminal.ctxt b/Terminal.ctxt index 53bc9da..8c302f3 100644 --- a/Terminal.ctxt +++ b/Terminal.ctxt @@ -1,29 +1,34 @@ #BlueJ class context comment0.target=Terminal -comment0.text=\r\n\ \r\n\ Die\ Klasse\ game\ beinhaltet\ die\ wichtige\ Funktion,\ das\ Spielfeld\ zu\ erstellen.\r\n\ \r\n\ @author\ JR,\ CS,\ SVC\r\n\ @version\ v1.2\ (02.06.2022\ 15\:35)\r\n +comment0.text=\r\n\ \r\n\ The\ Terminal\ creates\ the\ field/dashboard.\r\n\ It\ is\ also\ able\ to\ open\ a\ console\ for\ the\ input\ of\ the\ game\ instructions.\r\n\ Terminal\ gets\ and\ checks\ the\ user\ inputs.\r\n\ \r\n\ One\ important\ thing\ is\ to\ give\ messages\ and\ feedback\ to\ the\ user.\r\n\ \ \ \ \ \ \ \ \ \ \ \ \ \ -\ game\ instruction\r\n\ \ \ \ \ \ \ \ \ \ \ \ \ \ -\ hints\ for\ inputs\r\n\ \ \ \ \ \ \ \ \ \ \ \ \ \ -\ help\r\n\ \r\n\ @author\ \ \ \ \ \ Johannes\ Richter\r\n\ \ \ \ \ \ \ \ \ \ \ \ \ \ Simon\ Cirdei\r\n\ \ \ \ \ \ \ \ \ \ \ \ \ \ Christoph\ Schramm\r\n\ @version\ \ \ \ \ v1.3\ (02.06.2022\ 16\:45)\r\n comment1.params= comment1.target=void\ newGame() +comment1.text=\r\n\ The\ method\ game\ checks\ all\ the\ inputs\ of\ the\ players\ and\ runs\ selected\ loops.\r\n\ Instructions\ and\ errors/feedback\ will\ be\ given\r\n comment10.params= -comment10.target=void\ returnPoints() -comment10.text=\r\n\ \ Diese\ Methode\ gibt\ den\ aktuellen\ Punktestand\ auf\ der\ Konsole\ aus.\r\n +comment10.target=void\ error() +comment10.text=\r\n\ Feedback-Message\ in\ case\ of\ an\ error\r\n comment2.params= comment2.target=void\ inputForDartboard() +comment2.text=\r\n\ The\ method\ checks\ explicity\ the\ user\ input\ for\ the\ target-size\r\n comment3.params= -comment3.target=void\ errorValue() -comment3.text=\r\n\ Methode\ zur\ Ausgabe\ eines\ Error\ bez\u00FCglich\ der\ Oberfl\u00E4che\r\n +comment3.target=void\ startGame() +comment3.text=\r\n\ the\ method\ start\ the\ game\:\r\n\ \ \ \ \ \ \ \ \ \ -\ inputs\ will\ be\ validated\r\n\ \ \ \ \ \ \ \ \ \ -\ score\ is\ set\ to\ zero\r\n\ \ \ \ \ \ \ \ \ \ -\ the\ current\ player\ is\ ONE\r\n\ \ \ \ \ \ \ \ \ \ -\ a\ new\ surface\ (canvas)\ will\ be\ opened\r\n\ \ \ \ \ \ \ \ \ \ -\ printing\ of\ score\ and\ archers\r\n comment4.params= -comment4.target=void\ welcomeText() -comment4.text=\r\n\ Methode\ zur\ Ausgabe\ eines\ Willkommen-Textes\r\n +comment4.target=void\ swapPlayers() +comment4.text=\r\n\ the\ method\ switch\ the\ players\r\n comment5.params= -comment5.target=void\ howTo() -comment5.text=\r\n\ Die\ Methode\ help\ gibt\ die\ kleine\ Spielanleitung\ wieder.\r\n\ Sie\ wird\ dort\ aufgerufen,\ wo\ sie\ ben\u00F6tit\ wird.\ \r\n +comment5.target=void\ turn() +comment5.text=\r\n\ Gives\ information\ which\ player\ turn\ it\ is.\ \r\n\ Displays\ the\ points\ of\ the\ round\ in\ the\ console.\r\n comment6.params= -comment6.target=void\ error() -comment6.text=\r\n\ Error\ gibt\ einen\ Fehler\ wieder,\ wenn\ keine\ der\ geforderten\ Tasten\ gedr\u00FCckt\ wird\r\n +comment6.target=void\ returnPoints() +comment6.text=\r\n\ \ Method\ is\ able\ to\ give\ the\ points/score\ of\ the\ two\ players\ in\ the\ console\ at\ the\ end\ of\ the\ game\r\n comment7.params= -comment7.target=void\ startGame() +comment7.target=void\ errorValue() +comment7.text=\r\n\ Feedback-Message\ due\ to\ an\ error\ related\ to\ the\ surface\ (CanvasBG)\ \r\n comment8.params= -comment8.target=void\ swapPlayers() +comment8.target=void\ welcomeText() +comment8.text=\r\n\ First\ message\ to\ welcome\ the\ players\r\n comment9.params= -comment9.target=void\ turn() +comment9.target=void\ howTo() +comment9.text=\r\n\ Feedback-Message\ for\ instruction\ or\ help\r\n\ (How\ to\ play\ the\ game)\r\n numComments=11 diff --git a/Terminal.java b/Terminal.java index e72d8b3..94552c6 100644 --- a/Terminal.java +++ b/Terminal.java @@ -4,47 +4,83 @@ /** * - * Die Klasse game beinhaltet die wichtige Funktion, das Spielfeld zu erstellen. + * The Terminal creates the field/dashboard. + * It is also able to open a console for the input of the game instructions. + * Terminal gets and checks the user inputs. * - * @author JR, CS, SVC - * @version v1.2 (02.06.2022 15:35) + * One important thing is to give messages and feedback to the user. + * - game instruction + * - hints for inputs + * - help + * + * @author Johannes Richter + * Simon Cirdei + * Christoph Schramm + * @version v1.3 (02.06.2022 16:45) */ public class Terminal extends Game { - private Scanner scanner; //Einführen des scanners - private short a; //Short für den Bereich bullseye - private int ahalbe; //Variable zum Rechnen - private int starttarget; //Anfang Zielscheibenbereich - private CanvasBG screenbg; - private boolean checker; - private int ea, eb; + private Scanner scanner; // create a new scanner + private short a; // variable for area of bullseye + private int ahalbe; // variable to calculate the target + private int starttarget; // variable to set the beginning of the target + private CanvasBG screenbg; // set a new field/background + private boolean gameRunning; // is game on? + private int ea, eb; // help-variables for user inputs + + /** + * The method game checks all the inputs of the players and runs selected loops. + * Instructions and errors/feedback will be given + */ public void newGame () { - scanner = new Scanner (System.in); // Soll die Eingabe scannen. Dafür wird in Zeile 1 der Java Scanner importiert + scanner = new Scanner (System.in); // receives the input of the users welcomeText(); - boolean noInput = true; //setzt noInput auf true - super.currentPlayer = 1; + boolean noInput = true; // noInput is true or input is false + super.currentPlayer = 1; // current player is one + + // while the input is false, checking of input while (noInput = true) { - String input = scanner.nextLine(); //Scanner der Eingabe für Tastenkürzel liest + String input = scanner.nextLine(); // checking of the input + // if s, the game will starts if (input.equals("s")) { - startGame(); + // starts the game + if(gameRunning == false) { + startGame(); + gameRunning = true; + } else { + System.out.println("The game is already running. Please press n for the next turn."); + } } + // if n, checking of running. If true, the players change else if (input.equals("n")) { - screenbg.clearField(); - swapPlayers(); - turn(); + if(gameRunning == false) { + System.out.println("The game is not yet running. Please press s to start it first."); + } else { + screenbg.clearField(); + swapPlayers(); + turn(); + } + } + // if e, the game ends and the score will be printed else if (input.equals("e")) { noInput = false; System.out.println("Game over."); + gameRunning = false; returnPoints(); - System.exit(0); + System.exit(0); // closes the screen -> the console stays opened } + // if h, the instruction are printed else if (input.equals("h")) { howTo(); } + /** + * this is a fast solution for debbugging! + * else if (input.equals("joe")) { screenbg = new CanvasBG ((short)30, 265); + gameRunning = true; super.currentPlayer = 1; super.scorePlayer1 = 0; super.scorePlayer2 = 0; @@ -53,17 +89,24 @@ else if (input.equals("joe")) { screenbg.printArcher(); turn(); } + */ + + // if nothing of the previous conditions happens, an error mesage will be print. else { error(); } } } + /** + * The method checks explicity the user input for the target-size + */ public void inputForDartboard() { //ask for a System.out.println("Please enter a value for a [between 1 & " + (super.canvasHeight-super.wallStart)/9+"]. Hint: " +((super.canvasHeight-super.wallStart)/30)+" is a good value."); + //check input for a boolean aOK = false; while(!aOK) { Scanner inputDimensions = new Scanner(System.in); @@ -77,16 +120,16 @@ public void inputForDartboard() { aOK = true; } } - //ask for b System.out.println("Please enter a value for b [between "+(super.wallStart+(4*ea)+ahalbe) +" & "+(super.canvasHeight-(4*ea)-ahalbe)+"]. Hint: " +((super.canvasHeight-super.wallStart)/2+super.wallStart)+" is a good value."); + //check input for b boolean bOK = false; while(!bOK) { Scanner inputDimensions = new Scanner(System.in); - eb = inputDimensions.nextInt(); //process b - starttarget = eb - 4 * ea - ahalbe; //required var for check b + eb = inputDimensions.nextInt(); //process b + starttarget = eb - 4 * ea - ahalbe; //required var for check b if(eb < super.wallStart+(4*ea)+ahalbe) { errorValue(); } else if(eb > (super.canvasHeight-(4*ea)-ahalbe)) { @@ -95,48 +138,18 @@ public void inputForDartboard() { bOK = true; } } - + // output for player :) System.out.println("Inputs saved. Let's go!"); - } - - /** - * Methode zur Ausgabe eines Error bezüglich der Oberfläche - */ - public void errorValue() { - System.out.println ("ERROR. Please enter a valid value. The limits can be seen above. You may try again."); } /** - * Methode zur Ausgabe eines Willkommen-Textes + * the method start the game: + * - inputs will be validated + * - score is set to zero + * - the current player is ONE + * - a new surface (canvas) will be opened + * - printing of score and archers */ - public void welcomeText() { - System.out.println("Welcome to 2Darts" + "\n\n" + "Before playing, here is the overview:" +"\n"); - System.out.println("- The red area (bullseye) gives 50 points" + "\n" + "- Green (bull) gives 25 points" + "\n" + "- Black gives 10 points" + "\n" + "- Everything else 0 points"); - howTo(); - } - - /** - * Die Methode help gibt die kleine Spielanleitung wieder. - * Sie wird dort aufgerufen, wo sie benötit wird. - */ - public void howTo() { - System.out.println("\n" +"------------------------------------------------"); - System.out.println("s = start game"); - System.out.println("n = next player"); - System.out.println("e = end game"); - System.out.println("h = help"); - System.out.println("------------------------------------------------"); - } - - /** - * Error gibt einen Fehler wieder, wenn keine der geforderten Tasten gedrückt wird - */ - public void error() { - System.out.println("\n" +"------------------------------------------------" +"\n"); - System.out.println("Mistake! Please check your entry!"); - System.out.println("\n" + "If you need some help, press" + " h" + ""); - } - public void startGame() { inputForDartboard(); super.currentPlayer = 1; @@ -148,10 +161,16 @@ public void startGame() { screenbg.printArcher(); turn(); } + + /** + * the method switch the players + */ public void swapPlayers() { + // archer will be switched screenbg.swapArcher(super.currentPlayer); - + + //players-switch if (super.currentPlayer == 1) { super.currentPlayer = 2; } @@ -160,43 +179,101 @@ else if(super.currentPlayer == 2) { } } + /** + * Gives information which player turn it is. + * Displays the points of the round in the console. + */ public void turn() { System.out.println("It's player "+ super.currentPlayer +"'s turn."); int score = screenbg.shootArrow(); - //send won points to super + // send won points to super if(super.currentPlayer == 1) { super.scorePlayer1 = super.scorePlayer1 + score; } else if(super.currentPlayer == 2) { super.scorePlayer2 = super.scorePlayer2 + score; } + // Message when arrow hits the bullseye if(score == 50) { - System.out.println("BULLSEYE! Player "+ super.currentPlayer +" got "+ score + " Points! :)"); - } else if(score == 0) { + System.out.println("BULLSEYE! Player "+ super.currentPlayer +" got "+ score + " points! :)"); + } + // Message when arrow hits nothing + else if(score == 0) { System.out.println("Player "+ super.currentPlayer +" missed. :("); - } else { - System.out.println("Player "+ super.currentPlayer +" got "+ score + " Points."); + } + // Message when arrow hits green or black + else { + System.out.println("Player "+ super.currentPlayer +" got "+ score + " points."); } screenbg.printScore(super.scorePlayer1, super.scorePlayer2); } - /** - * Diese Methode gibt den aktuellen Punktestand auf der Konsole aus. + /** + * Method is able to give the points/score of the two players in the console at the end of the game */ public void returnPoints() { + //If score player 1 is bigger than two, Player 1 wins if(super.scorePlayer1 > super.scorePlayer2) { - System.out.println("Player 1 wins with " + super.scorePlayer1 + " points. Player 2 has " + super.scorePlayer2 + " points."); - } else if(super.scorePlayer2 > super.scorePlayer1) { - System.out.println("Player 2 wins with " + super.scorePlayer2 + " points. Player 1 has " + super.scorePlayer1 + " points."); - } else if((super.scorePlayer1 == 0) && (super.scorePlayer1 == 0)) { - System.out.println("Did you even play? Both players have " + super.scorePlayer1 + " points."); - } else if(super.scorePlayer1 == super.scorePlayer2) { + System.out.println("Player 1 wins with " + super.scorePlayer1 + " points. " + +"Player 2 has " + super.scorePlayer2 + " points."); + } + //If score player 2 is bigger than two, Player 2 wins + else if(super.scorePlayer2 > super.scorePlayer1) { + System.out.println("Player 2 wins with " + super.scorePlayer2 + " points. " + +"Player 1 has " + super.scorePlayer1 + " points."); + } + //If score is zero + else if((super.scorePlayer1 == 0) && (super.scorePlayer1 == 0)) { + System.out.println("Did you even play? No player has any points."); + } + //If score player 1 is the same as player 2 = tie + else if(super.scorePlayer1 == super.scorePlayer2) { System.out.println("It's a tie! Both players have " + super.scorePlayer1 + " points."); } + // you can close the console with Ctrl+W System.out.println("Press Ctrl+W to close this window."); + } + + /** + * Feedback-Message due to an error related to the surface (CanvasBG) + */ + public void errorValue() { + System.out.println ("ERROR. Please enter a valid value. The limits can be seen above. You may try again."); + } + + /** + * First message to welcome the players + */ + public void welcomeText() { + System.out.println("Welcome to 2Darts" + "\n\n" + "Before playing, here is the overview:" +"\n"); + System.out.println("- The red area (bullseye) gives 50 points" + "\n" + "- Green (bull) gives 25 points" + + "\n" + "- Black gives 10 points" + "\n" + "- Everything else 0 points"); + howTo(); + } + + /** + * Feedback-Message for instruction or help + * (How to play the game) + */ + public void howTo() { + System.out.println("\n" +"------------------------------------------------"); + System.out.println("s = start game"); + System.out.println("n = next player"); + System.out.println("e = end game"); + System.out.println("h = help"); + System.out.println("------------------------------------------------"); + } + + /** + * Feedback-Message in case of an error + */ + public void error() { + System.out.println("ERROR. This input cannot be processed. Please check your entry."); + System.out.println("If you need help, enter h."); } } + diff --git a/package.bluej b/package.bluej index bc76610..ac74f39 100644 --- a/package.bluej +++ b/package.bluej @@ -1,45 +1,45 @@ #BlueJ package file -dependency1.from=Terminal -dependency1.to=CanvasBG +dependency1.from=Points +dependency1.to=Canvas dependency1.type=UsesDependency -dependency2.from=Points +dependency2.from=Archer dependency2.to=Canvas dependency2.type=UsesDependency -dependency3.from=Archer +dependency3.from=Arrow dependency3.to=Canvas dependency3.type=UsesDependency -dependency4.from=Arrow -dependency4.to=Canvas +dependency4.from=Game +dependency4.to=Terminal dependency4.type=UsesDependency -dependency5.from=CanvasBG -dependency5.to=Canvas +dependency5.from=Terminal +dependency5.to=CanvasBG dependency5.type=UsesDependency dependency6.from=CanvasBG -dependency6.to=Archer +dependency6.to=Canvas dependency6.type=UsesDependency dependency7.from=CanvasBG -dependency7.to=Points +dependency7.to=Archer dependency7.type=UsesDependency dependency8.from=CanvasBG -dependency8.to=Arrow +dependency8.to=Points dependency8.type=UsesDependency -dependency9.from=Game -dependency9.to=Terminal +dependency9.from=CanvasBG +dependency9.to=Arrow dependency9.type=UsesDependency -editor.fx.0.height=737 -editor.fx.0.width=814 -editor.fx.0.x=360 -editor.fx.0.y=28 +editor.fx.0.height=744 +editor.fx.0.width=1376 +editor.fx.0.x=1528 +editor.fx.0.y=-8 objectbench.height=136 -objectbench.width=1336 +objectbench.width=1512 package.divider.horizontal=0.5850032320620556 -package.divider.vertical=0.7779503105590062 -package.editor.height=494 -package.editor.width=1233 -package.editor.x=1528 +package.divider.vertical=0.8062770562770563 +package.editor.height=590 +package.editor.width=1410 +package.editor.x=0 package.editor.y=0 -package.frame.height=744 -package.frame.width=1376 +package.frame.height=838 +package.frame.width=1550 package.numDependencies=9 package.numTargets=7 package.showExtends=true