commit d9222f394aa033ea07c08689db32f8bdc3f387ae Author: Jonathan Bernard Date: Sat Jul 3 11:32:30 2010 -0500 Initial commit. diff --git a/.gitignore b/.gitignore new file mode 100644 index 0000000..8c94d06 --- /dev/null +++ b/.gitignore @@ -0,0 +1,2 @@ +build/ +*.sw* diff --git a/TeamMaker.groovy b/TeamMaker.groovy new file mode 100644 index 0000000..221dccd --- /dev/null +++ b/TeamMaker.groovy @@ -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() { + + } +} diff --git a/lib/groovy-all-1.7.2.jar b/lib/groovy-all-1.7.2.jar new file mode 100644 index 0000000..7b50f70 Binary files /dev/null and b/lib/groovy-all-1.7.2.jar differ diff --git a/lib/miglayout-3.7.1-swing.jar b/lib/miglayout-3.7.1-swing.jar new file mode 100644 index 0000000..5a762c8 Binary files /dev/null and b/lib/miglayout-3.7.1-swing.jar differ diff --git a/make_teams.groovy b/make_teams.groovy new file mode 100644 index 0000000..3d53747 --- /dev/null +++ b/make_teams.groovy @@ -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]}" +}*/ diff --git a/make_teams_simple.groovy b/make_teams_simple.groovy new file mode 100644 index 0000000..23c28c1 --- /dev/null +++ b/make_teams_simple.groovy @@ -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]}" +} diff --git a/make_teams_simple2.groovy b/make_teams_simple2.groovy new file mode 100644 index 0000000..5911de9 --- /dev/null +++ b/make_teams_simple2.groovy @@ -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() { + +}