a_2048_gui
Differences
This shows you the differences between two versions of the page.
| Both sides previous revisionPrevious revisionNext revision | Previous revision | ||
| a_2048_gui [2026/02/12 15:57] – frchris | a_2048_gui [2026/02/12 16:36] (current) – frchris | ||
|---|---|---|---|
| Line 9: | Line 9: | ||
| - '' | - '' | ||
| - | Also add '' | + | Also add '' |
| Line 36: | Line 36: | ||
| | | ||
| | | ||
| - | | + | |
| | | ||
| - | | + | |
| - | | + | |
| - | | + | |
| - | | + | |
| + | | ||
| + | | ||
| + | | ||
| + | | ||
| */ | */ | ||
| Line 56: | Line 60: | ||
| String message; | String message; | ||
| private Game2048 myGame; | private Game2048 myGame; | ||
| - | + | private String version = " | |
| public GUI2048() | public GUI2048() | ||
| Line 81: | Line 85: | ||
| } | } | ||
| public void paintComponent(Graphics g){ | public void paintComponent(Graphics g){ | ||
| - | super.paintComponent(g); | + | |
| - | g.setColor(Color.WHITE); | + | g.setColor(Color.WHITE); |
| - | g.fillRect(0, | + | g.fillRect(0, |
| - | g.setColor(Color.BLUE); | + | g.setColor(Color.BLUE); |
| - | + | ||
| - | g.setFont(new Font(" | + | g.setFont(new Font(" |
| - | g.drawString(" | + | g.drawString(" |
| - | g.setFont(titleFont); | + | g.setFont(titleFont); |
| - | g.setColor(Color.BLACK); | + | g.setColor(Color.BLACK); |
| - | g.drawString(" | + | g.drawString(" |
| - | g.drawString( message , 20, WIDTH - 50); | + | g.drawString(" |
| - | + | g.drawString( message , 20, WIDTH - 50); | |
| - | g.setFont(regularFont); | + | |
| - | g.drawString(" | + | g.setFont(regularFont); |
| - | g.setFont(new Font(" | + | g.drawString(version, 20, 50); |
| - | g.setColor(Color.red); | + | g.setFont(new Font(" |
| - | drawBoard(g); | + | g.setColor(Color.red); |
| - | + | drawBoard(g); | |
| - | + | ||
| - | } | + | } |
| public void drawBoard(Graphics g) { | public void drawBoard(Graphics g) { | ||
| Line 115: | Line 119: | ||
| } | } | ||
| g.setColor(Color.BLACK); | g.setColor(Color.BLACK); | ||
| + | int thickness = 3; // of the grid lines | ||
| for(int r = 0; r <= boardSize; r++) { | for(int r = 0; r <= boardSize; r++) { | ||
| - | g.drawLine(left, | + | for(int i = 0; i < thickness ; i++) |
| + | | ||
| } | } | ||
| for(int c = 0; c <= boardSize; c++){ | for(int c = 0; c <= boardSize; c++){ | ||
| - | g.drawLine(left+c*size, | + | for(int i = 0; i < thickness ; i++) |
| + | g.drawLine(left+c*size+i, top , | ||
| } | } | ||
| } | } | ||
| Line 169: | Line 176: | ||
| myGame.add2ToBoard(); | myGame.add2ToBoard(); | ||
| if (myGame.gameOver()) | if (myGame.gameOver()) | ||
| - | message = "Game Over - You reached "+ myGame.max(); | + | message = "Game Over - You reached "+ myGame.getMax(); |
| repaint(); | repaint(); | ||
| } | } | ||
a_2048_gui.1770929875.txt.gz · Last modified: by frchris
