-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathplayergenerator.java
123 lines (107 loc) · 3.43 KB
/
playergenerator.java
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
/*
* Copyright 2009 James Koval
*
* This file is part of Jedi Mage
*
* Jedi Mage is free software: you can redistribute it
* and/or modify it under the terms of the GNU General Public License
* as published by the Free Software Foundation, either version 3
* of the License, or (at your option) any later version.
*
* Jedi Mage is distributed in the hope that it will be useful, but
* WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See
* the GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with Jedi Mage. If not, see <http://www.gnu.org/license/>
*/
import java.util.ArrayList;
public class playergenerator {
public player wizard;
filemanager fileman;
public String[] players;
String playersfolder;
/**
* Default constructor searches for deck txt files inside the decks folder. If it found decks, this.saDecks will be populated with valid decks.
* A valid deck is given to this.opendeck(String deckname). If the deck can be opened, this.library is populated with a deck.
*/
public playergenerator(){
fileman = new filemanager();
if(!getplayers())
System.out.println("Couldn't find players");
}
/**
* Looks for decks in the decks folder
* @return false if the decks folder isn't found or if no decks are found
*/
boolean getplayers(){
String[] saFolders;
players = null;
saFolders = fileman.ls();
for(int i = 0; i < saFolders.length; i++)
if(saFolders[i].equalsIgnoreCase("players")){//Search for decks folder and save the name
players = fileman.ls(saFolders[i]);
playersfolder = saFolders[i];
}
if(players == null || players.length == 0)//There is no decks folder or no docks
return false;
return true;
}
/**
* Opens a player by filename.
* @param deckname Name of the player including .txt
* @return false if player can't be opened or parsed. Otherwise, this.wizard is now usable
*/
public boolean open(String playername){
//Check for valid deck
boolean found = false;
for(int i = 0; i < players.length; i++)
if(playername.equalsIgnoreCase(players[i]))
found = true;
if(!found)
return false;
if(!lex(fileman.read("./"+playersfolder+"/"+playername), removetxt(playername)))
return false;
return true;
}
boolean lex(ArrayList<String> saPlayerinfo, String playername){
if(saPlayerinfo == null || saPlayerinfo.size() < 2)
return false;
wizard = new player(playername);
valuedstat vs = null;
effect win = null;
for(int i = 0; i < saPlayerinfo.size(); i++){
switch(saPlayerinfo.get(i).split(" ").length){
case 2: vs = valuedstat.getvaluedstat(saPlayerinfo.get(i));
win = null;
break;
case 3: win = effect.geteffect(saPlayerinfo.get(i));
vs = null;
break;
default: System.out.println("This line means nothing:\n"+saPlayerinfo.get(i));
}
if(win != null)
wizard.addwincondition(win);
else if(vs != null)
wizard.setstat(vs);
else
System.out.println("This line wasn't parsed correctly:\n"+saPlayerinfo.get(i));
}
return true;
}
/**
* Determine if the first character of a string is a number
* @param s
* @return
*/
boolean startswithnum(String s){
char c = s.charAt(0);
if(c == '-' || (c >= '0' && c <= '9'))
return true;
return false;
}
String removetxt(String s){
return s.substring(0, s.length()-4);
}
}