00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014
00015
00016
00017
00018
00019
00020
00021 package org.classroomgaming.cgp;
00022
00023 import java.awt.Color;
00024 import java.awt.Graphics;
00025 import java.util.StringTokenizer;
00026
00033 class Shop {
00034
00035 int x;
00036 int y;
00037 String newline;
00038 String items[];
00039 String b[];
00040 String links[];
00041
00042 public Shop(int i, int j, String stringArr[], String stringArr4[], String stringArr5[], String string) {
00043
00044 x = i;
00045 y = j;
00046 items = stringArr;
00047 b = stringArr4;
00048 newline = string;
00049 links = stringArr5;
00050 return;
00051 }
00052
00053 public String link(int i) {
00054 return (links[i]);
00055 }
00056
00057 public int purchase(Graphics graphics, int i) {
00058 int n;
00059 int m;
00060 int p;
00061 String stringArr[];
00062 int k;
00063 int j;
00064 if (i < 0) {
00065 i = items.length;
00066 }
00067
00068 if (i > items.length) {
00069 i = 1;
00070 }
00071
00072 graphics.setColor(Color.cyan);
00073 graphics.fill3DRect(0, 0, 320, 480, true);
00074 graphics.setColor(Color.green);
00075 graphics.fill3DRect(320, 0, 320, 240, true);
00076 graphics.setColor(Color.red);
00077 graphics.fill3DRect(320, 240, 320, 240, true);
00078 graphics.drawString("Welcome to the shop!", 325, 12);
00079 graphics.drawString("Use the 'n' and 'p' keys to select an item.", 325, 24);
00080 graphics.drawString("Use the 'b' Key to purchase that item", 325, 36);
00081 graphics.drawString("Press a movement key to leave the store.", 325, 48);
00082 graphics.drawString("Thank YOU! COME AGAIN!", 325, 60);
00083 j = 0;
00084 k = 26;
00085 j = 0;
00086 for (; j < items.length;) {
00087 if (i == j) {
00088 graphics.setColor(Color.red);
00089 } else {
00090 graphics.setColor(Color.black);
00091 }
00092
00093 graphics.drawString(items[j], 14, k);
00094
00095 k += 14;
00096 j++;
00097 }
00098 graphics.setColor(Color.black);
00099 n = 252;
00100 stringArr = parse(b[i], newline);
00101 j = 0;
00102 for (; j < stringArr.length;) {
00103 graphics.drawString(stringArr[j], 325, n);
00104
00105 n += 14;
00106 j++;
00107 }
00108 return (i);
00109 }
00110
00111 String[] parse(String string, String string2) {
00112 StringTokenizer stringtokenizer = new StringTokenizer(string, string2);
00113 String string4[] = new String[stringtokenizer.countTokens()];
00114 int i = 0;
00115 for (; i < string4.length;) {
00116 string4[i] = stringtokenizer.nextToken();
00117 i++;
00118 }
00119 return (string4);
00120 }
00121
00122 public boolean test(int i, int j) {
00123 if ((x == i) &&
00124 (y == j)) {
00125 return (true);
00126 }
00127
00128 return (false);
00129 }
00130 }