オープンソース・ソフトウェアの開発とダウンロード

Subversion リポジトリの参照

Contents of /trunk/OpenSangokushi/src/jp/or/cute/sangokushi/Lobby.java

Parent Directory Parent Directory | Revision Log Revision Log


Revision 256 - (show annotations) (download)
Mon May 10 01:25:31 2010 UTC (14 years ago) by izumist
File MIME type: text/plain
File size: 8707 byte(s)


1 package jp.or.cute.sangokushi;
2
3 /**
4 * ロビー画面
5 * @author akifumi3
6 * @author takki
7 * @version 0.1.1
8 * @since 2010/04/28
9 * @change 2010/05/02
10 * オープニング画面が呼び出される
11 * ロビーを選択すると戦闘画面に移行する
12 * TODO
13 * ・現在はなにが選択されても同じ画面が表示されている
14 *  選択された画面を表示するように修正すること
15 */
16
17 import jp.or.cute.sangokushi.httpclient.BattleCommand;
18 import android.app.Activity;
19 import android.os.Bundle;
20 import android.widget.ArrayAdapter;
21 import android.widget.ListView;
22 import android.widget.TextView;
23 import android.widget.AdapterView.OnItemClickListener;
24 import android.app.AlertDialog;
25 import android.content.DialogInterface;
26 import android.content.Intent;
27 import android.util.Log;
28 import android.view.View;
29 import android.widget.*;
30
31 public class Lobby extends Activity {
32 public static final int RESULT_OAUTH = 1001;
33 private Activity me;
34 private String user_id = "U7bd5r6a2d";
35 private String room_id;
36 private BattleCommand mBattleCommand;
37 private String[] battleStatusList;
38 private String selectRoomID;
39 private SangokushiPreferences mPref;
40
41 public battle_Status[] makeBattleStatus(String result) {
42 String[] param = result.split(">>");
43 int max_data = 5; // param.length-1;
44 battleStatusList = new String[max_data];
45 battle_Status[] bs = new battle_Status[max_data];
46
47 for(int j=1,i=0;j<6;j++,i++){
48 String[] value = param[j].split(",");
49 bs[i] = new battle_Status();
50 bs[i].setlocation(value[1]);
51 bs[i].setRoomid(Integer.parseInt(value[0]));
52 if (value[2] == "0") {
53 bs[i].setOngoing(false);
54 } else if (value[2] == "2"){
55 bs[i].setOngoing(true);
56 } else {
57 bs[i].setOngoing(false);
58 }
59 String location = value[1] + "之戦";
60 bs[i].setlocation(location);
61 }
62
63 return bs;
64 }
65
66 /** Called when the activity is first created. */
67 @Override
68 public void onCreate(Bundle savedInstanceState) {
69 super.onCreate(savedInstanceState);
70 setContentView(R.layout.lobby);
71
72 final ListView list1 = (ListView) findViewById(R.id.ListView01);
73 me = this;
74
75 //通信コマンドにsessionIDを追加 by iST
76 mPref = new SangokushiPreferences(this);
77 mBattleCommand = new BattleCommand(mPref.getSessionID());
78 String result = mBattleCommand.httpPost("data=R01001");
79 Log.d("Lobby","result="+result);
80 battle_Status[] bs = makeBattleStatus(result);
81 Log.d("Lobby","bs.length="+Integer.toString(bs.length));
82 /*
83 * Sample data
84 */
85 /*
86 String[] battleStatusList= new String[5]; //TODO 5はマジックナンバーなので修正予定
87 battle_Status[] bs = new battle_Status[5]; //TODO 5はマジックナンバーなので修正予定
88
89 for(int n = 0;n<5;n++){
90 bs[n] = new battle_Status();
91 }
92
93 bs[0].setAllParams("合肥之戦", true, 10, 3, "曹操", "張遼", 15, "孫権", "陸遜", 21);
94 bs[1].setAllParams("陽平関之戦", false, 15, 5, "劉備", "張飛", 12, "曹操", "陸遜", 9);
95 bs[2].setAllParams("赤壁之戦", true, 20, 7, "劉備", "諸葛亮", 5, "孫権", "陸遜", 2);
96 bs[3].setAllParams("定軍山之戦", false, 25, 9, "Apple", "iphone", 7, "Google", "Xperia", 4);
97 bs[4].setAllParams("野戦", false, 30, 11, "裕之", "Akifumi3", 100, "孫悟空", "孫正義", 2000);
98 */
99 for(int i =0;i<bs.length;i++){
100 battleStatusList[i] = bs[i].getlocation();
101 if(bs[i].isOngoing()){
102 battleStatusList[i] += " 対峙中";
103 }else{
104 battleStatusList[i] += " 開戦前";
105 }
106 }
107 //Sample data ここまで
108
109 /*
110 * ListView作成処理
111 */
112 ArrayAdapter<String> adapter = new ArrayAdapter<String>(this, R.layout.list, battleStatusList);
113 list1.setAdapter(adapter);
114 list1.setSelection(0);
115 //list1.setOnItemClickListener(new MyClickAdapter());
116 list1.setOnItemClickListener(new MyClickAdapter(bs));
117
118 /*
119 * UserStatus(画面下側)作成処理予定
120 * 暫定で名前だけ変更中
121 */
122 final TextView test = (TextView)findViewById(R.id.TextView01);
123 test.setText("裕之");
124
125 }
126
127
128 // イベントクラス
129 class MyClickAdapter implements OnItemClickListener {
130 battle_Status[] bs_copy = new battle_Status[5];//TODO also magic number too.
131
132 public MyClickAdapter(battle_Status _bs[]){
133 bs_copy = _bs;
134 }
135
136 /*
137 * TODO
138 * Battle遷移 @Takki
139 */
140 private void startBattle(){
141 try{
142 Log.d("Debug","Intent call");
143 Intent intent = new Intent(me, Battle.class);
144 String msg = user_id + "," + room_id;
145 intent.putExtra("String", msg);
146 startActivityForResult(intent, RESULT_OAUTH);
147 }catch(Exception e){
148 e.printStackTrace();
149 }
150 }
151
152
153 @Override
154 public void onItemClick(AdapterView<?> adapter,
155 View view, int position, long id) {
156 AlertDialog.Builder bldr = new AlertDialog.Builder(me);
157
158 bldr.setTitle("戦況");//TODO values/string/hoge に直す
159 //TextView txt = (TextView)view;
160
161 //String dialog_message = txt.getText()+"\n開催10日と3時間前\n\n曹操軍\n 総大将 張遼\n 参加人数 15\n VS\n孫権軍\n 総大将 陸遜\n 参加人数 21\n戦場を見る\n参戦する";
162 String dialog_message = bs_copy[position].getAll_jp();
163 //bldr.setMessage("選択項目:" + txt.getText()+"¥n");
164 bldr.setMessage(dialog_message);
165 room_id = Integer.toString(bs_copy[position].getRoomid());
166
167 DialogInterface.OnClickListener listner = new DialogInterface.OnClickListener(){
168 @Override
169 public void onClick(DialogInterface dialog, int which) {
170 Log.d("Button",Integer.toString(which));
171 setResult(RESULT_OK);
172 }
173 };
174
175 // bldr.setPositiveButton("参戦する",listner); //TODO String.xmlを参照する予定
176 bldr.setPositiveButton("参戦する",new DialogInterface.OnClickListener() {
177
178 @Override
179 public void onClick(DialogInterface dialog, int which) {
180 Log.d("Button push","compete");
181 startBattle();
182 }
183 });
184 bldr.setNegativeButton(getString(R.string.cancel), listner);
185 bldr.create();
186 bldr.show();
187 }
188
189
190 }
191
192 public class battle_Status {
193 private int roomid;
194 private String location; //赤壁乃戦 など
195 private boolean ongoing; //true = 対峙中, false = 開戦前
196 private int fromDay; //経過日数
197 private int fromHour; //経過時間
198
199
200 private String battler1; //チーム名 ("曹操" or "孫権" ..)
201 private String boss1; //総大将 ("張遼" ..)
202 private int numOfPeople1; //参戦人数
203
204 private String battler2; //チーム名 ("曹操" or "孫権" ..)
205 private String boss2; //総大将 ("張遼" ..)
206 private int numOfPeople2; //参戦人数
207
208
209
210 public String getlocation() {
211 return location;
212 }
213
214 public int getRoomid() {
215 return this.roomid;
216 }
217 public void setRoomid(int id) {
218 this.roomid = id;
219 }
220
221 public void setlocation(String location) {
222 this.location = location;
223 }
224
225 public void setOngoing(boolean going)
226 {
227 this.ongoing = going;
228 }
229
230 public void setAllParams(String _location ,boolean ongoing, int fromDay,int fromHour,String battler1,String boss1,int numOfPeople1,String battler2, String boss2,int numOfPeople2){
231 location = _location;
232 this.ongoing = ongoing;
233 this.fromDay = fromDay;
234 this.fromHour = fromHour;
235 this.battler1 = battler1;
236 this.boss1 = boss1;
237 this.numOfPeople1 = numOfPeople1;
238 this.battler2 = battler2;
239 this.boss2 = boss2;
240 this.numOfPeople2 = numOfPeople2;
241 }
242
243
244 public boolean isOngoing(){
245 if(ongoing){
246 return true;
247 }else{
248 return false;
249 }
250 }
251
252 public String getAll_jp(){
253 return location+"\n"+fromDay+"日と"+fromHour+"時間\n\n"+battler1+" 軍\n 総大将 "+boss1 +"\n 参加人数 "+numOfPeople1+"人\n VS\n"+battler2+" 軍\n 総大将 "+boss2 +"\n 参加人数 "+numOfPeople2+"人\n";
254
255 }
256
257
258 }
259
260
261
262 }

Properties

Name Value
svn:mime-type text/plain

Back to OSDN">Back to OSDN
ViewVC Help
Powered by ViewVC 1.1.26