Code Sketch
BixuuRealCricketPro_MainUI 2D
Category: Programming
import java.awt.{BorderLayout, CardLayout, Color, Dimension, Font, GradientPaint, Graphics, Graphics2D, GridLayout, FlowLayout, RenderingHints}
import java.awt.event.{ActionEvent, ActionListener, WindowAdapter, WindowEvent}
import javax.swing.{BorderFactory, Box, BoxLayout, JButton, JComboBox, JFrame, JLabel, JOptionPane, JPanel, JPasswordField, JTextField, SwingConstants, Timer, WindowConstants}
import scala.util.Random
object BixuuRealCricketPro_MainUI {
private val BG = new Color(7, 15, 29)
private val PANEL = new Color(17, 32, 52)
private val PANEL2 = new Color(25, 48, 72)
private val GREEN = new Color(36, 164, 103)
private val GOLD = new Color(250, 193, 72)
private val CYAN = new Color(69, 206, 226)
private val WHITE = new Color(246, 249, 252)
private val MUTED = new Color(165, 184, 205)
private val BLUE = new Color(62, 127, 205)
private val RED = new Color(190, 65, 76)
def main(args: Array[String]): Unit = {
javax.swing.SwingUtilities.invokeLater(new Runnable {
override def run(): Unit = {
try {
val frame = new CricketMainFrame()
frame.setVisible(true)
frame.toFront()
} catch {
case ex: Throwable =>
ex.printStackTrace()
JOptionPane.showMessageDialog(null, "Could not open Bixuu Cricket League: " + ex.toString, "Startup Error", JOptionPane.ERROR_MESSAGE)
}
}
})
}
private def label(text: String, size: Int, color: Color): JLabel = {
val l = new JLabel(text)
l.setFont(new Font("SansSerif", Font.BOLD, size))
l.setForeground(color)
l
}
private def button(text: String, color: Color): JButton = {
val b = new JButton(text)
b.setFont(new Font("SansSerif", Font.BOLD, 13))
b.setForeground(WHITE)
b.setBackground(color)
b.setOpaque(true)
b.setFocusPainted(false)
b.setBorder(BorderFactory.createCompoundBorder(
BorderFactory.createLineBorder(new Color(76, 111, 139), 1),
BorderFactory.createEmptyBorder(11, 15, 11, 15)))
b.setCursor(new java.awt.Cursor(java.awt.Cursor.HAND_CURSOR))
b
}
private def darkPanel(): JPanel = {
val p = new JPanel()
p.setBackground(BG)
p.setOpaque(true)
p
}
class CricketMainFrame extends JFrame("BIXUU CRICKET LEAGUE ? MAIN MENU") {
private val cards = new CardLayout()
private val root = new JPanel(cards)
private var playerName = "Guest Player"
private var cricketId = ""
private var teamName = "Bixuu Blasters"
private var bucks = 500
private var diamonds = 50
private var wins = 0
private var trophies = 0
private var tossDone = false
private var userBatting = true
private var runs = 0
private var wickets = 0
private var balls = 0
private var deliveryProgress = 0.0
private var deliveryRunning = false
private var paused = false
private var currentOvers = 2
private var currentInnings = 1
private var target = 0
private var firstInningsRuns = 0
private var matchFinished = false
private var commentary = "Welcome! Choose your match settings."
private val nameField = new JTextField(20)
private val idField = new JTextField(20)
private val passwordField = new JPasswordField(20)
private val teamField = new JTextField("Bixuu Blasters", 20)
private val countryBox = new JComboBox[String](Array("India", "Australia", "England", "New Zealand", "Pakistan", "Bangladesh", "Sri Lanka", "South Africa"))
private val opponentBox = new JComboBox[String](Array("New Zealand", "India", "Australia", "England", "Pakistan", "Bangladesh", "Sri Lanka", "South Africa"))
private val oversBox = new JComboBox[String](Array("2 Overs", "5 Overs", "10 Overs", "20 Overs"))
private val tossBox = new JComboBox[String](Array("HEADS", "TAILS"))
private val choiceBox = new JComboBox[String](Array("BAT FIRST", "BOWL FIRST"))
private val fieldBox = new JComboBox[String](Array("BALANCED", "ATTACKING", "BOUNDARY DEFENCE", "SPIN TRAP"))
private val statusLabel = label("Create an account or login to open the main menu.", 13, CYAN)
private val statsLabel = label("", 13, CYAN)
private val scoreLabel = label("0/0 (0.0)", 27, GOLD)
private val inningsLabel = label("INNINGS 1", 14, CYAN)
private val commentaryLabel = label(commentary, 12, WHITE)
private val stadium = new StadiumPanel(this)
private val controlPanel = new JPanel(new FlowLayout(FlowLayout.CENTER, 7, 5))
private val timer = new Timer(30, new ActionListener {
override def actionPerformed(e: ActionEvent): Unit = tickBall()
})
setDefaultCloseOperation(WindowConstants.DISPOSE_ON_CLOSE)
setMinimumSize(new Dimension(1050, 700))
setSize(1260, 820)
setLocationRelativeTo(null)
setContentPane(root)
root.add(buildLoginPage(), "login")
root.add(buildLobbyPage(), "lobby")
root.add(buildTeamPage(), "team")
root.add(buildMatchSetupPage(), "setup")
root.add(buildMatchPage(), "match")
root.add(buildRewardsPage(), "rewards")
root.add(buildEventsPage(), "events")
root.add(buildShopPage(), "shop")
root.add(buildLeaderboardPage(), "leaderboard")
cards.show(root, "login")
addWindowListener(new WindowAdapter {
override def windowClosing(e: WindowEvent): Unit = timer.stop()
override def windowClosed(e: WindowEvent): Unit = timer.stop()
})
private def showPage(name: String): Unit = {
cards.show(root, name)
root.revalidate()
root.repaint()
}
private def menuButton(text: String, color: Color)(action: => Unit): JButton = {
val b = button(text, color)
b.addActionListener(new ActionListener {
override def actionPerformed(e: ActionEvent): Unit = action
})
b
}
private def titleBlock(title: String, subtitle: String): JPanel = {
val p = new JPanel(new BorderLayout(5, 5))
p.setBackground(PANEL)
p.setBorder(BorderFactory.createEmptyBorder(17, 20, 17, 20))
p.add(label(title, 26, GOLD), BorderLayout.NORTH)
p.add(label(subtitle, 12, CYAN), BorderLayout.SOUTH)
p
}
private def buildLoginPage(): JPanel = {
val page = new JPanel(new GridLayout(1, 1))
page.setBackground(BG)
val center = new JPanel()
center.setLayout(new BoxLayout(center, BoxLayout.Y_AXIS))
center.setBackground(PANEL)
center.setBorder(BorderFactory.createCompoundBorder(
BorderFactory.createLineBorder(CYAN, 2),
BorderFactory.createEmptyBorder(28, 38, 28, 38)))
val heading = label("BIXUU CRICKET LEAGUE", 31, GOLD)
heading.setAlignmentX(0.5f)
val sub = label("CREATE YOUR TEAM ? WIN MATCHES ? LIFT THE CUP", 12, CYAN)
sub.setAlignmentX(0.5f)
center.add(heading)
center.add(Box.createVerticalStrut(8))
center.add(sub)
center.add(Box.createVerticalStrut(25))
center.add(label("PLAYER NAME", 12, MUTED))
center.add(nameField)
center.add(Box.createVerticalStrut(12))
center.add(label("CRICKET ID (FOR RETURNING PLAYER)", 12, MUTED))
center.add(idField)
center.add(Box.createVerticalStrut(12))
center.add(label("PASSWORD", 12, MUTED))
center.add(passwordField)
center.add(Box.createVerticalStrut(20))
val row = new JPanel(new GridLayout(1, 2, 12, 0))
row.setOpaque(false)
row.add(menuButton("CREATE ACCOUNT", GREEN) { createAccount() })
row.add(menuButton("LOGIN", BLUE) { loginAccount() })
center.add(row)
center.add(Box.createVerticalStrut(16))
statusLabel.setAlignmentX(0.5f)
center.add(statusLabel)
val outer = new JPanel(new java.awt.GridBagLayout())
outer.setBackground(BG)
outer.add(center)
page.add(outer)
page
}
private def createAccount(): Unit = {
val name = nameField.getText.trim
val password = new String(passwordField.getPassword)
if (name.length < 2 || password.length < 4) {
statusLabel.setText("Enter a name and a password with at least 4 characters.")
return
}
playerName = name
cricketId = "BIX" + java.lang.Long.toString(System.currentTimeMillis(), 36).toUpperCase
teamName = "Bixuu Blasters"
bucks = 500
diamonds = 50
statusLabel.setText("Account created. Your Cricket ID: " + cricketId)
JOptionPane.showMessageDialog(this, "Welcome " + playerName + "!\nYour Cricket ID is: " + cricketId + "\nKeep this ID to login again.")
updateStats()
showPage("lobby")
}
private def loginAccount(): Unit = {
val enteredId = idField.getText.trim.toUpperCase
if (enteredId.nonEmpty && cricketId.nonEmpty && enteredId == cricketId) {
playerName = nameField.getText.trim match {
case s if s.nonEmpty => s
case _ => playerName
}
updateStats()
showPage("lobby")
} else {
statusLabel.setText("Create an account first, then use your Cricket ID to login.")
}
}
private def updateStats(): Unit = {
statsLabel.setText("PLAYER: " + playerName + " ID: " + cricketId + " TEAM: " + teamName + " BUCKS: " + bucks + " DIAMONDS: " + diamonds + " WINS: " + wins)
}
private def buildLobbyPage(): JPanel = {
val page = darkPanel()
page.setLayout(new BorderLayout(15, 15))
page.setBorder(BorderFactory.createEmptyBorder(18, 20, 18, 20))
page.add(titleBlock("BIXUU CRICKET LEAGUE", "MAIN LOBBY ? WELCOME TO YOUR CRICKET WORLD"), BorderLayout.NORTH)
val center = new JPanel(new GridLayout(3, 3, 12, 12))
center.setOpaque(false)
center.add(menuButton("PLAY MATCH", GREEN) { resetSetup(); showPage("setup") })
center.add(menuButton("TEAM CREATOR", BLUE) { teamField.setText(teamName); showPage("team") })
center.add(menuButton("DAILY REWARDS", new Color(151, 104, 42)) { showPage("rewards") })
center.add(menuButton("IPL / WORLD CUP", new Color(54, 111, 151)) { resetSetup(); showPage("setup") })
center.add(menuButton("GEAR & KIT SHOP", new Color(117, 76, 150)) { showPage("shop") })
center.add(menuButton("EVENTS", new Color(110, 95, 46)) { showPage("events") })
center.add(menuButton("LEADERBOARD", new Color(44, 121, 105)) { showPage("leaderboard") })
center.add(menuButton("FRIEND ROOM", new Color(44, 91, 145)) { JOptionPane.showMessageDialog(this, "Friend Room is a local demo menu in this version.") })
center.add(menuButton("LOG OUT", RED) { showPage("login") })
page.add(center, BorderLayout.CENTER)
val bottom = new JPanel(new BorderLayout(6, 6))
bottom.setOpaque(false)
bottom.add(statsLabel, BorderLayout.CENTER)
bottom.add(label("BATTING ? BOWLING ? TOSS ? LIVE SCORE ? TROPHIES", 12, MUTED), BorderLayout.SOUTH)
page.add(bottom, BorderLayout.SOUTH)
page
}
private def buildTeamPage(): JPanel = {
val page = darkPanel()
page.setLayout(new BorderLayout(12, 12))
page.setBorder(BorderFactory.createEmptyBorder(20, 24, 20, 24))
page.add(titleBlock("TEAM CREATOR", "BUILD YOUR PLAYING XI"), BorderLayout.NORTH)
val form = new JPanel()
form.setOpaque(false)
form.setLayout(new BoxLayout(form, BoxLayout.Y_AXIS))
form.add(label("TEAM NAME", 12, MUTED))
form.add(teamField)
form.add(Box.createVerticalStrut(14))
form.add(label("SELECT YOUR PLAYING XI", 12, MUTED))
val roster = new JTextField("Aarav Mehta, Kabir Rao, Vivaan Patil, Arjun Nair, Dev Shah, Neil Das, Rohan Iyer, Aditya Sen, Yuvaan Joshi, Ishaan Kulkarni, Reyansh More", 70)
form.add(roster)
form.add(Box.createVerticalStrut(15))
form.add(menuButton("SAVE TEAM", GREEN) {
if (teamField.getText.trim.length < 3) JOptionPane.showMessageDialog(this, "Enter a team name with at least 3 characters.")
else { teamName = teamField.getText.trim; updateStats(); JOptionPane.showMessageDialog(this, "Team saved: " + teamName) }
})
form.add(Box.createVerticalStrut(12))
form.add(menuButton("BACK TO LOBBY", BLUE) { showPage("lobby") })
page.add(form, BorderLayout.CENTER)
page
}
private def resetSetup(): Unit = {
tossDone = false
statusLabel.setText("Select teams and call the toss.")
}
private def buildMatchSetupPage(): JPanel = {
val page = darkPanel()
page.setLayout(new BorderLayout(12, 12))
page.setBorder(BorderFactory.createEmptyBorder(20, 24, 20, 24))
page.add(titleBlock("MATCH CENTER", "TEAM SELECTION ? TOSS ? FIELD SETUP"), BorderLayout.NORTH)
val form = new JPanel(new GridLayout(0, 2, 12, 12))
form.setOpaque(false)
form.add(label("YOUR TEAM", 13, MUTED)); form.add(countryBox)
form.add(label("OPPONENT", 13, MUTED)); form.add(opponentBox)
form.add(label("OVERS", 13, MUTED)); form.add(oversBox)
form.add(label("CALL THE TOSS", 13, MUTED)); form.add(tossBox)
form.add(label("IF YOU WIN", 13, MUTED)); form.add(choiceBox)
form.add(label("FIELD SETTING", 13, MUTED)); form.add(fieldBox)
val middle = new JPanel(new BorderLayout(8, 12))
middle.setOpaque(false)
middle.add(form, BorderLayout.NORTH)
val buttons = new JPanel(new FlowLayout(FlowLayout.LEFT, 10, 5))
buttons.setOpaque(false)
buttons.add(menuButton("CALL TOSS", new Color(151, 104, 42)) { callToss() })
buttons.add(menuButton("START MATCH", GREEN) { if (tossDone) startMatch() else JOptionPane.showMessageDialog(this, "Call the toss first.") })
buttons.add(menuButton("BACK", BLUE) { showPage("lobby") })
middle.add(buttons, BorderLayout.CENTER)
middle.add(statusLabel, BorderLayout.SOUTH)
page.add(middle, BorderLayout.CENTER)
page
}
private def callToss(): Unit = {
val result = if (Random.nextBoolean()) "HEADS" else "TAILS"
val won = tossBox.getSelectedItem.toString == result
userBatting = if (won) choiceBox.getSelectedItem.toString == "BAT FIRST" else Random.nextBoolean()
tossDone = true
statusLabel.setText("TOSS: " + result + " ? " + (if (won) "YOU WON" else "OPPONENT WON") + ". " + (if (userBatting) "YOUR TEAM BATS FIRST." else "YOUR TEAM BOWLS FIRST."))
}
private def startMatch(): Unit = {
currentOvers = oversBox.getSelectedItem.toString.split(" ")(0).toInt
currentInnings = 1
target = 0
firstInningsRuns = 0
runs = 0
wickets = 0
balls = 0
matchFinished = false
deliveryRunning = false
paused = false
deliveryProgress = 0.0
commentary = "Match started. Press START BALL to begin the delivery."
scoreLabel.setText("0/0 (0.0)")
inningsLabel.setText("INNINGS 1 ? " + countryBox.getSelectedItem + (if (userBatting) " BATTING" else " BOWLING"))
commentaryLabel.setText(commentary)
updateMatchControls()
showPage("match")
timer.start()
}
private def buildMatchPage(): JPanel = {
val page = darkPanel()
page.setLayout(new BorderLayout(8, 8))
page.setBorder(BorderFactory.createEmptyBorder(10, 12, 10, 12))
val header = new JPanel(new BorderLayout(8, 5))
header.setBackground(PANEL)
val left = new JPanel(new GridLayout(2, 1)); left.setOpaque(false); left.add(scoreLabel); left.add(inningsLabel)
header.add(left, BorderLayout.WEST)
header.add(label("BIXUU CRICKET LEAGUE ? LIVE STADIUM", 13, CYAN), BorderLayout.EAST)
page.add(header, BorderLayout.NORTH)
page.add(stadium, BorderLayout.CENTER)
val bottom = new JPanel(new BorderLayout(5, 5)); bottom.setBackground(PANEL)
commentaryLabel.setBorder(BorderFactory.createEmptyBorder(5, 8, 5, 8))
bottom.add(commentaryLabel, BorderLayout.NORTH)
controlPanel.setOpaque(false)
bottom.add(controlPanel, BorderLayout.CENTER)
val actions = new JPanel(new FlowLayout(FlowLayout.CENTER, 8, 5)); actions.setOpaque(false)
actions.add(menuButton("START BALL", GREEN) { startBall() })
actions.add(menuButton("PAUSE / RESUME", RED) { togglePause() })
actions.add(menuButton("END MATCH", BLUE) { endMatch() })
bottom.add(actions, BorderLayout.SOUTH)
page.add(bottom, BorderLayout.SOUTH)
page
}
private def updateMatchControls(): Unit = {
controlPanel.removeAll()
if (userBatting) {
Vector("DEFEND", "DRIVE", "LOFT", "SWEEP", "CUT", "PULL").foreach { shot =>
controlPanel.add(menuButton(shot, BLUE) { playShot(shot) })
}
} else {
Vector("OFF", "MIDDLE", "LEG").foreach { line =>
controlPanel.add(menuButton(line, new Color(67, 88, 117)) { commentaryLabel.setText("Bowling line: " + line) })
}
Vector("FAST", "SWING", "OFF SPIN", "LEG SPIN").foreach { style =>
controlPanel.add(menuButton(style, new Color(102, 79, 137)) { commentaryLabel.setText("Bowling style: " + style) })
}
}
controlPanel.revalidate()
controlPanel.repaint()
}
private def startBall(): Unit = {
if (matchFinished || paused || deliveryRunning) return
deliveryProgress = 0.0
deliveryRunning = true
commentary = "Ball in play! Choose your shot at the right time."
commentaryLabel.setText(commentary)
stadium.repaint()
}
private def playShot(shot: String): Unit = {
if (!userBatting || !deliveryRunning || paused || matchFinished) return
val accuracy = Math.abs(deliveryProgress - 0.72)
val wicket = if (accuracy > 0.28) Random.nextInt(100) < 35 else Random.nextInt(100) < 7
val scored = if (wicket) 0 else if (accuracy < 0.08 && shot == "LOFT") 6 else if (accuracy < 0.13 && (shot == "DRIVE" || shot == "CUT" || shot == "SWEEP")) 4 else if (accuracy < 0.22) 2 else if (accuracy < 0.30) 1 else 0
finishBall(wicket, scored, shot + " selected")
}
private def resolveCpuBall(): Unit = {
val wicket = Random.nextInt(100) < 22
val scored = if (wicket) 0 else { val r = Random.nextInt(100); if (r < 8) 6 else if (r < 23) 4 else if (r < 58) 1 else 0 }
finishBall(wicket, scored, "CPU delivery resolved")
}
private def finishBall(out: Boolean, scored: Int, note: String): Unit = {
deliveryRunning = false
balls += 1
if (out) wickets += 1 else runs += scored
commentary = if (out) "WICKET! " + note else if (scored == 6) "SIX! " + note else if (scored == 4) "FOUR! " + note else scored + " run(s). " + note
scoreLabel.setText(runs + "/" + wickets + " (" + (balls / 6) + "." + (balls % 6) + ")")
inningsLabel.setText("INNINGS " + currentInnings + " ? " + (if (userBatting) countryBox.getSelectedItem else opponentBox.getSelectedItem))
commentaryLabel.setText(commentary)
stadium.repaint()
if (balls >= currentOvers * 6 || wickets >= 10) finishInnings()
}
private def finishInnings(): Unit = {
timer.stop()
deliveryRunning = false
if (currentInnings == 1) {
firstInningsRuns = runs
target = runs + 1
currentInnings = 2
runs = 0
wickets = 0
balls = 0
userBatting = !userBatting
scoreLabel.setText("0/0 (0.0)")
inningsLabel.setText("INNINGS 2 ? TARGET " + target)
commentaryLabel.setText("INNINGS BREAK! Target is " + target + ". Press START BALL.")
updateMatchControls()
timer.start()
} else endMatch()
}
private def endMatch(): Unit = {
timer.stop()
matchFinished = true
val won = if (currentInnings == 2 && userBatting) runs >= target else if (currentInnings == 2) firstInningsRuns > runs else runs > 0
if (won) { wins += 1; trophies += 1; bucks += 150 } else bucks += 50
updateStats()
commentaryLabel.setText(if (won) "YOU WON! +150 BIXUU BUCKS + TROPHY" else "MATCH FINISHED. +50 BIXUU BUCKS")
JOptionPane.showMessageDialog(this, (if (won) "CONGRATULATIONS ? YOU WON!" else "MATCH FINISHED") + "\nScore: " + runs + "/" + wickets + "\nBixuu Bucks: " + bucks + "\nTrophies: " + trophies)
showPage("lobby")
}
private def togglePause(): Unit = {
paused = !paused
if (paused) timer.stop() else timer.start()
commentaryLabel.setText(if (paused) "MATCH PAUSED" else "MATCH RESUMED")
}
private def tickBall(): Unit = {
if (!paused && !matchFinished && deliveryRunning) {
deliveryProgress += 0.035
if (deliveryProgress >= 1.0) {
if (userBatting) finishBall(Random.nextInt(100) < 20, 0, "You missed the delivery")
else resolveCpuBall()
}
stadium.repaint()
}
}
private def buildRewardsPage(): JPanel = {
val page = darkPanel(); page.setLayout(new BorderLayout(10, 10)); page.setBorder(BorderFactory.createEmptyBorder(20, 24, 20, 24))
page.add(titleBlock("DAILY CRICKET REWARDS", "CLAIM ONE REWARD PER DAY"), BorderLayout.NORTH)
val body = new JPanel(new GridLayout(0, 1, 8, 8)); body.setOpaque(false)
val rewardNames = Vector("Day 1 ? 200 Bixuu Bucks", "Day 2 ? 400 Bixuu Bucks", "Day 3 ? 800 Bixuu Bucks", "Day 4 ? 1,000 Bixuu Bucks", "Day 5 ? 7,000 Bucks + Trophy", "Day 6 ? 20 Training Tokens", "Day 7 ? RCB-inspired Team Card")
rewardNames.foreach { s => body.add(label(s, 15, WHITE)) }
body.add(menuButton("BACK TO LOBBY", BLUE) { showPage("lobby") })
page.add(body, BorderLayout.CENTER); page
}
private def buildEventsPage(): JPanel = {
val page = darkPanel(); page.setLayout(new BorderLayout(10, 10)); page.setBorder(BorderFactory.createEmptyBorder(20, 24, 20, 24))
page.add(titleBlock("BIXUU EVENTS", "SEASONAL CHALLENGES"), BorderLayout.NORTH)
val body = new JPanel(new GridLayout(0, 1, 10, 10)); body.setOpaque(false)
body.add(label("POWER PLAY WEEKEND ? Score 30 runs", 16, WHITE))
body.add(label("WICKET HUNT ? Take 5 wickets", 16, WHITE))
body.add(label("WORLD XI CHALLENGE ? Win a match", 16, WHITE))
body.add(menuButton("BACK TO LOBBY", BLUE) { showPage("lobby") })
page.add(body, BorderLayout.CENTER); page
}
private def buildShopPage(): JPanel = {
val page = darkPanel(); page.setLayout(new BorderLayout(10, 10)); page.setBorder(BorderFactory.createEmptyBorder(20, 24, 20, 24))
page.add(titleBlock("GEAR & KIT SHOP", "CUSTOMIZE YOUR CRICKET LOOK"), BorderLayout.NORTH)
val body = new JPanel(new GridLayout(0, 1, 8, 8)); body.setOpaque(false)
val products = Vector(("Neon Bat Grip", 100), ("Gold Helmet Trim", 150), ("Blue Match Gloves", 120), ("Stadium Kit Skin", 200))
products.foreach { item =>
body.add(menuButton("BUY " + item._1 + " ? " + item._2 + " BUCKS", BLUE) {
if (bucks >= item._2) { bucks -= item._2; updateStats(); JOptionPane.showMessageDialog(this, item._1 + " unlocked!") }
else JOptionPane.showMessageDialog(this, "Not enough Bixuu Bucks.")
})
}
body.add(menuButton("BACK TO LOBBY", GREEN) { showPage("lobby") })
page.add(body, BorderLayout.CENTER); page
}
private def buildLeaderboardPage(): JPanel = {
val page = darkPanel(); page.setLayout(new BorderLayout(10, 10)); page.setBorder(BorderFactory.createEmptyBorder(20, 24, 20, 24))
page.add(titleBlock("LOCAL LEADERBOARD", "YOUR CRICKET RECORD"), BorderLayout.NORTH)
val info = label("PLAYER: " + playerName + " WINS: " + wins + " TROPHIES: " + trophies, 18, WHITE)
page.add(info, BorderLayout.CENTER)
page.add(menuButton("BACK TO LOBBY", BLUE) { showPage("lobby") }, BorderLayout.SOUTH)
page
}
def stadiumState: (Double, Boolean, Int) = (deliveryProgress, userBatting, balls)
}
class StadiumPanel(frame: CricketMainFrame) extends JPanel {
setPreferredSize(new Dimension(1100, 480))
setBackground(new Color(12, 24, 40))
override def paintComponent(graphics: Graphics): Unit = {
super.paintComponent(graphics)
val g = graphics.create().asInstanceOf[Graphics2D]
g.setRenderingHint(RenderingHints.KEY_ANTIALIASING, RenderingHints.VALUE_ANTIALIAS_ON)
val w = getWidth
val h = getHeight
g.setPaint(new GradientPaint(0, 0, new Color(12, 22, 48), 0, h, new Color(20, 92, 57)))
g.fillRect(0, 0, w, h)
g.setColor(new Color(34, 49, 73)); g.fillRect(0, 0, w, (h.toDouble * 0.27).toInt)
g.setColor(new Color(56, 72, 94))
var row = 0
while (row < 5) { g.drawLine(0, 28 + row * 17, w, 28 + row * 17); row += 1 }
g.setColor(new Color(31, 132, 74)); g.fillOval((w.toDouble * 0.10).toInt, (h.toDouble * 0.24).toInt, (w.toDouble * 0.80).toInt, (h.toDouble * 0.90).toInt)
g.setColor(new Color(75, 167, 95)); g.drawOval((w.toDouble * 0.16).toInt, (h.toDouble * 0.32).toInt, (w.toDouble * 0.68).toInt, (h.toDouble * 0.76).toInt)
val pitch = new java.awt.Polygon()
pitch.addPoint((w.toDouble * 0.44).toInt, (h.toDouble * 0.30).toInt)
pitch.addPoint((w.toDouble * 0.56).toInt, (h.toDouble * 0.30).toInt)
pitch.addPoint((w.toDouble * 0.62).toInt, (h.toDouble * 0.98).toInt)
pitch.addPoint((w.toDouble * 0.38).toInt, (h.toDouble * 0.98).toInt)
g.setColor(new Color(190, 155, 108)); g.fillPolygon(pitch)
drawCricketer(g, (w.toDouble * 0.50).toInt, (h.toDouble * 0.39).toInt, 0.82, BLUE, false)
drawCricketer(g, (w.toDouble * 0.50).toInt, (h.toDouble * 0.82).toInt, 1.12, new Color(32, 115, 208), true)
g.setColor(new Color(255, 238, 210)); g.setStroke(new java.awt.BasicStroke(4f))
val sx = (w.toDouble * 0.50).toInt; val sy = (h.toDouble * 0.88).toInt
g.drawLine(sx - 10, sy, sx - 10, sy - 28); g.drawLine(sx, sy, sx, sy - 28); g.drawLine(sx + 10, sy, sx + 10, sy - 28)
val state = frame.stadiumState
val progress = state._1
if (progress > 0.0 && progress < 1.0) {
val px = w.toDouble * 0.50 + Math.sin(progress * Math.PI) * 85.0
val py = h.toDouble * 0.40 + progress * h.toDouble * 0.38
val ballSize = (7 + progress * 8).toInt
g.setColor(new Color(220, 55, 65)); g.fillOval(px.toInt - ballSize / 2, py.toInt - ballSize / 2, ballSize, ballSize)
}
g.setColor(new Color(5, 14, 27, 180)); g.fillRoundRect(15, h - 45, 310, 30, 10, 10)
g.setColor(WHITE); g.setFont(new Font("SansSerif", Font.BOLD, 12)); g.drawString("BIXUU STADIUM ? LIVE MATCH", 28, h - 25)
g.dispose()
}
private def drawCricketer(g: Graphics2D, cx: Int, cy: Int, scale: Double, shirt: Color, hasBat: Boolean): Unit = {
val head = (18.0 * scale).toInt
g.setColor(new Color(0, 0, 0, 65)); g.fillOval(cx - 17, cy + (28 * scale).toInt, 34, 8)
g.setColor(new Color(27, 37, 53)); g.setStroke(new java.awt.BasicStroke((5.0 * scale).toFloat))
g.drawLine(cx - 5, cy + 10, cx - 9, cy + (28 * scale).toInt)
g.drawLine(cx + 5, cy + 10, cx + 9, cy + (28 * scale).toInt)
g.setColor(shirt); g.fillRoundRect(cx - (11 * scale).toInt, cy - 7, (22 * scale).toInt, (24 * scale).toInt, 7, 7)
g.setColor(new Color(191, 139, 105)); g.setStroke(new java.awt.BasicStroke((4.0 * scale).toFloat))
g.drawLine(cx - 10, cy, cx - 18, cy + 10); g.drawLine(cx + 10, cy, cx + 18, cy + 9)
g.setColor(new Color(187, 139, 105)); g.fillOval(cx - head / 2, cy - (25 * scale).toInt, head, (20 * scale).toInt)
g.setColor(new Color(24, 41, 69)); g.fillArc(cx - (12 * scale).toInt, cy - (28 * scale).toInt, (24 * scale).toInt, (14 * scale).toInt, 0, 180)
if (hasBat) { g.setColor(new Color(190, 137, 71)); g.setStroke(new java.awt.BasicStroke((5.0 * scale).toFloat)); g.drawLine(cx + 14, cy + 4, cx + 25, cy - 28) }
}
}
}
BixuuRealCricketPro_MainUI.main(Array[String]())