@Test public void testGetCellValuePlayerX() { GameLogic g = new GameLogic(); g.ticBox(7); assertEquals(1, g.getBoard().getCellValue(7)); }
@Test public void testTicBoxSingleTic() { GameLogic g = new GameLogic(); g.ticBox(3); assertEquals(1, g.getBoard().getCellValue(3)); }
@Test public void testLegalMoveEmpty() { GameLogic g = new GameLogic(); // Tests an empty board assertEquals(true, g.legalMove(0)); assertEquals(true, g.legalMove(1)); }
public void hit() { this.hp--; if (this.hp == 0) { this.isDestroyed = true; GameLogic.getInstance().enemyCount++; GameLogic.getInstance().status.addScore(this.score); } }
@Test public void testGetCellValuePlayerO() { GameLogic g = new GameLogic(); g.ticBox(2); g.ticBox(3); assertEquals(2, g.getBoard().getCellValue(3)); }
@Test public void testLegalMoveIllegal() { GameLogic g = new GameLogic(); // Illegal inputs assertEquals(false, g.legalMove(-1)); assertEquals(false, g.legalMove(9)); }
@Test public void testTicBoxTwoTics() { GameLogic g = new GameLogic(); g.ticBox(4); g.ticBox(5); assertEquals(1, g.getBoard().getCellValue(4)); assertEquals(2, g.getBoard().getCellValue(5)); }
@Test public void testCounter() { GameLogic g = new GameLogic(); for (int i = 0; i < 10; i++) { g.ticBox(i); } assertEquals(9, g.getCountMoves()); }
/** Paints the grid, the falling shape and the next shape */ public void paintComponent(Graphics g) { super.paintComponent(g); grid.drawGrid(grid.getGrid(), g); game.getCurrentShape().drawShape(g); game.drawAllShapes(g, game.getAllShapes()); repaint(); }
@Test public void testTicBoxThreeTics() { GameLogic g = new GameLogic(); g.ticBox(0); g.ticBox(1); g.ticBox(2); assertEquals(1, g.getBoard().getCellValue(0)); assertEquals(2, g.getBoard().getCellValue(1)); assertEquals(1, g.getBoard().getCellValue(2)); }
/** * makes a movement, conquer positions, update possible positions, toggles player * * @param player * @param col * @param row * @return if the turn has to change */ private boolean doMovement(int player, int col, int row) { boolean changePlayer = false; if (gameLogic.canSet(player, col, row)) { gameLogic.setStone(player, col, row); gameLogic.conquerPosition(player, col, row); changePlayer = togglePlayer(); } notifyChanges(); return changePlayer; }
@Test public void testProcessTurn1Win() { GameLogic g = new GameLogic(); assertEquals(1, g.processTurn(0)); assertEquals(2, g.processTurn(1)); assertEquals(1, g.processTurn(3)); assertEquals(2, g.processTurn(4)); assertEquals(3, g.processTurn(6)); assertEquals(0, g.processTurn(7)); }
public static void newGame() { gui.removeCards(); stand = false; GameLogic.setupGame(); player = new Player(); dealer = new Player(); gameLoop.loop(); gameLoop.dealerLoop(); if (GameLogic.check(player, dealer)) { System.out.println("You win"); } else { System.out.println("You lose"); } }
/** * Changes the player * * @return if the player has been toggled (if the opponent player can play) */ private boolean togglePlayer() { int current = gameLogic.getCurrentPlayer(); boolean toggled; // if the next player can play (has at least one place to put the // chip) if (!gameLogic.isBlockedPlayer(GameHelper.opponent(current))) { // just toggles gameLogic.setCurrentPlayer(GameHelper.opponent(current)); toggled = true; } else { System.out.println( String.format("player %d cannot play!!!!!!!!!!!!!!!!!!!", GameHelper.opponent(current))); toggled = false; } return toggled; }
private void initState() { Block[][] blocks = null; if (mSizeInfo.useDefaultSize) { blocks = GameLogic.createBlocksByScreen( mViewInfo.blockRect.width(), mViewInfo.blockRect.height(), mPictureInfo.animalBitmaps.size(), getResources().getDisplayMetrics().densityDpi); } else { blocks = GameLogic.createBlocks(mSizeInfo.rows, mSizeInfo.cols, mPictureInfo.animalBitmaps.size()); } mGameState.start(blocks, mCurLevel); eventBus.post(GameEvent.createEvent(GameEvent.GAME_START_ONE_LEVEL)); invalidate(); }
private void dealerLoop() { while (dealer.getPlayerHand().getValue() <= 17) { dealer.getPlayerHand().addCard(GameLogic.deal()); GameLoop.drawCard(dealer); } System.out.println("Dealer value: " + dealer.getPlayerHand().getValue()); }
/** Notifies the listener for the changes occured in the game */ private void notifyChanges() { if (gameEventsListener != null) { int p1 = gameLogic.getCounterForPlayer(GameLogic.PLAYER_ONE); int p2 = gameLogic.getCounterForPlayer(GameLogic.PLAYER_TWO); gameEventsListener.onScoreChanged(p1, p2); if (gameLogic.isFinished()) { int winner = GameLogic.EMPTY; if (p1 > p2) { winner = GameLogic.PLAYER_ONE; } else if (p2 > p1) { winner = GameLogic.PLAYER_TWO; } gameEventsListener.onGameFinished(winner); } } }
@Override protected void logicLoop(long frameTime) { // System.out.println("Looping"); if (gameRunning) { disableLogic(); gameLogic.runGame(); gameRunning = false; enableLogic(); } }
private void createEntities() { gameLogic = new GameLogic(); Carte carte = new Carte(gameLogic); gameLogic.setCarte(carte); for (int i = 1; i <= 6; i++) { Zone zone = createZone(i); groupZones.addActor(new ZoneActor(zone)); carte.addZone(zone); } }
@Test public void testLegalMoveNotEmpty() { GameLogic g = new GameLogic(); g.ticBox(0); assertEquals(false, g.legalMove(0)); assertEquals(true, g.legalMove(1)); g.ticBox(1); assertEquals(false, g.legalMove(1)); assertEquals(true, g.legalMove(2)); assertEquals(false, g.legalMove(0)); }
@Override public void render(float delta) { GL10 gl = Gdx.graphics.getGL10(); // Update model gameLogic.update((int) (delta * 1000.0f)); // clear previous frame gl.glClear(GL10.GL_COLOR_BUFFER_BIT); stage.act(delta); stage.draw(); }
public void run() { System.out.println("Client connected to socket: " + _socket.toString()); try { _out = new PrintWriter(_socket.getOutputStream(), true); _in = new BufferedReader(new InputStreamReader(_socket.getInputStream())); String inputLine, outputLine; GameLogic businessLogic = new GameLogic(); outputLine = businessLogic.processInput(null); _out.println(outputLine); // Read from socket and write back the response to client. while ((inputLine = _in.readLine()) != null) { outputLine = businessLogic.processInput(inputLine); if (outputLine != null) { _out.println(outputLine); if (outputLine.equals("exit")) { // System.out.println("Server is closing socket for client:" + // _socket.getLocalSocketAddress()); break; } } else { // System.out.println("OutputLine is null!"); } } } catch (IOException e) { e.printStackTrace(); } finally { // In case anything goes wrong we need to close our I/O streams and sockets. try { _out.close(); _in.close(); _socket.close(); } catch (Exception e) { System.out.println("Couldn't close I/O streams"); } } }
@Test public void testCheckForWin() { GameLogic g = new GameLogic(); g.ticBox(0); g.ticBox(1); assertEquals(false, g.checkForWin()); g.ticBox(2); g.ticBox(8); g.ticBox(3); g.ticBox(4); g.ticBox(5); assertEquals(false, g.checkForWin()); g.ticBox(7); assertEquals(true, g.checkForWin()); }
/** * Jos peli on pällä se kuuntelee aina pausen painamista, jos peli ei ole pausella se kuuntelee * myös pelin ohjauspainkikkeita. * * @param ke painettu näppäin */ @Override public void keyPressed(KeyEvent ke) { if (game.getIsGameRunning()) { if (ke.getKeyCode() == KeyEvent.VK_P) { game.setIsPaused(); } else if (!game.getIsPaused()) { if (ke.getKeyCode() == KeyEvent.VK_LEFT) { game.setIsMoved(-1); } else if (ke.getKeyCode() == KeyEvent.VK_RIGHT) { game.setIsMoved(1); } else if (ke.getKeyCode() == KeyEvent.VK_UP || ke.getKeyCode() == KeyEvent.VK_X) { game.setIsRotated(1); } else if (ke.getKeyCode() == KeyEvent.VK_Z) { game.setIsRotated(-1); } else if (ke.getKeyCode() == KeyEvent.VK_DOWN) { game.setSoftDrop(1); } else if (ke.getKeyCode() == KeyEvent.VK_SPACE) { game.setDropDownTrue(); } } } }
@Test public void testReset_game() { GameLogic g = new GameLogic(); g.reset_game(); assertEquals(false, g.getIsFinished()); assertEquals(true, g.getPlayer().getPlayer1Turn()); assertEquals(0, g.getBoard().getBoardByIndex(0)); assertEquals(0, g.getBoard().getBoardByIndex(5)); assertEquals(0, g.getBoard().getBoardByIndex(8)); }
private void loop() { GameLogic.setupGame(); GameLoop.drawCard(dealer); if (player.getPlayerHand().getValue() == 21) { System.out.println("BLACKJACK"); return; } while (player.getPlayerHand().getValue() < 21 ^ stand) { GameLoop.drawCard(player); } GameLoop.drawCard(player); }
@Test public void testProcessTurnIllegal() { GameLogic g = new GameLogic(); assertEquals(0, g.processTurn(-1)); assertEquals(0, g.processTurn(9)); assertEquals(1, g.processTurn(0)); assertEquals(0, g.processTurn(0)); assertEquals(2, g.processTurn(1)); assertEquals(0, g.processTurn(1)); assertEquals(0, g.processTurn(0)); }
private void checkForSpecialTile(List<Tile> list) { List<Tile> res = new ArrayList<Tile>(); List<Tile> tempTiles = null; for (Tile t : list) { tempTiles = null; if (t instanceof FlameTile && !t.detonate) { tempTiles = getTilesToDeleteFlame(t); } else if (t instanceof StarTile && !t.detonate) { tempTiles = getTilesToDeleteStar(t); } if (tempTiles != null) { for (Tile tt : tempTiles) { if (!list.contains(tt)) { res.add(tt); } } } } GameLogic.get().addTiles(res, list); }
@Test public void testProcessTurnDraw() { GameLogic g = new GameLogic(); assertEquals(1, g.processTurn(4)); assertEquals(2, g.processTurn(1)); assertEquals(1, g.processTurn(0)); assertEquals(2, g.processTurn(8)); assertEquals(1, g.processTurn(5)); assertEquals(2, g.processTurn(3)); assertEquals(1, g.processTurn(6)); assertEquals(2, g.processTurn(2)); assertEquals(5, g.processTurn(7)); assertEquals(0, g.processTurn(0)); }
@Test public void testGetCellValueEmptyCell() { GameLogic g = new GameLogic(); assertEquals(0, g.getBoard().getCellValue(0)); }