Initial commit.

This commit is contained in:
Jonathan Bernard 2010-07-03 11:32:30 -05:00
commit d9222f394a
7 changed files with 323 additions and 0 deletions

2
.gitignore vendored Normal file
View File

@ -0,0 +1,2 @@
build/
*.sw*

107
TeamMaker.groovy Normal file
View File

@ -0,0 +1,107 @@
import groovy.swing.SwingBuilder
import java.awt.GridBagConstraints as GBC
import javax.swing.ListCellRenderer
public class TeamMaker {
/* ======== MODEL ======== */
public static def swing = new SwingBuilder()
public static final String version = "0.2"
def frame
def team1List
def team2List
def sittingList
class Player {
String name
int gamesSat
}
/* ======== VIEW ======== */
/*
+--------------------------------------------------+
| JDB TeamMaker v0.2 _[]X |
+--------------------------------------------------+
| |
| +-Current-Game--------------+ +-Sitting-Players+ |
| | | | | |
| | Team 1 Team 2 | | Jeptha 3 | |
| | Derrick Eric | | Jack 2 | |
| | Shane Brandon | | Sam 2 | |
| | Shane Darren | | Greg 2 | |
| | Christian Brett | | Frank 1 | |
| +---------------------------+ | Chris D 1 | |
| | Joshua 1 | |
| | | |
| | | |
| | | |
| | | |
| | | |
| +----------------+ |
+--------------------------------------------------+
*/
private void init() {
frame = swing.frame(title: "JDB TeamMaker v$version",
size: [600, 400], locationRelativeTo: null) {
panel() {
gridBagLayout()
panel(constraints: gbc(gridx: 0, gridy: 0,
insets: [5, 5, 5, 5]),
border: titleBorder(title: 'Current Game')) {
gridBagLayout()
label('Team A', constraints: gbc(gridx: 0, gridy: 0,
fill: GBC.BOTH, insets: [5, 5, 0, 0]))
label('Team B', constraints: gbc(gridx: 1, gridy: 0,
fill: GBC.BOTH, insets: [5, 5, 0, 5]))
def teamListRenderer = new PlayerRenderer(showStats: false
colored: false)
team1List = list(cellRenderer: teamListRenderer,
constraints: gbc(gridx: 0, gridy: 0, fill: GBC.BOTH,
insets: [5, 5, 5, 0], weightx: 2, weighty: 2))
team2List = list(cellRenderer: teamListRenderer,
constraints: gbc(gridx: 1, gridy: 1, fill: GBC.BOTH,
insets: [5, 5, 5, 5], weightx: 2, weighty: 2))
}
}
sittingList = list(
cellRenderer: new PlayerRenderer(
showStats: true, colored: true),
constraints: gbc(gridx: 1, gridy: 0, gridheight: 2) {
}
}
}
class PlayerRenderer implements ListCellRenderer extends JLabel {
boolean showStats
boolean colored
PlayerRenderer
}
/* ======== CONTROLLER ======== */
public static void main(String[] args) {
def inst = new TeamMaker()
inst.frame.show()
}
TeamMaker() {
}
}

BIN
lib/groovy-all-1.7.2.jar Normal file

Binary file not shown.

Binary file not shown.

94
make_teams.groovy Normal file
View File

@ -0,0 +1,94 @@
#!/usr/env groovy
import groovy.swing.SwingBuilder
import java.util.Random
import javax.swing.JFrame
import net.miginfocom.swing.MigLayout
Scanner sysin = new Scanner(System.in)
def version = "0.1"
def final teamNames = "ABCDEFGHIJKLMNOPQRSTUVWXYZ"
def swing = new SwingBuilder()
def allPlayers = []
def teams = [:]
def teamQueue = []
def rand = new Random(System.currentTimeMillis())
def go = true
def addPlayers
def makeTeams
def awardTeam1
def awardTeam2
/*/////// GUI Definitions \\\\\\\\*\
\*\\\\\\\ --------------- ////////*/
def frame = swing.frame(title: "JDB Team Maker v$version",
defaultCloseOperation: JFrame.EXIT_ON_CLOSE) {
//tabbedPane {
panel(layout: new MigLayout('insets 5 5 5 5', 'fill', '')) {
textArea(constraints: '')
button("Add Players", actionPerformed: { addPlayers() })
button("Make Team", actionPerformed: { makeTeams() })
button("Team 1 Wins", actionPerformed: { awardTeam1() })
button("Team 2 Wins", actionPerformed: { awardTeam2() })
}
//}
}
frame.pack()
def playersDialog = swing.dialog(title: "Manage Players",
layout: new MigLayout('insets 5 5 5 5', '', ''),
modal: true) {
scrollPane(constraints: '') {
playerList = list()
}
button("Add Players", constraints: '',
actionPerformed: { addPlayers() })
button("Make Team", constraints: '',
actionPerformed: { makeTeams() })
button("Done", constraints: '',
actionPerformed: { playersDialog.visible = false; })
}
playersDialog.pack()
// show main frame
frame.show()
/*/////// Action Methods \\\\\\\\*\
\*\\\\\\\ -------------- ////////*/
addPlayers = {
playersDialog.show()
}
makeTeams = {
}
/*while(true) {
print "Name: "
player = sysin.nextLine()
if (player == null || player == "DONE")
break
allPlayers << player
}
allPlayers.sort({ return rand.nextInt() })
println "\nTeam Assignments:"
println "-------------------"
for (int i = 0; i < allPlayers.size(); i++) {
if (i % teamSize == 0)
println "\nTeam ${++teamNum}"
println " ${allPlayers[i]}"
}*/

44
make_teams_simple.groovy Normal file
View File

@ -0,0 +1,44 @@
def allPlayers = []
def player
def teamSize
def badInput = true
Scanner sysin = new Scanner(System.in)
def rand = new Random(System.currentTimeMillis())
while(badInput) {
print "Enter team size: "
teamSize = sysin.nextLine()
badInput = !teamSize.isInteger()
}
teamSize = teamSize.toInteger()
// theoretically no point, but seems to make it more random
// we're choosing pickup teams, so appearence matters :)
(1.10000).each {rand.nextInt() }
while(true) {
print "Name: "
player = sysin.nextLine()
if (player == null || player == "DONE")
break
allPlayers << player
}
allPlayers.sort({ return rand.nextInt() })
println "\nTeam Assignments:"
println "-------------------"
def teamNum = 0
for (int i = 0; i < allPlayers.size(); i++) {
if (i % teamSize == 0)
println "\nTeam ${++teamNum}"
println " ${allPlayers[i]}"
}

76
make_teams_simple2.groovy Normal file
View File

@ -0,0 +1,76 @@
import java.util.Scanner
class Player {
def name
def gamesSat
}
class Team {
def name
def players
}
def teams = []
def players = [:]
def running = true
def choice
def version="0.1"
def sysin = new Scanner(System.in)
def options=[
ls: ["List Round Information", { list() }],
add: ["Add New Player", { add() }],
win: ["Report Game Result", { gameResult() }]
]
while (running) {
println "==>JDB Team Maker v${version}<=="
options.each { println "(${it[0]}) ${it[1]}" }
choice = sysin.nextLine()
if (options[(choice)])
options.each { opt ->
if (opt[0].toUpperCase().startsWith(choice.toUpperCase()))
opt[1]()
}
println ""
println ""
}
def list() {
println "Current Game:"
println "-------------"
println ""
println "\t${teams[0].name}"
println "\t${'-'.times(teams[0].name.length())}"
teams[0].players.each { println "\t\t$it" }
println ""
println "\t${teams[0].name}"
println "\t${'-'.times(teams[1].name.length())}"
teams[1].players.each { println "\t\t$it" }
println "Remaining Teams:"
println "----------------"
if (teams.length() < 2) return
teams[2..-1].each {
println ""
println "\t${it.name}"
println "\t${'-'.times(it.name.length())}"
it.players.each { println "\t\t$it" }
}
}
def add() {
}
def win() {
}