From 71676509f76dce5153744366a7d798702fa6157a Mon Sep 17 00:00:00 2001 From: Ryan Hope Date: Wed, 30 Apr 2008 10:30:05 -0400 Subject: [PATCH] sadjfda --- lab7/.classpath | 6 + lab7/.project | 17 + lab7/AddressScreen.class | Bin 0 -> 1383 bytes lab7/AddressScreen.java | 48 +++ lab7/AddressScreen.java,v | 70 ++++ lab7/DialogViewer.class | Bin 0 -> 1889 bytes lab7/DialogViewer.java | 70 ++++ lab7/DialogViewer.java,v | 92 +++++ lab7/LottoGUI.class | Bin 0 -> 1674 bytes lab7/LottoGUI.java | 65 ++++ lab7/LottoGUI.java,v | 87 +++++ project2/Frenzy.class | Bin 1309 -> 1437 bytes project2/Frenzy.java | 14 +- .../FrenzyController$PlayerControlsListener.class | Bin 3028 -> 3376 bytes project2/FrenzyController$QuitListener.class | Bin 773 -> 795 bytes project2/FrenzyController$ResetListener.class | Bin 638 -> 1265 bytes project2/FrenzyController$SpawnListener.class | Bin 2017 -> 783 bytes project2/FrenzyController.class | Bin 2336 -> 3642 bytes project2/FrenzyController.java | 398 +++++++++++++------ project2/FrenzyModel$Enemy.class | Bin 1178 -> 0 bytes project2/FrenzyModel$OCCUPANT.class | Bin 1066 -> 1066 bytes project2/FrenzyModel$Player.class | Bin 1306 -> 0 bytes project2/FrenzyModel.class | Bin 873 -> 1189 bytes project2/FrenzyModel.java | 356 ++++++----------- project2/FrenzyView$BoardSqaure.class | Bin 1130 -> 1399 bytes project2/FrenzyView.class | Bin 5274 -> 6069 bytes project2/FrenzyView.java | 172 ++++++++- project2/RCS/Frenzy.java,v | 55 ++- project2/RCS/FrenzyController.java,v | 426 ++++++++++++++++++--- project2/RCS/FrenzyModel.java,v | 137 +++++-- project2/RCS/FrenzyView.java,v | 257 +++++++++++-- project2/README-min | 3 + 32 files changed, 1768 insertions(+), 505 deletions(-) create mode 100644 lab7/.classpath create mode 100644 lab7/.project create mode 100644 lab7/AddressScreen.class create mode 100644 lab7/AddressScreen.java create mode 100644 lab7/AddressScreen.java,v create mode 100644 lab7/DialogViewer.class create mode 100644 lab7/DialogViewer.java create mode 100644 lab7/DialogViewer.java,v create mode 100644 lab7/LottoGUI.class create mode 100644 lab7/LottoGUI.java create mode 100644 lab7/LottoGUI.java,v rewrite project2/Frenzy.class (77%) rewrite project2/FrenzyController$PlayerControlsListener.class (85%) rewrite project2/FrenzyController$SpawnListener.class (83%) rewrite project2/FrenzyController.class (99%) delete mode 100644 project2/FrenzyModel$Enemy.class delete mode 100644 project2/FrenzyModel$Player.class rewrite project2/FrenzyModel.class (100%) rewrite project2/FrenzyModel.java (63%) rewrite project2/FrenzyView$BoardSqaure.class (86%) rewrite project2/FrenzyView.class (93%) diff --git a/lab7/.classpath b/lab7/.classpath new file mode 100644 index 0000000..233be1d --- /dev/null +++ b/lab7/.classpath @@ -0,0 +1,6 @@ + + + + + + diff --git a/lab7/.project b/lab7/.project new file mode 100644 index 0000000..79383f6 --- /dev/null +++ b/lab7/.project @@ -0,0 +1,17 @@ + + + lab7 + + + + + + org.eclipse.jdt.core.javabuilder + + + + + + org.eclipse.jdt.core.javanature + + diff --git a/lab7/AddressScreen.class b/lab7/AddressScreen.class new file mode 100644 index 0000000000000000000000000000000000000000..2a57fe0f7ca72e65e3052ad246ee60d7de607936 GIT binary patch literal 1383 zcwTK(-%}e^6#j0r*}c0>3tb3hOD&WZ-B4&KYSe(WC74PLP`gN6T6Gq3!L7+IZZ^`s z`{;k*TVM34GrlAPe}JwNU}fBy5^K7bqe+Q3_w z(Qt!fmg8-XcR1eVC~&;T@jk}~8j2iq22NvMnh!PHG|-0`1B3WTdTvQ`Tf>6%kW$IO z5EeCjY+zW%45F;zj)4)(aC{=qOB(JP7{#X=Dh4iNo?}^xtY}y@Fd;?mF{tx?;Kw%^ zQg&{gK`Dhb!O&On1F_O-Y>H^j+pLpEX?T9XFl0ZdJo3Kx@^vrR$vbi62Rm~z&~U<5 zv?a>EB%8NuwMaCZ&Q>Hua9svuU?a!Se>|9!SG)$rXa_Me2S0wokal7(CLp!p?~)~$ zvRw{q{x*T?qNodrno{s_zPU$Q`Mc#P(Hc0=8e0ms!>HlKei+CEKFi=f9ENO?g|`>y z7s99}qKfwuLJ%a~$ zNNqcUtck~Q*%x(LP)P)_h$QXH*R{*_aPLsNdH}srSZKv@7|0$GyE>T^ghO^woY1hnjaAsw?jk86?Qo87KJLqrY+_c(;IjyuY(8VD6 zvcOR>`C8*N;ADNRaUjJiq(W28J))GTekz*7Z1t7rLBj9OY&pDh}ab=kFy4#pEP zoy7hkG1a_6VpPM`U#Ue5*T}9TOST^h&S4xT3K+mGxqZlgpH@;8=kbtMl7NLKF5pMn zNI&5sexd)*a0wmSNPl1q&#C!;W1K0t!Z@x%#}uY}?Wdv0aR7Q36I92W)x*yl1c6AL LP7K$R$>sk8s~kJO literal 0 HcwPel00001 diff --git a/lab7/AddressScreen.java b/lab7/AddressScreen.java new file mode 100644 index 0000000..b38f99b --- /dev/null +++ b/lab7/AddressScreen.java @@ -0,0 +1,48 @@ +/* + * AddressScreen.java + * + * Version: + * $Id: AddressScreen.java,v 1.1 2008/04/30 14:28:49 rmh3093 Exp rmh3093 $ + * + * Revisions: + * $Log: AddressScreen.java,v $ + * Revision 1.1 2008/04/30 14:28:49 rmh3093 + * Initial revision + * + */ + +import java.awt.*; +import javax.swing.*; + +public class AddressScreen { + + public AddressScreen() { + String[] elements = {"Name","Address","City","State","Zip"}; + String[] buttons = {"Add","Modify","Delete"}; + JFrame mainFrame = new JFrame("Address Information"); + Container mainPane = mainFrame.getContentPane(); + mainPane.setLayout(new BorderLayout()); + mainFrame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE); + mainFrame.setVisible(true); + Container top = new Container(); + top.setLayout(new GridLayout(5,2)); + for (String s : elements) { + top.add(new JLabel(s)); + top.add(new JTextField()); + } + mainPane.add(top, BorderLayout.CENTER); + Container bottom = new Container(); + bottom.setLayout(new FlowLayout(FlowLayout.CENTER)); + for (String s : buttons) { bottom.add(new JButton(s)); } + mainPane.add(bottom, BorderLayout.SOUTH); + mainFrame.pack(); + } + + /** + * Main loop + */ + public static void main(String args[]) { + new AddressScreen(); + } + +} diff --git a/lab7/AddressScreen.java,v b/lab7/AddressScreen.java,v new file mode 100644 index 0000000..fd4f77e --- /dev/null +++ b/lab7/AddressScreen.java,v @@ -0,0 +1,70 @@ +head 1.1; +access; +symbols; +locks + rmh3093:1.1; strict; +comment @# @; + + +1.1 +date 2008.04.30.14.28.49; author rmh3093; state Exp; +branches; +next ; + + +desc +@initial commit +@ + + +1.1 +log +@Initial revision +@ +text +@/* + * AddressScreen.java + * + * Version: + * $Id$ + * + * Revisions: + * $Log$ + */ + +import java.awt.*; +import javax.swing.*; + +public class AddressScreen { + + public AddressScreen() { + String[] elements = {"Name","Address","City","State","Zip"}; + String[] buttons = {"Add","Modify","Delete"}; + JFrame mainFrame = new JFrame("Address Information"); + Container mainPane = mainFrame.getContentPane(); + mainPane.setLayout(new BorderLayout()); + mainFrame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE); + mainFrame.setVisible(true); + Container top = new Container(); + top.setLayout(new GridLayout(5,2)); + for (String s : elements) { + top.add(new JLabel(s)); + top.add(new JTextField()); + } + mainPane.add(top, BorderLayout.CENTER); + Container bottom = new Container(); + bottom.setLayout(new FlowLayout(FlowLayout.CENTER)); + for (String s : buttons) { bottom.add(new JButton(s)); } + mainPane.add(bottom, BorderLayout.SOUTH); + mainFrame.pack(); + } + + /** + * Main loop + */ + public static void main(String args[]) { + new AddressScreen(); + } + +} +@ diff --git a/lab7/DialogViewer.class b/lab7/DialogViewer.class new file mode 100644 index 0000000000000000000000000000000000000000..8ab13aceae205245ce32edf46c435c3310a6481b GIT binary patch literal 1889 zcwUuN-%}e^6#gy=-4K>vfkHtli&{-WA@qk>`5|Chgqj9~62(~T5^l(1vYXi~MP~Zw zyYGE)97m@!mKS{p9hvDL;2-7q-Cb&l1!qj=ZqB{;-0z(4JLhix{OgYw0Is2`p-Di$ zZJA|fCuhlh>1qfI#CFX`=C`TZzGd&E?yi`&EDLm)1fQJR~9^iT|}RT-iB0y zJsp?OFA(t@1}5)+BLu5NcmtO;3<`9gk*$t5F(jZ>)l%6er}*m-N|=s}Wy|bdWlOsE z&8;%?jb)sIS1llvFOEe`QxHtG;;tO1uwrtD$NT4~MPbYFwgpknj zE|Qcxp2%sqDsZWx&I?vqrb~`flWr6vNT^3j$2hJrgIdYiU#?0!NJOCTRPEDFrRvyz z&6m`n8#->{eUen=kY$Q1w-q>5e<>+tQ!AA71AM6A7Q68Dx{gUz42=L;vmzsyrrue{ zD00u(H)}?r#5C<;4J6ptz+$=TcPV=|iWwv#m=|c9ccpRQ>>0H^SI(;Sw2s@jBhaOI zr5(Fyxs{jH5@%9-y_phA5qv^5H)Jh>C4r`_6TzocK5g0sS&rZyJ972Fw2eil>Swd8 zV+Eg`M7<|#HFHP)@2Kipc?VUh*_2N+yeoNk1mm|VbqYZNd0R5)6_?EsF8bwYZ!89j zPza#ysC-Uhi1T59O??v#9fU&NGn=}-%ar$N$`Qqck#YMd>giC>`ocSJ_&Xs@HEj)C8}(gcIgsK48T zHoj$sY4rx)cnfd)Xzh3hSBNDPlK@j}(x;hwhsh(vM?yEB(f-+w3=}w4If@(#ufp-e zF-A6yFq$1r)-g6S_ym2UbzGkeGpGJ=9TUvxDIRhboAS-|W6bct>|{6@n|qFrX9j;& zx!gkVQ5gk8+2Mv_{1y zIKPi|Mz=71VvQ3!htH|l92Ne8vBHd%#+S&`YQa}{a8kcbzn(xm`6B!y29u%db!^g# s9Ygq&?IV<)qE!*zZK!OFNMOWHUg9CllF_`Mryk&;?AJ!X_D?u}13P%P&Hw-a literal 0 HcwPel00001 diff --git a/lab7/DialogViewer.java b/lab7/DialogViewer.java new file mode 100644 index 0000000..1c548d6 --- /dev/null +++ b/lab7/DialogViewer.java @@ -0,0 +1,70 @@ +/* + * DialogViewer.java + * + * Version: + * $Id: DialogViewer.java,v 1.1 2008/04/30 14:29:05 rmh3093 Exp rmh3093 $ + * + * Revisions: + * $Log: DialogViewer.java,v $ + * Revision 1.1 2008/04/30 14:29:05 rmh3093 + * Initial revision + * + */ + +import java.awt.*; +import java.awt.event.ActionEvent; +import java.io.File; + +import javax.swing.*; + +public class DialogViewer extends JPanel { + + public void actionPerformed(ActionEvent e) { + System.out.println(e.getSource().toString()); + } + + /** + * Create new DialogViewer + * @param type display type + */ + public DialogViewer(char[] type){ + int ret; + switch (type[0]) { + case 'f': + JFileChooser filechooser = new JFileChooser(); + ret = filechooser.showOpenDialog(DialogViewer.this); + if (ret == JFileChooser.APPROVE_OPTION) { + File file = filechooser.getSelectedFile(); + System.out.println(file.getName()); + } else { + System.out.println("No file was chosen!"); + } + break; + case 'c': + JOptionPane confirmation = new JOptionPane(); + ret = confirmation.showConfirmDialog(DialogViewer.this, + "Are you sure?"); + switch (ret) { + case 0: System.out.println("Yes"); break; + case 1: System.out.println("No"); break; + case 2: System.out.println("Cancel"); break; + } + break; + case 'm': + JOptionPane.showMessageDialog(DialogViewer.this, "Ryan Hope"); + break; + } + } + + /** + * Main loop + */ + public static void main(String args[]) { + if (args.length==1 && args[0].length()==1) { + new DialogViewer(args[0].toCharArray()); + } else { + System.out.println("Usage: java DialogViewer [f|c|m]"); + } + } + +} diff --git a/lab7/DialogViewer.java,v b/lab7/DialogViewer.java,v new file mode 100644 index 0000000..f1ad40a --- /dev/null +++ b/lab7/DialogViewer.java,v @@ -0,0 +1,92 @@ +head 1.1; +access; +symbols; +locks + rmh3093:1.1; strict; +comment @# @; + + +1.1 +date 2008.04.30.14.29.05; author rmh3093; state Exp; +branches; +next ; + + +desc +@initial commit +@ + + +1.1 +log +@Initial revision +@ +text +@/* + * DialogViewer.java + * + * Version: + * $Id$ + * + * Revisions: + * $Log$ + */ + +import java.awt.*; +import java.awt.event.ActionEvent; +import java.io.File; + +import javax.swing.*; + +public class DialogViewer extends JPanel { + + public void actionPerformed(ActionEvent e) { + System.out.println(e.getSource().toString()); + } + + /** + * Create new DialogViewer + * @@param type display type + */ + public DialogViewer(char[] type){ + int ret; + switch (type[0]) { + case 'f': + JFileChooser filechooser = new JFileChooser(); + ret = filechooser.showOpenDialog(DialogViewer.this); + if (ret == JFileChooser.APPROVE_OPTION) { + File file = filechooser.getSelectedFile(); + System.out.println(file.getName()); + } else { + System.out.println("No file was chosen!"); + } + break; + case 'c': + JOptionPane confirmation = new JOptionPane(); + ret = confirmation.showConfirmDialog(DialogViewer.this, + "Are you sure?"); + switch (ret) { + case 0: System.out.println("Yes"); break; + case 1: System.out.println("No"); break; + case 2: System.out.println("Cancel"); break; + } + break; + case 'm': + JOptionPane.showMessageDialog(DialogViewer.this, "Ryan Hope"); + break; + } + } + + /** + * Main loop + */ + public static void main(String args[]) { + if (args.length==1 && args[0].length()==1) { + new DialogViewer(args[0].toCharArray()); + } else { + System.out.println("Usage: java DialogViewer [f|c|m]"); + } + } + +} +@ diff --git a/lab7/LottoGUI.class b/lab7/LottoGUI.class new file mode 100644 index 0000000000000000000000000000000000000000..1df2bd0c8f8be00839621e4b279f34a45ecf4c46 GIT binary patch literal 1674 zcwTK(+fv(B6kP|)lB^gob_`KSQgSOY7#m!mDJE%(Db%UC1aqmA-h?e2fh{qz3~3+w z&}RD7r+xx6oj&))&eYR`OXjQcV^kT9np!b2j+ zNSIg9j}N)Cz|A6$`$$HXKOZRQ#m5|;l97|JBx6~@5cgL2b5+JeUT;l8UcoT0x6UBW znwII_WAJIQO$H%jmkfs9oM{=$_3F0atn1qqLWHVrS`7W#Gb3Oiu33*{*9ZZe$aj8^j1k8N&SiX|i@mA;|{|j$Y-=j9uN&7tJ9rf-^UQ z*u)k?)GMPOy2&})DH%>q|H`hrL41Nj5RdRUh)?m^aaNC(u`QQ+G#rM=3ApH(rB37s zK4%EM**%Rm@92jN{xzd!xa2;po9=OrlXmCo)SeZ@7uaCvd97x}c6jD5gV3=ZM3I{k zxL{jG&E@YqL6q@?l+GBI%ey-*L{8r}Dg>^Y#XSOs+N#$Qi3IJ*t%-4--K6eFU-wB6 zyI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U7L@T1 z@HTAt271FqT=Nyb%CMThF4}68Qfp}Irsa8;}(tpM-4{@#{|c$-#G)H^16gJN4Rwk zZoiYW-&MGIO$HCn;ke&5gVhVRO^!Ku{4TZdJ6jix{f-Pe=djQ3TrfQgcX=-K{*s}C zepi99r#v5ff2r67H98t=SYprD82AjY6v-cJ)(R1OV&TK6(lU^bE;u~-E#gCkrel|2 zUBuxv&tz~!*&fN@#Y}#OtjTLl?gjrh{O(J5d%O;6z@p2i21e263Xf(`I1YUc40zGo-njO037UxC1j{3+KCVT6E%!*nulN8kCNluqI1T9l delta 76 zcwU>$*2=cQi;ZcIhD{_F>SHv@6?35s@E)` zfE+`&)^yiYei)1@8Vs2$C>I+gO09a(!Lo2aJMNCyVCc_Pu5EHg*~Bt|yXe-?MI*Xg zoudc63^Cm>gy&^P83wLvGz=|JuU0XRG%_0c8Jf<8IRdXxoYo^#Ih#c}71{o6dD8~>U6R4{0dlkJVEQYqA^@D=9Z<6lwL9`gdFbOhC zOfoCJZPUp>0wZ{;ff`I*y}ER_Phdtt+rJ-f>J}nznG)(ht?L zwuD1k4t%Qq9%T(PMCW{*V-_DsY${3wJ)f4Oh;ir zZ=f%Z1Vx+38Y5pt68WKH@ca+7d=GMN({Cf?fOR27Hdi*?x`Q_QCqC#1D|`zpl=Da6 zKhYUIM&GG<{|Jv#Pfk!cbDu{}@G8tZ!dvo6XJ>P%3Z>T3y9pnx2TiOO-K-Bemc}^i iCoM7oqmEP5kdd+$u|%92upHF*gq46X&6?gw75E3@NHt0T delta 138 zcwYO+`HzL`)W2Q(7#J7~8RR!|IWbPIVGb8#XOLxN5O6C>&8w<(&d)0;%FoG3Et-6p zIfRK}!(>es`2bU(4kjRG+z4g}0!cOoMj*L~K?q2SK_nT38AKQuz$|eF2_VVDAPH74 S#UKr&xqu>!3^ELI3=9B@a1~hq diff --git a/project2/FrenzyController$SpawnListener.class b/project2/FrenzyController$SpawnListener.class dissimilarity index 83% index 8d77beff4e2acbc01ab726ea3492b82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Hs`Jor^HC^6d1KC6MUfR0Q^&0plsXR$9Ql1~P%8PW8Vaj$GZi>nM;&;RGHM2X~}`&?4)#tjmex;OUBL^xe>!L z)wyc)yVGVtJzG;Vc7Ao4`75hSs}8onhWe?aM?p%)^o{khV+-DxD)!MjznU556~W-G zssEi(dPP!?m^MYNWaNr!FPhW~)8-@k}Rykikt;_>ehDI-ebGFsD{b}ixQ0qw_7x4*ND zy9#bZPgnGZ@jbO`++oP$U@j zN3_Guxc_=2G(XW5yrYSTrhR??ulO>0(vjfZB|Nu?)Az8!Gc2K(Cq-x(eQ71rWtl>_!Xs^C%bOS^oNQjtJ+8 zki<1y;7&?m0+(rPsEBK00zQHJdrq{2OzhMl2;0FHYjeocoeB4Mu7$`A% zo+V_dFo$`-(-v52;c2&7Y#*8YiC6F{TcH!b<2ADOlTik5FkXP10(c8=^UgI-dxzQt z-{TG&BS^2kxC`~=w$Y4tsfC(Ccn|MaS_OM384Cesy5(E1lT>0n0!&J&+FL%pmiqq? gA5q2`XoemiQy-@MgmRqnQ%Xts8D$?o8lMCI0Z`jJnE(I) diff --git a/project2/FrenzyController.java b/project2/FrenzyController.java index 024a568..14c23f6 100644 --- a/project2/FrenzyController.java +++ b/project2/FrenzyController.java @@ -2,10 +2,13 @@ * FrenzyController.java * * Version: - * $Id: FrenzyController.java,v 1.1 2008/04/26 15:45:41 rmh3093 Exp rmh3093 $ + * $Id: FrenzyController.java,v 1.2 2008/04/30 04:10:52 rmh3093 Exp $ * * Revisions: * $Log: FrenzyController.java,v $ + * Revision 1.2 2008/04/30 04:10:52 rmh3093 + * break out random number generator, first attempt at moving enemies + * * Revision 1.1 2008/04/26 15:45:41 rmh3093 * Initial revision * @@ -40,62 +43,114 @@ SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. */ import java.awt.event.*; -import java.io.File; -import java.io.FileInputStream; -import java.io.FileNotFoundException; -import java.io.IOException; -import java.util.Random; +/** + * Controls the Frenzy view and updates the model + * + * @author Ryan Hope + */ public class FrenzyController { - protected FrenzyModel m_model; - protected FrenzyView m_view; - public Random rand; - private int boardsize = -1; - - FrenzyController(FrenzyModel model, FrenzyView view) { - m_model = model; - m_view = view; - boardsize = m_model.getBoardSize(); - - // Get better random numbers - File urandom = new File("/dev/urandom"); - byte[] seed = new byte[4]; - if (urandom.exists()) { - FileInputStream streamer = null; - try { - streamer = new FileInputStream(urandom); - } catch (FileNotFoundException e) { - e.printStackTrace(); - } - try { - streamer.read(seed); - } catch (IOException e) { - e.printStackTrace(); - } - int value = 0; - for (int i = 0; i < 4; i++) { - int shift = (4 - 1 - i) * 8; - value += (seed[i] & 0x000000FF) << shift; - } - rand = new Random(value); - } else { - rand = new Random(); - } + // Random number generator + private BetterRandom betterRandom; + + private FrenzyModel f_model; + private FrenzyView f_view; + + /** + * Create a new Frenzy Controller + * + * @param f_model the Frenzy game f_model + * @param f_view the Frenzy game f_view + */ + FrenzyController(FrenzyModel f_model, FrenzyView f_view, + BetterRandom betterRandom) { + this.f_model = f_model; + this.f_view = f_view; + this.betterRandom = betterRandom; // Add player to board in random position - m_model.player = m_model.new Player(rand.nextInt(model.getBoardSize()), - rand.nextInt(model.getBoardSize())); + f_model.player = new FrenzyPlayer( + betterRandom.rand.nextInt(f_model.boardsize), + betterRandom.rand.nextInt(f_model.boardsize)); + + // Add listeners to f_view + f_view.addQuitListener(new QuitListener()); + f_view.addResetListener(new ResetListener()); + f_view.addSpawnListener(new SpawnListener()); + f_view.addPauseListener(new PauseListener()); + f_view.addPlayerControlsListener(new PlayerControlsListener()); + f_view.addEnemySpawnListener(new SpawnListener()); + + } + + private synchronized void spawnEnemy() { + if (f_model.gamestate) { + // Can't spawn new enemies if there are no unique ASCII characters + if (f_model.enemyCount < FrenzyModel.MAX_ENIMES) { + + while (true) { + + int num = betterRandom.rand.nextInt(255); + + // These characters don't print + if (num < 33 || ((num > 126) && (num < 161)) || num == 173) + continue; + + // Can't use players symbol + if (String.valueOf((char)num) == FrenzyPlayer.symbol) + continue; + + // The symbol for the new enemy + String symbol = String.valueOf((char)num); + + // Check to make sure the symbol is already in use + if (f_model.enimies.containsKey(symbol)) continue; + + // Find a random unoccupied location for the enemy to spawn + int x = -1; + int y = -1; + while (true) { + x = betterRandom.rand.nextInt(f_model.getBoardSize()); + y = betterRandom.rand.nextInt(f_model.getBoardSize()); + if (f_view.boardSquares[y][x].isOccupied() == + FrenzyModel.OCCUPANT.NONE) { + break; + } + } - // Add listeners to view - view.addQuitListener(new QuitListener()); - view.addResetListener(new ResetListener()); - view.addSpawnListener(new SpawnListener()); - view.addPlayerControlsListener(new PlayerControlsListener()); + int move_x = betterRandom.rand.nextInt(2); + int move_y = betterRandom.rand.nextInt(2); + FrenzyEnemy.MOVEMENT_PATTERN mp = null; + // Spawn the new enemy + if ((move_x == 1) && (move_y == 1)) { + mp = FrenzyEnemy.MOVEMENT_PATTERN.NE; + } else if ((move_x == 1) && (move_y == 0)) { + mp = FrenzyEnemy.MOVEMENT_PATTERN.SE; + } else if ((move_x == 0) && (move_y == 1)) { + mp = FrenzyEnemy.MOVEMENT_PATTERN.NW; + } else if ((move_x == 0) && (move_y == 0)) { + mp = FrenzyEnemy.MOVEMENT_PATTERN.SW; + } + FrenzyEnemy enemy = + new FrenzyEnemy(f_model, x, y, symbol, mp, + new EnemyMover()); + f_model.enimies.put(symbol, enemy); + f_view.addOccupant(enemy, f_view.boardSquares[y][x]); + f_model.increaseEnemyCount(); + enemy.moverThread.start(); + break; + } - view.updateBoard(); + } + } } + /** + * Handles moving the Frenzy player around the game board + * + * @author Ryan Hope + */ class PlayerControlsListener implements KeyListener { public void keyPressed(KeyEvent e) { @@ -104,108 +159,201 @@ public class FrenzyController { public void keyTyped(KeyEvent e) { } + // Only perform an action on the release of the key public void keyReleased(KeyEvent e) { - int keycode = e.getKeyCode(); - int x_new = -1; - int y_new = -1; - int x_old = m_model.player.getXposition(); - int y_old = m_model.player.getYposition(); - if (keycode > 36 && keycode < 41) { - m_view.removeOccupant(m_view.boardSquares[y_old][x_old]); - switch (keycode) { - case 37: - if (x_old == 0) { - x_new = boardsize-1; - } else { - x_new = x_old-1; - } - y_new = y_old; - m_model.player.setXposition(x_new); - break; - case 38: - if (y_old == 0) { - y_new = boardsize-1; - } else { - y_new = y_old-1; - } - x_new = x_old; - m_model.player.setYposition(y_new); - break; - case 39: - if (x_old == boardsize-1) { - x_new = 0; - } else { - x_new = x_old+1; + + if (!f_view.pauseControl.isSelected()) { + + int keycode = e.getKeyCode(); + int x_new = -1; + int y_new = -1; + int x_old = f_model.player.getXposition(); + int y_old = f_model.player.getYposition(); + if ((keycode > 36 && keycode < 41) && f_model.gamestate) { + + // Remove player from current location + f_view.removeOccupant(f_view.boardSquares[y_old][x_old]); + + switch (keycode) { + + // Move left + case 37: + if (x_old == 0) { + x_new = f_model.boardsize-1; + } else { + x_new = x_old-1; + } + y_new = y_old; + f_model.player.setXposition(x_new); + break; + + // Move up + case 38: + if (y_old == 0) { + y_new = f_model.boardsize-1; + } else { + y_new = y_old-1; + } + x_new = x_old; + f_model.player.setYposition(y_new); + break; + + // Move right + case 39: + if (x_old == f_model.boardsize-1) { + x_new = 0; + } else { + x_new = x_old+1; + } + y_new = y_old; + f_model.player.setXposition(x_new); + break; + + // Move down + case 40: + if (y_old == f_model.boardsize-1) { + y_new = 0; + } else { + y_new = y_old+1; + } + x_new = x_old; + f_model.player.setYposition(y_new); + break; } - y_new = y_old; - m_model.player.setXposition(x_new); - break; - case 40: - if (y_old == boardsize-1) { - y_new = 0; - } else { - y_new = y_old+1; + + // If new location is occupied by an enemy, eat it + if (f_view.boardSquares[y_new][x_new].isOccupied() == + FrenzyModel.OCCUPANT.ENEMY) { + + // Eat enemy + String key = + f_view.boardSquares[y_new][x_new].getText(); + f_model.player.eatEnemy(); + f_model.decreaseEnemyCount(); + if (f_model.player.getConsumedCount() > 0 && + f_model.enemyCount==0) { + f_model.gamestate = false; + f_view.statusLabel.setText("Game over."); + } + + // Remove key from list so that the symbol can be reused + f_model.enimies.remove(key); + + // ==================================================== + // These should be handled by events + + // Update the last action display + f_view.lastActionLabel.setText( + f_model.player.getSymbol() + " ate " + key); + + // Update the consumed enemy count display + int count = f_model.player.getConsumedCount(); + f_view.consumedLabel.setText(String.valueOf(count)); + + // ==================================================== } - x_new = x_old; - m_model.player.setYposition(y_new); - break; - } - if (m_view.boardSquares[y_new][x_new].isOccupied() == - FrenzyModel.OCCUPANT.ENEMY) { - String key = m_view.boardSquares[y_new][x_new].getText(); - m_model.player.eatEnimie(); - m_model.enimies.remove(key); - m_view.lastActionLabel.setText(m_model.player.getSymbol() + - " ate " + key); - int count = m_model.player.getConsumedCount(); - m_view.consumedLabel.setText(String.valueOf(count)); + + // Add player to new square + f_view.addOccupant(f_model.player, + f_view.boardSquares[y_new][x_new]); } - m_view.addOccupant(m_model.player, - m_view.boardSquares[y_new][x_new]); } } } + /** + * Handles quitting Frenzy + * + * @author Ryan Hope + */ class QuitListener implements ActionListener { public void actionPerformed(ActionEvent e) { - m_view.dispose(); + f_view.dispose(); System.exit(0); } } + /** + * Handles resetting Frenzy + * + * @author Ryan Hope + */ class ResetListener implements ActionListener { public void actionPerformed(ActionEvent e) { + f_model.gamestate = true; + f_view.statusLabel.setText("Game Running!"); + f_view.pauseControl.setSelected(false); + f_model.player.setConsumedCount(0); + f_view.consumedLabel.setText("0"); } } + /** + * Handles resetting Frenzy + * + * @author Ryan Hope + */ + class PauseListener implements ActionListener { + public void actionPerformed(ActionEvent e) { + if (f_view.pauseControl.isSelected()) { + f_model.gamestate = false; + f_view.statusLabel.setText("Game Paused!"); + } else { + f_model.gamestate = true; + f_view.statusLabel.setText("Game Running!"); + } + } + } + + /** + * Handles spawning of new enemies + * + * @author Ryan Hope + */ class SpawnListener implements ActionListener { + public void actionPerformed(ActionEvent e) { - if (m_model.enimieCount <= FrenzyModel.MAX_ENIMES) { - while (true) { - int num = rand.nextInt(127); - if (num < 33) continue; - if ((char)num == 'P') continue; - String symbol = String.valueOf((char)num); - if (m_model.enimies.containsKey(symbol)) continue; - int x = -1; - int y = -1; - while (true) { - x = rand.nextInt(m_model.getBoardSize()); - y = rand.nextInt(m_model.getBoardSize()); - if (m_view.boardSquares[y][x].isOccupied() == - FrenzyModel.OCCUPANT.NONE) { - break; - } + if (f_model.gamestate) spawnEnemy(); + } + + } + + /** + * Handles moving enemies + * + * @author Ryan Hope + */ + class EnemyMover { + + public void move(String symbol) { + FrenzyEnemy enemy = f_model.enimies.get(symbol); + FrenzyEnemy eaten = null; + if (enemy != null) { + int x = enemy.getXposition(); + int y = enemy.getYposition(); + FrenzyModel.OCCUPANT occupant_t = + f_view.boardSquares[y][x].isOccupied(); + if (occupant_t != FrenzyModel.OCCUPANT.NONE) { + String occupant = f_view.boardSquares[y][x].getText(); + if (occupant_t == FrenzyModel.OCCUPANT.PLAYER) { + f_model.gamestate = false; + f_model.player.died = true; + f_view.statusLabel.setText("Game over."); } - FrenzyModel.Enemy enemy = - m_model.new Enemy(x, y, symbol); - m_model.enimies.put(symbol, enemy); - m_view.addOccupant(enemy, m_view.boardSquares[y][x]); - m_model.enimieCount++; - break; + eaten = f_model.enimies.get(occupant); + eaten.move = false; + f_view.lastActionLabel.setText( + symbol + " ate " + occupant); } + while (eaten != null && eaten.moverThread.isAlive()) { + Thread.yield(); + } + f_view.removeOccupant( + f_view.boardSquares[enemy.Yposition_old][enemy.Xposition_old]); + f_view.addOccupant(enemy, f_view.boardSquares[y][x]); } } + } } \ No newline at end of file diff --git a/project2/FrenzyModel$Enemy.class b/project2/FrenzyModel$Enemy.class deleted file mode 100644 index 42d2b1178ab6e6b570774ec3b0fb05e1f5e2493f..0000000000000000000000000000000000000000 GIT binary patch literal 0 HcwPel00001 literal 1178 zcwTi<%Wl&^6g}fOHcnlVz5;!u4=~`k(6qn`5SxlhkwRGnMX+>&6a^C_ndR@Ju_eaefS7q54TlF408vedvPlz3s#!yo^~Uro2yC4b+1U73Uc8HP?3zk2_5#d~7#8hj$RP zY_DO5F5f4IGOxn0P@9@4sWj+_i(k;8adABwYe6=vWB`rW^cMf?at>T>P+_Ff4lhG+dMr+o3kNg_}pQEoL4nJXDfCT^xSOotqrIL%2 zs+=@amA9z9sVg=Ydx4&sRzqimV3B9 ztgO-~b16g|@!`uTub5D_TyrE~_N2!3PSG?LU*CBYEc7^dX~2d6V;W@=L7PM0qI z*tt_TE;ON-xbO$~qm1{xPTHZ?CiC9C^X@tCoO>tz{paT|0GF_lKukey)8o#I<~?_x z+Y4K^+2mdVnu6@1`P?kprgKnyP(9?eKtbGZ)~l{fm`e9>JMb*$U_-%R$#wj|bb=kz zZtx^h3Y0AcsYlOT-wG_(p}b7_ZZ}WX2-2wYec}$DSpLE)(NrRWh?X7jAVQ%QbRyA8 zbee*KQHC@!3Wh6|!|ylhRqj1Bt2P%J-I{6dn4Tr_@TDehAynmG)8SPeb%K48feCiz zpU|Kc%KA?GZNyB9(A!~yMhkks7R7H_juqS{afK5u%fu({TVNQ%a2hHuFwA06+Lb3d z!vNwUT4ESPCQZ>Y!xZu&Dl$wXPctJ4rLd(Xx8cytQrrygI9A=FcCF(|0+$tJB6l-f z6%I38)`Xz+w%hP(eA5y=%SNhKgeh`fb{y`NY}5BSwKLxCAZAF4N}tvMazZU-3Cdzf z(nC{{F$?!Wv1hZwFXc&kvN%PE97RRi6~SX1VdSeUKTT^~zI=)?T3NdQXD|-&JKGmL z(F+dxf~kuk_$F1yM71&5!pQd?^h=2zYgcs8ap_H*Pxt4U=;e9+A08I+oRggtJjL-HnKMeUHxVlITfqH2wH-B@a2-uQv@MlRVx!HAJFu}m0h3x+XujEhG87%N?s zb8;RZs6%g&!eg4y9!6nOlWXMh9p>>~UOpqIt#>ZhWhY`X5?)l2vf6hrM(xv(eqCSz7&&2a3!aE-F#&Aup*KvdPw3M|@ GBg0=lV$0e9 diff --git a/project2/FrenzyModel.class b/project2/FrenzyModel.class dissimilarity index 100% index 98cc24466504192e12edd6250135436e0f29c7f7..553d134ebc6871f0606c54b92acd39e1aad9f3b0 100644 GIT binary patch literal 1189 zcwTi=>rN9v6#k|y6x!v|f&u~xhyp88MZAIrXi98s3$e8U@6&dyi`!YU-D2Q5d<_4X z&|oC-0emRqnQ5gpV3VD5nKR#azH`!FzkmD$a2t<<@G*opTpkkULg&$44VSBNyEV);632EtU#Y(ExT-I|fSzc~3B&4VuEI%QL zPuPpCqu;>mFtlafU3bDJTelWAvP zv~t~LUJ-=lDUmNpn}zl~-=4S?X2QVKV2^J-O8gCO$3wxa3Hc>KlIS|-QP_1DED=~O%HhEK_c z`jKclsdI$1r2*2}L%t8a7(pN16Tgll2&l2@cLPm3*nCd|B^#h`2*VVQkoSey6yKtG zj7#PT#&?c!rH%>HU&oXg34gC++Kl+N>$t8`v*vsqra4;2{5Q?FK&PqudPT^q)bkqk z^OQKBVH6omA%_{f#ysB8|M4wiR5{UL#4XA|dy86u@|0#Dd3UhX>@Y@F-F28pnE!f8 z+NqNtG@#KaXaY{-F2t<8 delta 514 zcwSA9&q@MO6vn?hCEVQaJNKOXJKufu{K(4Z@7o7}JT@&wv(96_;PFArFz-4i z&1<8cw%P@@V?AZ%Vfm$PUov4y>o2TzW{jWMnifle=Z0V-k`r#^#^*As9#!MF$g zBS4)ga#uuiZl?7E9GM*tSFG+dY?b#5g66?4!3Xg*fN8Rw{ji6KY8GCwoWI8%g9{Ve%a(%fDY I>!cgNAKns3l>h($ diff --git a/project2/FrenzyModel.java b/project2/FrenzyModel.java dissimilarity index 63% index 12f5338..f1538aa 100644 --- a/project2/FrenzyModel.java +++ b/project2/FrenzyModel.java @@ -1,243 +1,113 @@ -/* - * FrenzyModel.java - * - * Version: - * $Id: FrenzyModel.java,v 1.1 2008/04/26 15:46:05 rmh3093 Exp rmh3093 $ - * - * Revisions: - * $Log: FrenzyModel.java,v $ - * Revision 1.1 2008/04/26 15:46:05 rmh3093 - * Initial revision - * - */ - -/* -Copyright (c) 2008, Ryan M. Hope -All rights reserved. - -Redistribution and use in source and binary forms, with or without modification, -are permitted provided that the following conditions are met: - - * Redistributions of source code must retain the above copyright notice, - this list of conditions and the following disclaimer. - * Redistributions in binary form must reproduce the above copyright notice, - this list of conditions and the following disclaimer in the documentation - and/or other materials provided with the distribution. - * Neither the name of the project nor the names of its contributors may be - used to endorse or promote products derived from this software without - specific prior written permission. - -THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND -ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED -WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE -DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE FOR -ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES -(INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; -LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON -ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT -(INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS -SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. - */ - -import java.util.TreeMap; - -public class FrenzyModel { - - // The number of rows and columns for the current game - private int boardsize; - - // The player - public Player player; - - // The enemies - public TreeMap enimies = - new TreeMap(); - - // Valid 'printable' ASCII characters start at 33 and go to 126 which only - // leaves 92 unique enemy symbols... therefore only 92 enemies can be - // active at any one time - public static final int MAX_ENIMES = 92; - - // The number of active enemies - protected int enimieCount = 0; - - // The possible occupants of a board square - static enum OCCUPANT {NONE,PLAYER,ENEMY}; - - /** - * Create a new Frenzy model - * - * @param boardSize number of rows and columns - */ - FrenzyModel(int boardSize) { - this.boardsize = boardSize; - } - - /** - * Returns the number of rows and columns for the current game - * - * @return number of rows and columns - */ - int getBoardSize() { - return boardsize; - } - - /** - * Frenzy Player Class - * - * @author Ryan Hope - * - */ - class Player { - - // Player symbol - private final String symbol = "P"; - // Player's location - private int Xposition = -1; - private int Yposition = -1; - // Count of what player has consumed - private int consumed = 0; - - /** - * Returns the column in the game board corresponding to the player's - * location - * - * @return column in game board - */ - int getXposition() { return Xposition; } - - - /** - * Returns the row in the game board corresponding to the player's - * location - * - * @return row in game board - */ - int getYposition() { return Yposition; } - - - /** - * Set the column of the player's location on the game board - * - * @param Xposition column in game board - */ - void setXposition(int Xposition) { this.Xposition = Xposition; } - - - /** - * Set the row of the player's location on the game board - * - * @param Yposition row in game board - */ - void setYposition(int Yposition) { this.Yposition = Yposition; } - - - /** - * Returns the players symbol - * - * @return player's symbol - */ - String getSymbol() { return symbol; } - - /** - * Create a new player - * - * @param Xposition initial column of player - * @param Yposition initial row of player - */ - Player(int Xposition, int Yposition) { - setXposition(Xposition); - setYposition(Yposition); - } - - /** - * Returns the number of consumed enemies - * - * @return count of consumed enemies - */ - public int getConsumedCount() { return consumed; } - - /** - * Eat enemy, increase consumed enemy count, decrease active enemy - * count - */ - public void eatEnimie() { - consumed++; - enimieCount--; - } - } - - /** - * A representation of the computer controlled enemies - * - * @author Ryan Hope - * - */ - class Enemy { - - // Symbol of enemy - private String symbol; - - // Enemy's location - private int Xposition = -1; - private int Yposition = -1; - - /** - * Returns the column in the game board corresponding to the enemy's - * location - * - * @return column in game board - */ - int getXposition() { return Xposition; } - - /** - * Returns the row in the game board corresponding to the enemy's - * location - * - * @return row in game board - */ - int getYposition() { return Yposition; } - - /** - * Set the column of the enemy's location on the game board - * - * @param Xposition column in game board - */ - void setXposition(int Xposition) { this.Xposition = Xposition; } - - /** - * Set the row of the enemy's location on the game board - * - * @param Yposition row in game board - */ - void setYposition(int Yposition) { this.Yposition = Yposition; } - - /** - * Returns the enemy's symbol - * - * @return enemy's symbol - */ - String getSymbol() { return symbol; } - - /** - * Sets the enemy's symbol - * - * @param symbol symbol of enemy - */ - void setSymbol(String symbol) { this.symbol = symbol; } - - /** - * Create a new enemy - * - * @param Xposition starting column on game board - * @param Yposition starting row on game board - * @param symbol symbol of enemy - */ - Enemy(int Xposition, int Yposition, String symbol) { - setXposition(Xposition); - setYposition(Yposition); - setSymbol(symbol); - } - } - -} +/* + * FrenzyModel.java + * + * Version: + * $Id: FrenzyModel.java,v 1.2 2008/04/30 04:11:55 rmh3093 Exp $ + * + * Revisions: + * $Log: FrenzyModel.java,v $ + * Revision 1.2 2008/04/30 04:11:55 rmh3093 + * break out Player and Enemy class, other changes + * + * Revision 1.1 2008/04/26 15:46:05 rmh3093 + * Initial revision + * + */ + +/* +Copyright (c) 2008, Ryan M. Hope +All rights reserved. + +Redistribution and use in source and binary forms, with or without modification, +are permitted provided that the following conditions are met: + + * Redistributions of source code must retain the above copyright notice, + this list of conditions and the following disclaimer. + * Redistributions in binary form must reproduce the above copyright notice, + this list of conditions and the following disclaimer in the documentation + and/or other materials provided with the distribution. + * Neither the name of the project nor the names of its contributors may be + used to endorse or promote products derived from this software without + specific prior written permission. + +THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND +ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED +WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE +DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE FOR +ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES +(INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; +LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON +ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT +(INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS +SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. + */ + +import java.util.TreeMap; + +/** + * Stores all the data and important generic aspects of the game Frenzy + * + * @author Ryan Hope + */ +public class FrenzyModel { + + // Random number generator + private BetterRandom betterRandom; + + // The number of rows and columns for the current game + int boardsize; + + // The player + public FrenzyPlayer player; + + // The enemies + public TreeMap enimies = + new TreeMap(); + + // Valid 'printable' ASCII characters start at 1 and go to 254, if you + // subtract the non-printing characters, there are 187 unique characters + public static final int MAX_ENIMES = 187; + + // The number of active enemies + protected int enemyCount = 0; + + // The interval in ms to spawn enemies + int enemySpawnInterval = 3000; + + // The interval in ms to spawn enemies + int enemyMoveInterval = 600; + + // The possible occupants of a board square + static enum OCCUPANT {NONE,PLAYER,ENEMY}; + + // Game state + public boolean gamestate = false; + + /** + * Create a new Frenzy model + * + * @param boardSize number of rows and columns + */ + FrenzyModel(int boardSize, BetterRandom betterRandom) { + this.betterRandom = betterRandom; + this.boardsize = boardSize; + } + + /** + * Returns the number of rows and columns for the current game + * + * @return number of rows and columns + */ + int getBoardSize() { + return boardsize; + } + + protected synchronized void decreaseEnemyCount() { + enemyCount--; + } + + protected synchronized void increaseEnemyCount() { + enemyCount++; + } + +} diff --git a/project2/FrenzyView$BoardSqaure.class b/project2/FrenzyView$BoardSqaure.class dissimilarity index 86% index 051e1c5fac2ca48d49d463e1834dc07fa95be309..b351db1b8bf384a581544ea644a933fc7b56b677 100644 GIT binary patch literal 1399 zcwTK(?Q+vb6g?X|QDU~lm^2B{QrenUaSEp8qtE~)F?MSzI|dt5Q@#{?;|LU~NOA)_ zMjwEm@E0vqSDn!f7?0!d3(W$mpf zo70gcfr)6t3Df6TYVD!x_*KVqqU!?F=4fJ}E)dW8Ej0y!k0cCCCJ@84#1xVOF>|4w zU?wGT6f*=3RaEesozPx$6?dBV`}tXkIm{EGt)dmX`K%rI9k0cG=E8o7n&`O1I3^5y zLOH{9(Ia@6zzLkx?4Jo3W|2>y;d6;E@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unYta9tKED`@5PnsSzM)F!VdL1*Wbi7>K$C?a^ZTH4>!2VaHFdVH@WI@ zv+E?>;yMkty7&%tt;X%HPSTsm%V3x5Qrzj;W3v!^Zhwfw9U_W0m+L{$v@e95wc5W^$x;x~y(jULU-ert0hW z<87Lt<$sKClMm6ay)^kS=ld*E(`?aEQ{|QcG4-#}-fU7<910P(>HYY34(~1;CI7c* zge^5t-B{I_Qy6b|klj8hPnw%qgL-jf3 z&1(->++jBM#|uv59X*X#O;GZ*hAQO)#@5yB=qi<_;cKMAiQ^SM#qsF^g{7kkOI4Yg zVkrz3SLiLO@EMNJ9!6ogqi||*h3=vXpXd0(VH8$~!ZN>_#`?Au9?elwS|XX+JF3cS kF;5)5E?sJd^ 0) { - if (getText() == m_model.player.getSymbol()) { + if (getText() == FrenzyPlayer.symbol) { ret = FrenzyModel.OCCUPANT.PLAYER; } else { ret = FrenzyModel.OCCUPANT.ENEMY; @@ -73,6 +115,7 @@ public class FrenzyView extends JFrame { } + // The label of the game control buttons private static final String[] buttonLables = { "Pause","Spawn","++","--","Restart","Quit" }; @@ -86,7 +129,7 @@ public class FrenzyView extends JFrame { JCheckBox pauseControl = new JCheckBox(); JButton[] controlButtons = new JButton[5]; JLabel consumptionLabel = new JLabel("Consumption"); - JLabel pieceLabel = new JLabel("Piece is P"); + JLabel pieceLabel = new JLabel("Piece is "); JLabel consumedLabel = new JLabel("0"); JLabel statusLabel = new JLabel("Game Running!"); JLabel lastActionLabel = new JLabel("S ate K"); @@ -95,14 +138,22 @@ public class FrenzyView extends JFrame { TitledBorder boardContainerBoarder; Border standardBoarder; - FrenzyView(FrenzyModel model) { - m_model = model; + /** + * Create a new view + * + * @param f_model Frenzy f_model of important game data + */ + FrenzyView(FrenzyModel f_model, BetterRandom betterRandom) { + this.f_model = f_model; + this.betterRandom = betterRandom; - // Set some basics + // Set some basics settings setTitle("Frenzy"); setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE); standardBoarder = BorderFactory.createTitledBorder(""); + pauseControl.setSelected(false); setFocusable(true); + setResizable(false); // Setup view ==================================================== mainPane.setLayout(new BorderLayout()); @@ -141,7 +192,7 @@ public class FrenzyView extends JFrame { mainPane.add(infoContainer, BorderLayout.NORTH); // Game board - int boardsize = model.getBoardSize(); + int boardsize = f_model.getBoardSize(); boardContainerBoarder = BorderFactory.createTitledBorder("Game Board"); gameboard.setBorder(boardContainerBoarder); gameboard.setLayout(new GridLayout(boardsize, boardsize)); @@ -156,47 +207,134 @@ public class FrenzyView extends JFrame { mainPane.add(gameboard, BorderLayout.CENTER); this.pack(); - int width = mainPane.getWidth() + 75; - setSize(width, width); - + + setVisible(true); + } + + /** + * Start game + */ + protected void start() { + pieceLabel.setText("Piece is " + f_model.player.getSymbol()); + spawnPlayer(); + f_model.gamestate = true; + enemySpawnerThread.start(); + } + + class EnemySpawner implements Runnable { - public void addOccupant(FrenzyModel.Player player, BoardSqaure location) { + public void run() { + try { + try { + Thread.sleep(f_model.enemySpawnInterval); + } catch (InterruptedException e) { + } + while (true) { + enemySpawner.actionPerformed(new ActionEvent(this, + ActionEvent.ACTION_PERFORMED, "spawn")); + Thread.sleep(f_model.enemySpawnInterval); + } + } catch (InterruptedException e) { + } + } + + } + + /** + * Add a player to a board square + * + * @param player the player + * @param location the board square to move to + */ + public void addOccupant(FrenzyPlayer player, BoardSqaure location) { location.setText(player.getSymbol()); location.setBackground(new Color(255,255,0)); } - public void addOccupant(FrenzyModel.Enemy enemy, BoardSqaure location) { + /** + * Add an enemy to a board square + * + * @param enemy the enemy + * @param location the board square to move to + */ + public void addOccupant(FrenzyEnemy enemy, BoardSqaure location) { location.setText(enemy.getSymbol()); location.setBackground(new Color(0,255,0)); } + /** + * Remove occupant from board square + * + * @param location board square to remove occupant from + */ public void removeOccupant(BoardSqaure location) { location.setText(""); location.setBackground(location.defaultcolor); location.repaint(); } - void updateBoard() { - int px = m_model.player.getXposition(); - int py = m_model.player.getYposition(); - addOccupant(m_model.player, boardSquares[py][px]); + /** + * Spawn the player + */ + void spawnPlayer() { + int px = f_model.player.getXposition(); + int py = f_model.player.getYposition(); + addOccupant(f_model.player, boardSquares[py][px]); } + /** + * Register a player controls handler + * + * @param pc player controls handler + */ void addPlayerControlsListener(KeyListener pc) { this.addKeyListener(pc); } + /** + * Register a quit handler + * + * @param quit quit handler + */ void addQuitListener(ActionListener quit) { controlButtons[4].addActionListener(quit); } + /** + * Register a reset handler + * + * @param reset + */ void addResetListener(ActionListener reset) { controlButtons[3].addActionListener(reset); } + /** + * Register a spawn handler + * + * @param spawn + */ void addSpawnListener(ActionListener spawn) { controlButtons[0].addActionListener(spawn); } + /** + * Register a pause handler + * + * @param pause + */ + void addPauseListener(ActionListener pause) { + pauseControl.addActionListener(pause); + } + + /** + * Register an enemy spawn handler + * + * @param spawn + */ + void addEnemySpawnListener(ActionListener spawn) { + enemySpawner = spawn; + } + } diff --git a/project2/RCS/Frenzy.java,v b/project2/RCS/Frenzy.java,v index 9f07584..81bc3b5 100644 --- a/project2/RCS/Frenzy.java,v +++ b/project2/RCS/Frenzy.java,v @@ -1,11 +1,15 @@ -head 1.1; +head 1.2; access; symbols; -locks - rmh3093:1.1; strict; +locks; strict; comment @# @; +1.2 +date 2008.04.30.04.13.28; author rmh3093; state Exp; +branches; +next 1.1; + 1.1 date 2008.04.26.15.45.05; author rmh3093; state Exp; branches; @@ -17,19 +21,22 @@ desc @ -1.1 +1.2 log -@Initial revision +@first attempt at moving enemies, eating player don't work 100% @ text @/* * Frenzy.java * * Version: - * $Id$ + * $Id: Frenzy.java,v 1.1 2008/04/26 15:45:05 rmh3093 Exp rmh3093 $ * * Revisions: - * $Log$ + * $Log: Frenzy.java,v $ + * Revision 1.1 2008/04/26 15:45:05 rmh3093 + * Initial revision + * */ /* @@ -70,7 +77,7 @@ SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. * the computer. Enemies may be created by the player using a button, and/or * created at regular time intervals by the computer. * - * @@author rmh3093 + * @@author Ryan Hope * */ public class Frenzy { @@ -84,10 +91,11 @@ public class Frenzy { * Create new Frenzy game */ public Frenzy(int boardSize) { - FrenzyModel model = new FrenzyModel(boardSize); - FrenzyView view = new FrenzyView(model); - new FrenzyController(model, view); - view.setVisible(true); + BetterRandom betterRandom = new BetterRandom(); + FrenzyModel f_model = new FrenzyModel(boardSize, betterRandom); + FrenzyView f_view = new FrenzyView(f_model, betterRandom); + new FrenzyController(f_model, f_view, betterRandom); + f_view.start(); } /** @@ -114,3 +122,26 @@ public class Frenzy { } @ + + +1.1 +log +@Initial revision +@ +text +@d5 1 +a5 1 + * $Id$ +d8 4 +a11 1 + * $Log$ +d52 1 +a52 1 + * @@author rmh3093 +d66 5 +a70 4 + FrenzyModel model = new FrenzyModel(boardSize); + FrenzyView view = new FrenzyView(model); + new FrenzyController(model, view); + view.setVisible(true); +@ diff --git a/project2/RCS/FrenzyController.java,v b/project2/RCS/FrenzyController.java,v index 90a09f3..0083e23 100644 --- a/project2/RCS/FrenzyController.java,v +++ b/project2/RCS/FrenzyController.java,v @@ -1,11 +1,15 @@ -head 1.1; +head 1.2; access; symbols; -locks - rmh3093:1.1; strict; +locks; strict; comment @# @; +1.2 +date 2008.04.30.04.10.52; author rmh3093; state Exp; +branches; +next 1.1; + 1.1 date 2008.04.26.15.45.41; author rmh3093; state Exp; branches; @@ -17,19 +21,22 @@ desc @ -1.1 +1.2 log -@Initial revision +@break out random number generator, first attempt at moving enemies @ text @/* * FrenzyController.java * * Version: - * $Id$ + * $Id: FrenzyController.java,v 1.1 2008/04/26 15:45:41 rmh3093 Exp rmh3093 $ * * Revisions: - * $Log$ + * $Log: FrenzyController.java,v $ + * Revision 1.1 2008/04/26 15:45:41 rmh3093 + * Initial revision + * */ /* @@ -61,14 +68,342 @@ SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. */ import java.awt.event.*; + +/** + * Controls the Frenzy view and updates the model + * + * @@author Ryan Hope + */ +public class FrenzyController { + + // Random number generator + private BetterRandom betterRandom; + + private FrenzyModel f_model; + private FrenzyView f_view; + + /** + * Create a new Frenzy Controller + * + * @@param f_model the Frenzy game f_model + * @@param f_view the Frenzy game f_view + */ + FrenzyController(FrenzyModel f_model, FrenzyView f_view, + BetterRandom betterRandom) { + this.f_model = f_model; + this.f_view = f_view; + this.betterRandom = betterRandom; + + // Add player to board in random position + f_model.player = new FrenzyPlayer( + betterRandom.rand.nextInt(f_model.boardsize), + betterRandom.rand.nextInt(f_model.boardsize)); + + // Add listeners to f_view + f_view.addQuitListener(new QuitListener()); + f_view.addResetListener(new ResetListener()); + f_view.addSpawnListener(new SpawnListener()); + f_view.addPauseListener(new PauseListener()); + f_view.addPlayerControlsListener(new PlayerControlsListener()); + f_view.addEnemySpawnListener(new SpawnListener()); + + } + + private synchronized void spawnEnemy() { + if (f_model.gamestate) { + // Can't spawn new enemies if there are no unique ASCII characters + if (f_model.enemyCount < FrenzyModel.MAX_ENIMES) { + + while (true) { + + int num = betterRandom.rand.nextInt(255); + + // These characters don't print + if (num < 33 || ((num > 126) && (num < 161)) || num == 173) + continue; + + // Can't use players symbol + if (String.valueOf((char)num) == FrenzyPlayer.symbol) + continue; + + // The symbol for the new enemy + String symbol = String.valueOf((char)num); + + // Check to make sure the symbol is already in use + if (f_model.enimies.containsKey(symbol)) continue; + + // Find a random unoccupied location for the enemy to spawn + int x = -1; + int y = -1; + while (true) { + x = betterRandom.rand.nextInt(f_model.getBoardSize()); + y = betterRandom.rand.nextInt(f_model.getBoardSize()); + if (f_view.boardSquares[y][x].isOccupied() == + FrenzyModel.OCCUPANT.NONE) { + break; + } + } + + int move_x = betterRandom.rand.nextInt(2); + int move_y = betterRandom.rand.nextInt(2); + FrenzyEnemy.MOVEMENT_PATTERN mp = null; + // Spawn the new enemy + if ((move_x == 1) && (move_y == 1)) { + mp = FrenzyEnemy.MOVEMENT_PATTERN.NE; + } else if ((move_x == 1) && (move_y == 0)) { + mp = FrenzyEnemy.MOVEMENT_PATTERN.SE; + } else if ((move_x == 0) && (move_y == 1)) { + mp = FrenzyEnemy.MOVEMENT_PATTERN.NW; + } else if ((move_x == 0) && (move_y == 0)) { + mp = FrenzyEnemy.MOVEMENT_PATTERN.SW; + } + FrenzyEnemy enemy = + new FrenzyEnemy(f_model, x, y, symbol, mp, + new EnemyMover()); + f_model.enimies.put(symbol, enemy); + f_view.addOccupant(enemy, f_view.boardSquares[y][x]); + f_model.increaseEnemyCount(); + enemy.moverThread.start(); + break; + } + + } + } + } + + /** + * Handles moving the Frenzy player around the game board + * + * @@author Ryan Hope + */ + class PlayerControlsListener implements KeyListener { + + public void keyPressed(KeyEvent e) { + } + + public void keyTyped(KeyEvent e) { + } + + // Only perform an action on the release of the key + public void keyReleased(KeyEvent e) { + + if (!f_view.pauseControl.isSelected()) { + + int keycode = e.getKeyCode(); + int x_new = -1; + int y_new = -1; + int x_old = f_model.player.getXposition(); + int y_old = f_model.player.getYposition(); + if ((keycode > 36 && keycode < 41) && f_model.gamestate) { + + // Remove player from current location + f_view.removeOccupant(f_view.boardSquares[y_old][x_old]); + + switch (keycode) { + + // Move left + case 37: + if (x_old == 0) { + x_new = f_model.boardsize-1; + } else { + x_new = x_old-1; + } + y_new = y_old; + f_model.player.setXposition(x_new); + break; + + // Move up + case 38: + if (y_old == 0) { + y_new = f_model.boardsize-1; + } else { + y_new = y_old-1; + } + x_new = x_old; + f_model.player.setYposition(y_new); + break; + + // Move right + case 39: + if (x_old == f_model.boardsize-1) { + x_new = 0; + } else { + x_new = x_old+1; + } + y_new = y_old; + f_model.player.setXposition(x_new); + break; + + // Move down + case 40: + if (y_old == f_model.boardsize-1) { + y_new = 0; + } else { + y_new = y_old+1; + } + x_new = x_old; + f_model.player.setYposition(y_new); + break; + } + + // If new location is occupied by an enemy, eat it + if (f_view.boardSquares[y_new][x_new].isOccupied() == + FrenzyModel.OCCUPANT.ENEMY) { + + // Eat enemy + String key = + f_view.boardSquares[y_new][x_new].getText(); + f_model.player.eatEnemy(); + f_model.decreaseEnemyCount(); + if (f_model.player.getConsumedCount() > 0 && + f_model.enemyCount==0) { + f_model.gamestate = false; + f_view.statusLabel.setText("Game over."); + } + + // Remove key from list so that the symbol can be reused + f_model.enimies.remove(key); + + // ==================================================== + // These should be handled by events + + // Update the last action display + f_view.lastActionLabel.setText( + f_model.player.getSymbol() + " ate " + key); + + // Update the consumed enemy count display + int count = f_model.player.getConsumedCount(); + f_view.consumedLabel.setText(String.valueOf(count)); + + // ==================================================== + } + + // Add player to new square + f_view.addOccupant(f_model.player, + f_view.boardSquares[y_new][x_new]); + } + } + } + } + + /** + * Handles quitting Frenzy + * + * @@author Ryan Hope + */ + class QuitListener implements ActionListener { + public void actionPerformed(ActionEvent e) { + f_view.dispose(); + System.exit(0); + } + } + + /** + * Handles resetting Frenzy + * + * @@author Ryan Hope + */ + class ResetListener implements ActionListener { + public void actionPerformed(ActionEvent e) { + f_model.gamestate = true; + f_view.statusLabel.setText("Game Running!"); + f_view.pauseControl.setSelected(false); + f_model.player.setConsumedCount(0); + f_view.consumedLabel.setText("0"); + } + } + + /** + * Handles resetting Frenzy + * + * @@author Ryan Hope + */ + class PauseListener implements ActionListener { + public void actionPerformed(ActionEvent e) { + if (f_view.pauseControl.isSelected()) { + f_model.gamestate = false; + f_view.statusLabel.setText("Game Paused!"); + } else { + f_model.gamestate = true; + f_view.statusLabel.setText("Game Running!"); + } + } + } + + /** + * Handles spawning of new enemies + * + * @@author Ryan Hope + */ + class SpawnListener implements ActionListener { + + public void actionPerformed(ActionEvent e) { + if (f_model.gamestate) spawnEnemy(); + } + + } + + /** + * Handles moving enemies + * + * @@author Ryan Hope + */ + class EnemyMover { + + public void move(String symbol) { + FrenzyEnemy enemy = f_model.enimies.get(symbol); + FrenzyEnemy eaten = null; + if (enemy != null) { + int x = enemy.getXposition(); + int y = enemy.getYposition(); + FrenzyModel.OCCUPANT occupant_t = + f_view.boardSquares[y][x].isOccupied(); + if (occupant_t != FrenzyModel.OCCUPANT.NONE) { + String occupant = f_view.boardSquares[y][x].getText(); + if (occupant_t == FrenzyModel.OCCUPANT.PLAYER) { + f_model.gamestate = false; + f_model.player.died = true; + f_view.statusLabel.setText("Game over."); + } + eaten = f_model.enimies.get(occupant); + eaten.move = false; + f_view.lastActionLabel.setText( + symbol + " ate " + occupant); + } + while (eaten != null && eaten.moverThread.isAlive()) { + Thread.yield(); + } + f_view.removeOccupant( + f_view.boardSquares[enemy.Yposition_old][enemy.Xposition_old]); + f_view.addOccupant(enemy, f_view.boardSquares[y][x]); + } + } + + } + +}@ + + +1.1 +log +@Initial revision +@ +text +@d5 1 +a5 1 + * $Id$ +d8 4 +a11 1 + * $Log$ +a42 5 import java.io.File; import java.io.FileInputStream; import java.io.FileNotFoundException; import java.io.IOException; import java.util.Random; - -public class FrenzyController { - +d44 5 +d51 17 +a67 34 protected FrenzyModel m_model; protected FrenzyView m_view; public Random rand; @@ -103,29 +438,24 @@ public class FrenzyController { } else { rand = new Random(); } - - // Add player to board in random position +d70 13 +a82 2 m_model.player = m_model.new Player(rand.nextInt(model.getBoardSize()), rand.nextInt(model.getBoardSize())); - +d84 4 +a87 5 // Add listeners to view view.addQuitListener(new QuitListener()); view.addResetListener(new ResetListener()); view.addSpawnListener(new SpawnListener()); view.addPlayerControlsListener(new PlayerControlsListener()); - +d89 55 +a143 1 view.updateBoard(); - } - - class PlayerControlsListener implements KeyListener { - - public void keyPressed(KeyEvent e) { - } - - public void keyTyped(KeyEvent e) { - } - - public void keyReleased(KeyEvent e) { +d146 5 +d159 1 +d161 58 +a218 13 int keycode = e.getKeyCode(); int x_new = -1; int y_new = -1; @@ -139,7 +469,8 @@ public class FrenzyController { x_new = boardsize-1; } else { x_new = x_old-1; - } +d220 31 +a250 8 y_new = y_old; m_model.player.setXposition(x_new); break; @@ -148,7 +479,8 @@ public class FrenzyController { y_new = boardsize-1; } else { y_new = y_old-1; - } +d252 4 +a255 21 x_new = x_old; m_model.player.setYposition(y_new); break; @@ -170,7 +502,7 @@ public class FrenzyController { x_new = x_old; m_model.player.setYposition(y_new); break; - } +a256 12 if (m_view.boardSquares[y_new][x_new].isOccupied() == FrenzyModel.OCCUPANT.ENEMY) { String key = m_view.boardSquares[y_new][x_new].getText(); @@ -183,24 +515,16 @@ public class FrenzyController { } m_view.addOccupant(m_model.player, m_view.boardSquares[y_new][x_new]); - } - } - } - - class QuitListener implements ActionListener { - public void actionPerformed(ActionEvent e) { +d261 5 +d268 1 +a268 1 m_view.dispose(); - System.exit(0); - } - } - - class ResetListener implements ActionListener { - public void actionPerformed(ActionEvent e) { - } - } - - class SpawnListener implements ActionListener { - public void actionPerformed(ActionEvent e) { +d273 5 +d280 5 +d288 22 +d311 1 +d313 26 +a338 16 if (m_model.enimieCount <= FrenzyModel.MAX_ENIMES) { while (true) { int num = rand.nextInt(127); @@ -217,16 +541,14 @@ public class FrenzyController { FrenzyModel.OCCUPANT.NONE) { break; } - } +d340 7 +a346 6 FrenzyModel.Enemy enemy = m_model.new Enemy(x, y, symbol); m_model.enimies.put(symbol, enemy); m_view.addOccupant(enemy, m_view.boardSquares[y][x]); m_model.enimieCount++; break; - } - } - } - } - -}@ +d348 3 +d353 1 +@ diff --git a/project2/RCS/FrenzyModel.java,v b/project2/RCS/FrenzyModel.java,v index 159cdaf..e7c328c 100644 --- a/project2/RCS/FrenzyModel.java,v +++ b/project2/RCS/FrenzyModel.java,v @@ -1,11 +1,15 @@ -head 1.1; +head 1.2; access; symbols; -locks - rmh3093:1.1; strict; +locks; strict; comment @# @; +1.2 +date 2008.04.30.04.11.55; author rmh3093; state Exp; +branches; +next 1.1; + 1.1 date 2008.04.26.15.46.05; author rmh3093; state Exp; branches; @@ -17,21 +21,22 @@ desc @ -1.1 +1.2 log -@Initial revision +@break out Player and Enemy class, other changes @ text -@import java.util.TreeMap; - -/* +@/* * FrenzyModel.java * * Version: - * $Id$ + * $Id: FrenzyModel.java,v 1.1 2008/04/26 15:46:05 rmh3093 Exp rmh3093 $ * * Revisions: - * $Log$ + * $Log: FrenzyModel.java,v $ + * Revision 1.1 2008/04/26 15:46:05 rmh3093 + * Initial revision + * */ /* @@ -62,35 +67,54 @@ ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. */ +import java.util.TreeMap; + +/** + * Stores all the data and important generic aspects of the game Frenzy + * + * @@author Ryan Hope + */ public class FrenzyModel { + // Random number generator + private BetterRandom betterRandom; + // The number of rows and columns for the current game - private int boardsize; - + int boardsize; + // The player - public Player player; - + public FrenzyPlayer player; + // The enemies - public TreeMap enimies = - new TreeMap(); - - // Valid 'printable' ASCII characters start at 33 and go to 126 which only - // leaves 92 unique enemy symbols... therefore only 92 enemies can be - // active at any one time - public static final int MAX_ENIMES = 92; - + public TreeMap enimies = + new TreeMap(); + + // Valid 'printable' ASCII characters start at 1 and go to 254, if you + // subtract the non-printing characters, there are 187 unique characters + public static final int MAX_ENIMES = 187; + // The number of active enemies - protected int enimieCount = 0; - + protected int enemyCount = 0; + + // The interval in ms to spawn enemies + int enemySpawnInterval = 3000; + + // The interval in ms to spawn enemies + int enemyMoveInterval = 600; + // The possible occupants of a board square static enum OCCUPANT {NONE,PLAYER,ENEMY}; - + + // Game state + public boolean gamestate = false; + /** * Create a new Frenzy model * * @@param boardSize number of rows and columns */ - FrenzyModel(int boardSize) { + FrenzyModel(int boardSize, BetterRandom betterRandom) { + this.betterRandom = betterRandom; this.boardsize = boardSize; } @@ -103,6 +127,64 @@ public class FrenzyModel { return boardsize; } + protected synchronized void decreaseEnemyCount() { + enemyCount--; + } + + protected synchronized void increaseEnemyCount() { + enemyCount++; + } + +} +@ + + +1.1 +log +@Initial revision +@ +text +@a0 2 +import java.util.TreeMap; + +d5 1 +a5 1 + * $Id$ +d8 4 +a11 1 + * $Log$ +d42 7 +d51 3 +d55 2 +a56 2 + private int boardsize; + +d58 2 +a59 2 + public Player player; + +d61 7 +a67 8 + public TreeMap enimies = + new TreeMap(); + + // Valid 'printable' ASCII characters start at 33 and go to 126 which only + // leaves 92 unique enemy symbols... therefore only 92 enemies can be + // active at any one time + public static final int MAX_ENIMES = 92; + +d69 8 +a76 2 + protected int enimieCount = 0; + +d79 4 +a82 1 + +d88 2 +a89 1 + FrenzyModel(int boardSize) { +d102 3 +a104 109 /** * Frenzy Player Class * @@ -212,6 +294,5 @@ public class FrenzyModel { setSymbol(symbol); } } - -} +d106 4 @ diff --git a/project2/RCS/FrenzyView.java,v b/project2/RCS/FrenzyView.java,v index 2c6e7da..414440d 100644 --- a/project2/RCS/FrenzyView.java,v +++ b/project2/RCS/FrenzyView.java,v @@ -1,11 +1,15 @@ -head 1.1; +head 1.2; access; symbols; -locks - rmh3093:1.1; strict; +locks; strict; comment @# @; +1.2 +date 2008.04.30.04.13.13; author rmh3093; state Exp; +branches; +next 1.1; + 1.1 date 2008.04.26.15.46.15; author rmh3093; state Exp; branches; @@ -17,19 +21,22 @@ desc @ -1.1 +1.2 log -@Initial revision +@first attemp at moving enemies @ text @/* * FrenzyView.java * * Version: - * $Id$ + * $Id: FrenzyView.java,v 1.1 2008/04/26 15:46:15 rmh3093 Exp rmh3093 $ * * Revisions: - * $Log$ + * $Log: FrenzyView.java,v $ + * Revision 1.1 2008/04/26 15:46:15 rmh3093 + * Initial revision + * */ /* @@ -66,24 +73,63 @@ import javax.swing.*; import javax.swing.border.Border; import javax.swing.border.TitledBorder; +/** + * The visual aspect of Frenzy + * + * @@author Ryan Hope + */ @@SuppressWarnings("serial") public class FrenzyView extends JFrame { - private FrenzyModel m_model; + ActionListener enemySpawner; + ActionListener enemyMover; + + private FrenzyModel f_model; + private BetterRandom betterRandom; + + Thread enemySpawnerThread = new Thread(new EnemySpawner()); + /** + * Customized button to represent a square on the game board + * + * @@author Ryan Hope + */ class BoardSqaure extends JButton { + // The default button colors Color defaultcolor; + + /** + * Create a new board square + */ public BoardSqaure() { + + // Do not want board squares stealing focus from player controls setFocusable(false); + + // Get the default button color for unoccupied squares defaultcolor = getBackground(); + + // Set margins to 0 so that symbol shows up with out a giant button + setMargin(new Insets(0,0,0,0)); + + // Set button size to something reasonable + setPreferredSize(new Dimension(20,20)); + + // Force font size so that symbol fits within button bounds + setFont(new Font(getFont().getName(), getFont().getStyle(), 12)); } + /** + * Returns the occupant of the board square + * + * @@return the board square occupant + */ FrenzyModel.OCCUPANT isOccupied() { FrenzyModel.OCCUPANT ret = FrenzyModel.OCCUPANT.NONE; if (getText().length() > 0) { - if (getText() == m_model.player.getSymbol()) { + if (getText() == FrenzyPlayer.symbol) { ret = FrenzyModel.OCCUPANT.PLAYER; } else { ret = FrenzyModel.OCCUPANT.ENEMY; @@ -94,6 +140,7 @@ public class FrenzyView extends JFrame { } + // The label of the game control buttons private static final String[] buttonLables = { "Pause","Spawn","++","--","Restart","Quit" }; @@ -107,7 +154,7 @@ public class FrenzyView extends JFrame { JCheckBox pauseControl = new JCheckBox(); JButton[] controlButtons = new JButton[5]; JLabel consumptionLabel = new JLabel("Consumption"); - JLabel pieceLabel = new JLabel("Piece is P"); + JLabel pieceLabel = new JLabel("Piece is "); JLabel consumedLabel = new JLabel("0"); JLabel statusLabel = new JLabel("Game Running!"); JLabel lastActionLabel = new JLabel("S ate K"); @@ -116,14 +163,22 @@ public class FrenzyView extends JFrame { TitledBorder boardContainerBoarder; Border standardBoarder; - FrenzyView(FrenzyModel model) { - m_model = model; + /** + * Create a new view + * + * @@param f_model Frenzy f_model of important game data + */ + FrenzyView(FrenzyModel f_model, BetterRandom betterRandom) { + this.f_model = f_model; + this.betterRandom = betterRandom; - // Set some basics + // Set some basics settings setTitle("Frenzy"); setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE); standardBoarder = BorderFactory.createTitledBorder(""); + pauseControl.setSelected(false); setFocusable(true); + setResizable(false); // Setup view ==================================================== mainPane.setLayout(new BorderLayout()); @@ -162,7 +217,7 @@ public class FrenzyView extends JFrame { mainPane.add(infoContainer, BorderLayout.NORTH); // Game board - int boardsize = model.getBoardSize(); + int boardsize = f_model.getBoardSize(); boardContainerBoarder = BorderFactory.createTitledBorder("Game Board"); gameboard.setBorder(boardContainerBoarder); gameboard.setLayout(new GridLayout(boardsize, boardsize)); @@ -177,48 +232,204 @@ public class FrenzyView extends JFrame { mainPane.add(gameboard, BorderLayout.CENTER); this.pack(); - int width = mainPane.getWidth() + 75; - setSize(width, width); - + + setVisible(true); + } + + /** + * Start game + */ + protected void start() { + pieceLabel.setText("Piece is " + f_model.player.getSymbol()); + spawnPlayer(); + f_model.gamestate = true; + enemySpawnerThread.start(); + } + + class EnemySpawner implements Runnable { - public void addOccupant(FrenzyModel.Player player, BoardSqaure location) { + public void run() { + try { + try { + Thread.sleep(f_model.enemySpawnInterval); + } catch (InterruptedException e) { + } + while (true) { + enemySpawner.actionPerformed(new ActionEvent(this, + ActionEvent.ACTION_PERFORMED, "spawn")); + Thread.sleep(f_model.enemySpawnInterval); + } + } catch (InterruptedException e) { + } + } + + } + + /** + * Add a player to a board square + * + * @@param player the player + * @@param location the board square to move to + */ + public void addOccupant(FrenzyPlayer player, BoardSqaure location) { location.setText(player.getSymbol()); location.setBackground(new Color(255,255,0)); } - public void addOccupant(FrenzyModel.Enemy enemy, BoardSqaure location) { + /** + * Add an enemy to a board square + * + * @@param enemy the enemy + * @@param location the board square to move to + */ + public void addOccupant(FrenzyEnemy enemy, BoardSqaure location) { location.setText(enemy.getSymbol()); location.setBackground(new Color(0,255,0)); } + /** + * Remove occupant from board square + * + * @@param location board square to remove occupant from + */ public void removeOccupant(BoardSqaure location) { location.setText(""); location.setBackground(location.defaultcolor); location.repaint(); } - void updateBoard() { - int px = m_model.player.getXposition(); - int py = m_model.player.getYposition(); - addOccupant(m_model.player, boardSquares[py][px]); + /** + * Spawn the player + */ + void spawnPlayer() { + int px = f_model.player.getXposition(); + int py = f_model.player.getYposition(); + addOccupant(f_model.player, boardSquares[py][px]); } + /** + * Register a player controls handler + * + * @@param pc player controls handler + */ void addPlayerControlsListener(KeyListener pc) { this.addKeyListener(pc); } + /** + * Register a quit handler + * + * @@param quit quit handler + */ void addQuitListener(ActionListener quit) { controlButtons[4].addActionListener(quit); } + /** + * Register a reset handler + * + * @@param reset + */ void addResetListener(ActionListener reset) { controlButtons[3].addActionListener(reset); } + /** + * Register a spawn handler + * + * @@param spawn + */ void addSpawnListener(ActionListener spawn) { controlButtons[0].addActionListener(spawn); } + /** + * Register a pause handler + * + * @@param pause + */ + void addPauseListener(ActionListener pause) { + pauseControl.addActionListener(pause); + } + + /** + * Register an enemy spawn handler + * + * @@param spawn + */ + void addEnemySpawnListener(ActionListener spawn) { + enemySpawner = spawn; + } + } @ + + +1.1 +log +@Initial revision +@ +text +@d5 1 +a5 1 + * $Id$ +d8 4 +a11 1 + * $Log$ +d48 5 +d56 5 +a60 1 + private FrenzyModel m_model; +d62 7 +d71 1 +d74 4 +d79 2 +d82 2 +d85 9 +d96 5 +d104 1 +a104 1 + if (getText() == m_model.player.getSymbol()) { +d115 1 +d129 1 +a129 1 + JLabel pieceLabel = new JLabel("Piece is P"); +d138 8 +a145 2 + FrenzyView(FrenzyModel model) { + m_model = model; +d147 1 +a147 1 + // Set some basics +d151 1 +d153 1 +d192 1 +a192 1 + int boardsize = model.getBoardSize(); +d207 16 +a222 2 + int width = mainPane.getWidth() + 75; + setSize(width, width); +d224 14 +a237 1 + } +d239 9 +a247 1 + public void addOccupant(FrenzyModel.Player player, BoardSqaure location) { +d252 7 +a258 1 + public void addOccupant(FrenzyModel.Enemy enemy, BoardSqaure location) { +d263 5 +d274 7 +a280 4 + void updateBoard() { + int px = m_model.player.getXposition(); + int py = m_model.player.getYposition(); + addOccupant(m_model.player, boardSquares[py][px]); +d283 5 +d292 5 +d301 5 +d310 5 +d319 18 +@ diff --git a/project2/README-min b/project2/README-min index 3774f9d..4e49208 100644 --- a/project2/README-min +++ b/project2/README-min @@ -22,3 +22,6 @@ Implementation: 3. Which features (if any) are incomplete or faulty? 4. Please describe any other known problems with this version of the program. + +Thread.suspend() and Thread.resume() are used to stop the spawning of enemies +but these functions are inherently unsafe. -- 2.11.4.GIT