Commit 115d8d22 authored by Choirunnisa Fatima's avatar Choirunnisa Fatima
Browse files

Completing requirements

parent 78a5539b
# APPLICATION NAME
# WINNIE QUEST
By:
Tony / 13512018
Jacqueline Ibrahim / 13512074
Choirunnisa Fatima / 13512084
William Stefan Hartono / 13512098
package com.sist.j.grandquest;
import android.graphics.Color;
import android.os.Bundle;
import android.support.v7.app.ActionBarActivity;
import android.view.View;
import android.widget.Button;
import android.widget.EditText;
import android.widget.TextView;
import android.widget.Toast;
public class SignInActivity extends ActionBarActivity {
private EditText username;
private EditText password;
private Button login;
private TextView loginLockedTV;
private TextView attemptsLeftTV;
private TextView numberOfRemainingLoginAttemptsTV;
int numberOfRemainingLoginAttempts = 3;
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);
setupVariables();
}
public void authenticateLogin(View view) {
//have not: fetch the localhost input too
//have not: uname & passw from Mongo
if (username.getText().toString().equals("player") &&
password.getText().toString().equals("player")) {
Toast.makeText(getApplicationContext(), "Hello, Player!",
Toast.LENGTH_SHORT).show();
} else {
Toast.makeText(getApplicationContext(), "Seems like you're not Player!",
Toast.LENGTH_SHORT).show();
numberOfRemainingLoginAttempts--;
attemptsLeftTV.setVisibility(View.VISIBLE);
numberOfRemainingLoginAttemptsTV.setVisibility(View.VISIBLE);
numberOfRemainingLoginAttemptsTV.setText(Integer.toString(numberOfRemainingLoginAttempts));
if (numberOfRemainingLoginAttempts == 0) {
login.setEnabled(false);
loginLockedTV.setVisibility(View.VISIBLE);
loginLockedTV.setBackgroundColor(Color.RED);
loginLockedTV.setText("LOGIN LOCKED");
}
}
}
private void setupVariables() {
username = (EditText) findViewById(R.id.usernameET);
password = (EditText) findViewById(R.id.passwordET);
login = (Button) findViewById(R.id.loginBtn);
loginLockedTV = (TextView) findViewById(R.id.loginLockedTV);
attemptsLeftTV = (TextView) findViewById(R.id.attemptsLeftTV);
numberOfRemainingLoginAttemptsTV = (TextView) findViewById(R.id.numberOfRemainingLoginAttemptsTV);
numberOfRemainingLoginAttemptsTV.setText(Integer.toString(numberOfRemainingLoginAttempts));
}
}
\ No newline at end of file
<FrameLayout xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:tools="http://schemas.android.com/tools" android:id="@+id/container"
android:layout_width="match_parent" android:layout_height="match_parent"
tools:context="com.sist.j.grandquest.MenuActivity" tools:ignore="MergeRootFrame" />
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:tools="http://schemas.android.com/tools"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:paddingBottom="@dimen/activity_vertical_margin"
android:paddingLeft="@dimen/activity_horizontal_margin"
android:paddingRight="@dimen/activity_horizontal_margin"
android:paddingTop="@dimen/activity_vertical_margin"
tools:context="com.sist.j.grandquest"
android:background="@drawable/wy">
<TextView
android:id="@+id/textView1"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_alignParentTop="true"
android:layout_centerHorizontal="true"
android:layout_marginTop="20dp"
android:text="Log Yourself In First"
android:textAppearance="?android:attr/textAppearanceLarge"
/>
<EditText
android:id="@+id/usernameET"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:hint="username"
android:layout_above="@+id/passwordET"
android:layout_alignLeft="@+id/passwordET"
android:layout_alignStart="@+id/passwordET">
<requestFocus />
</EditText>
<EditText
android:id="@+id/passwordET"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:hint="password"
android:inputType="textPassword"
android:layout_centerVertical="true"
android:layout_alignRight="@+id/loginBtn"
android:layout_alignEnd="@+id/loginBtn" />
<EditText
android:id="@+id/localhostET"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:hint="localhost"/>
<TextView
android:id="@+id/attemptsLeftTV"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_marginLeft="30dp"
android:layout_marginTop="48dp"
android:text="Attempts Left:"
android:visibility="invisible"
android:textAppearance="?android:attr/textAppearanceMedium"
android:layout_below="@+id/textView1" />
<Button
android:id="@+id/loginBtn"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:onClick="authenticateLogin"
android:text="Login"
android:layout_below="@+id/passwordET"
android:layout_centerHorizontal="true"
android:layout_marginTop="32dp" />
<TextView
android:id="@+id/numberOfRemainingLoginAttemptsTV"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_alignRight="@+id/textView1"
android:layout_alignTop="@+id/attemptsLeftTV"
android:visibility="invisible" />
<TextView
android:id="@+id/loginLockedTV"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_below="@+id/loginBtn"
android:layout_marginTop="35dp"
android:layout_centerHorizontal="true"
android:textAppearance="?android:attr/textAppearanceMedium"
android:visibility="invisible" />
<Button
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="Register"
android:id="@+id/button2"
android:layout_alignBottom="@+id/loginLockedTV"
android:layout_alignLeft="@+id/passwordET"
android:layout_alignStart="@+id/passwordET" />
</RelativeLayout>
package com.sist.j.grandquest;
import android.net.Uri;
import android.os.Bundle;
import android.provider.MediaStore;
import android.app.Activity;
import android.content.Context;
import android.content.Intent;
import android.database.Cursor;
import android.graphics.Bitmap;
import android.graphics.BitmapFactory;
import android.support.v4.widget.SlidingPaneLayout;
import android.util.Log;
import android.view.Display;
import android.view.Gravity;
import android.view.LayoutInflater;
import android.view.Menu;
import android.view.MenuItem;
import android.view.View;
import android.view.Window;
import android.view.WindowManager;
import android.view.inputmethod.InputMethodManager;
import android.widget.AdapterView;
import android.widget.Button;
import android.widget.EditText;
import android.widget.PopupWindow;
import android.widget.RelativeLayout;
import android.widget.TextView;
import android.widget.Toast;
import android.widget.GridView;
//import com.sist.j.grandquest.MapFragment;
//import com.sist.j.grandquest.MenuFragment;
public class MapGridActivity extends Activity {
//plus slidingpanelayout
// private SlidingPaneLayout sPaneLy;
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_map_grid);
GridView gridview = (GridView) findViewById(R.id.gridview);
final MapGridView.GridAdapter gridadapter = new MapGridView.GridAdapter(this);
gridview.setAdapter(gridadapter));
gridview.setOnItemClickListener(new AdapterView.OnItemClickListener() {
public void onItemClick(AdapterView<?> parent, View v, int position, long id) {
Intent i = new Intent(Intent.ACTION_VIEW);
i.setData(Uri.parse(gridadapter.getItem(position).getImageUrlString()));
startActivity(i);
//Then, "move" the chara = clear on the previous place then show on current.new place
}
});
}
}
\ No newline at end of file
package com.sist.j.grandquest;
import com.sist.j.grandquest.R;
import android.content.Context;
import android.graphics.Bitmap;
import android.graphics.Canvas;
import android.graphics.drawable.Drawable;
import android.media.MediaPlayer;
import android.util.AttributeSet;
import android.util.Log;
import android.view.MotionEvent;
import android.view.ViewGroup;
import android.view.View;
import android.widget.BaseAdapter;
import android.widget.GridView;
import android.widget.Toast;
public class MapGridView extends GridView {
public class GridAdapter extends BaseAdapter {
private Context context;
//should retrieve from server the "col x row"
private Integer[] imageIds = {
R.drawable.tilebkg
};
public GridAdapter(Context c) {
context = c;
}
public int getCount() {
return imageIds.length;
}
public Object getItem(int position) {
return imageIds[position];
}
public long getItemId(int position) {
return 0;
}
public View getView(int position, View view, ViewGroup parent) {
SqrImageView iview;
if (view == null) {
iview = new SqrImageView(context);
iview.setLayoutParams(new GridView.LayoutParams(150, 200));
iview.setScaleType(SqrImageView.ScaleType.CENTER_CROP);
iview.setPadding(5, 5, 5, 5);
} else {
iview = (SqrImageView) view;
}
iview.setImageResource(imageIds[position]);
return iview;
}
//connect to server to get/collect item from that place/field
//should be random
private CharaToCollect[] imageIds = {
new CharaToCollect(R.drawable.tilebkg, "") //"" = to server
};
public CharaToCollect getItem(int position) {
return imageIds[position];
}
public View getView(int position, View view, ViewGroup parent) {
// most of this is just as before
SqrImageView iview;
iview.setImageResource(imageIds[position].getImageId());
return iview;
}
protected class CharaToCollect extends Object {
private int imageId;
private String imageUrlString;
CharaToCollect(int id, String url) { //url = connect server
imageId = id;
imageUrlString = url;
}
public int getImageId() {
return imageId;
}
public String getImageUrlString() {
return imageUrlString;
}
}
}
}
\ No newline at end of file
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:tools="http://schemas.android.com/tools" android:layout_width="match_parent"
android:layout_height="match_parent" android:paddingLeft="@dimen/activity_horizontal_margin"
android:paddingRight="@dimen/activity_horizontal_margin"
android:paddingTop="@dimen/activity_vertical_margin"
android:paddingBottom="@dimen/activity_vertical_margin"
tools:context="com.sist.j.grandquest.MapGridActivity">
<TextView android:text="@string/hello_world" android:layout_width="wrap_content"
android:layout_height="wrap_content" />
<GridView xmlns:android="http://schemas.android.com/apk/res/android"
android:id="@+id/gridview"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:gravity="center"
android:stretchMode="columnWidth"
android:numColumns="auto_fit"
android:paddingBottom="@dimen/activity_vertical_margin"
android:paddingLeft="@dimen/activity_horizontal_margin"
android:paddingRight="@dimen/activity_horizontal_margin"
android:paddingTop="@dimen/activity_vertical_margin"
/>
</RelativeLayout>
# Client Side
By:
Jacqueline
Choirunnisa Fatima
Tony
William Stefan Hartono
Tony / 13512018
Jacqueline Ibrahim / 13512074
Choirunnisa Fatima / 13512084
William Stefan Hartono / 13512098
## Development Environment
Android
## Development Environment
Java programming language on Android
## Requirements
Android device or android emulator
## How to Run
Install the apk file from folder bin on android device or emulator.
## Additional Information
/*** HOW TO PLAY WINNIE QUEST ***/
......@@ -33,3 +33,4 @@ Android device or android emulator
Last Updated:
26/4/2015 9:37 pm
### Import ###
#Socket client example in python
import socket #for sockets
import sys #for exit
#md5 hash function
def md5(string):
m = hashlib.md5()
m.update(string.encode('UTF-8'))
return m.hexdigest()
#def receiverHandler(conn):
#reply = conn.recv(4096)
#create an INET, STREAMing socket
try:
sock = socket.socket(socket.AF_INET, socket.SOCK_STREAM)
except socket.error:
print ('Failed to create socket')
sys.exit()
print ('Socket Created')
host = 'localhost';
port = 5005;
#try:
#remote_ip = socket.gethostbyname( host )
#except socket.gaierror:
#could not resolve
#print ('Hostname could not be resolved. Exiting')
#sys.exit()
#Connect to remote server
sock.connect((host , port))
#print ('Socket Connected to ' + host + ' on ip ' + remote_ip)
user_token = ''
#Send some data to remote server
user_input = input('Masukkan angka 1-15 (0 untuk keluar):')
#Server Status#
if user_input == '1':
message = '{\"method\": \"serverStatus\", \"server\": [{\"ip\" : \"167.205.32.46\", \"port\": 8000}]}'
#Sign Up#
elif user_input == '2':
username = input("Username: ")
password = input("Password: ")
message = '{"method": "signup", "username": "'+ username +'", "password": "'+ password +'"}'
#Login#
elif user_input == '3':
username = input("Username: ")
password = input("Password: ")
message = '{"method": "login", "username": "'+ username +'", "password": "'+ password +'"}'
#Inventory#
elif user_input == '4':
message = '{"method": "inventory", "token": "553525ee2c4aa802e47749c6"}'
#MixItem#
elif user_input == '5':
message = '{"method": "mixitem", "token": "553525ee2c4aa802e47749c6", "item1": 0, "item2": 1}'
elif user_input == '6':
message = '{\"method\": \"map\", \"token\": \"1\"}'
elif user_input == '7':
message = '{\"method\": \"field\", \"token\": \"1\"}'
elif user_input == '8':
message = '{\"method\": \"offer\", \"token\": \"1\", \"offered_item\": 0, \"n1\": 1, \"demanded_item\": 1, \"n2\": 1}'
elif user_input == '9':
message = '{\"met:hod\": \"tradebox\", \"token\": \"1\"}'
elif user_input == '10':
message = '{\"method\": \"sendfind\", \"token\": \"1\", \"item\": 2}'
elif user_input == '11':
message = '{\"method\": \"findoffer\", \"item\": 2}'
elif user_input == '12':
message = '{\"method\": \"sendaccept\", \"token\": \"1\", \"offer_token\": 1}'
elif user_input == '13':
message = '{\"method\": \"accept\", \"offer_token\": 1}'
elif user_input == '14':
message = '{\"method\": \"fetch\", \"token\": \"1\", \"offer_token\": 1}'
elif user_input == '15':
message = '{\"method\": \"canceloffer\", \"token\": \"1\", \"offer_token\": 1}'
elif user_input == '16':
message = '';
try :
#Set the whole string
sock.sendall(bytes(message, 'UTF-8'))
except socket.error:
#Send failed
print ('Send failed')
sys.exit()
print ('Message send successfully')
print (message)
#Now receive data
reply = sock.recv(4096)
print (reply.decode('UTF-8'))
\ No newline at end of file
src/client/drawable/chara.png

4.08 KB | W: | H:

src/client/drawable/chara.png

17.2 KB | W: | H:

src/client/drawable/chara.png
src/client/drawable/chara.png
src/client/drawable/chara.png
src/client/drawable/chara.png
  • 2-up
  • Swipe
  • Onion skin
src/client/drawable/chara_shadow.png

6.54 KB | W: | H:

src/client/drawable/chara_shadow.png

17.1 KB | W: | H:

src/client/drawable/chara_shadow.png
src/client/drawable/chara_shadow.png
src/client/drawable/chara_shadow.png
src/client/drawable/chara_shadow.png
  • 2-up
  • Swipe
  • Onion skin
src/client/drawable/tilebkg.png

71.8 KB | W: | H:

src/client/drawable/tilebkg.png

19.6 KB | W: | H:

src/client/drawable/tilebkg.png
src/client/drawable/tilebkg.png
src/client/drawable/tilebkg.png
src/client/drawable/tilebkg.png
  • 2-up
  • Swipe
  • Onion skin
......@@ -8,20 +8,16 @@ import android.content.Context;
import android.content.Intent;
import android.content.IntentFilter;
import android.content.ServiceConnection;
import android.graphics.Bitmap;
import android.graphics.BitmapFactory;
import android.graphics.Typeface;
import android.os.IBinder;
import android.support.v7.app.ActionBarActivity;
import android.os.Bundle;
import android.view.Menu;
import android.view.MenuItem;
import android.view.View;
import android.view.ViewGroup;
import android.view.Window;
import android.widget.Button;
import android.widget.GridView;
import android.widget.ImageButton;
import android.widget.ImageView;
import android.widget.TextView;
import org.json.JSONException;
......@@ -59,6 +55,7 @@ public class FindActivity extends Activity implements View.OnClickListener {
if (item >= 0) {
Intent offerboxIntent = new Intent(FindActivity.this, OffersboxActivity.class);
offerboxIntent.putExtra("servermessage", message);
FindActivity.this.finish();
FindActivity.this.startActivity(offerboxIntent);
}
} else if (json.getString("status").equals("fail")) {
......@@ -78,6 +75,7 @@ public class FindActivity extends Activity implements View.OnClickListener {
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
requestWindowFeature(Window.FEATURE_NO_TITLE);
setContentView(R.layout.activity_find);
TextView title = (TextView) findViewById(R.id.findTitle);
......@@ -108,15 +106,15 @@ public class FindActivity extends Activity implements View.OnClickListener {
@Override
protected void onResume() {
super.onResume();
IntentFilter filter = new IntentFilter(SocketService.BROADCAST);
registerReceiver(receiver, filter);
super.onResume();
}
@Override
protected void onDestroy() {
unregisterReceiver(receiver);
super.onDestroy();
unregisterReceiver(receiver);
doUnbindService();
}
......@@ -194,7 +192,6 @@ public class FindActivity extends Activity implements View.OnClickListener {
}
mBoundService.sendMessage(json.toString());
}
this.pd = ProgressDialog.show(this, "Working...", "Doownloading data...", true, false);
break;
}
}
......
Supports Markdown
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment