Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- package com.android;
- import android.app.Activity;
- import android.os.Bundle;
- import android.view.View;
- import android.view.animation.Animation;
- import android.view.animation.AnimationUtils;
- import android.widget.Button;
- public class Game extends Activity {
- private Button buttons[]=new Button[9];
- private int data[]={1,3,1,4,3,2,4,2};
- private int pressed1,pressed2,press=0,index1,index2;
- /** Called when the activity is first created. */
- @Override
- public void onCreate(Bundle savedInstanceState) {
- super.onCreate(savedInstanceState);
- setContentView(R.layout.game);
- buttons[0] = (Button)findViewById(R.id.button1);
- buttons[1] = (Button)findViewById(R.id.button2);
- buttons[2] = (Button)findViewById(R.id.button3);
- buttons[3] = (Button)findViewById(R.id.button4);
- buttons[4] = (Button)findViewById(R.id.button5);
- buttons[5] = (Button)findViewById(R.id.button6);
- buttons[6] = (Button)findViewById(R.id.button7);
- buttons[7] = (Button)findViewById(R.id.button8);
- buttons[0].setOnClickListener(new View.OnClickListener() {
- public void onClick(View v) {
- pressMe(v);
- buttons[0].setText(Integer.toString(data[whatIsPressed(v)]));
- // TODO Auto-generated method stub
- }
- });
- buttons[1].setOnClickListener(new View.OnClickListener() {
- public void onClick(View v) {
- pressMe(v);
- buttons[1].setText(Integer.toString(data[whatIsPressed(v)]));
- // TODO Auto-generated method stub
- }
- });
- buttons[2].setOnClickListener(new View.OnClickListener() {
- public void onClick(View v) {
- pressMe(v);
- buttons[2].setText(Integer.toString(data[whatIsPressed(v)]));
- // TODO Auto-generated method stub
- }
- });
- buttons[3].setOnClickListener(new View.OnClickListener() {
- public void onClick(View v) {
- pressMe(v);
- buttons[3].setText(Integer.toString(data[whatIsPressed(v)]));
- // TODO Auto-generated method stub
- }
- });
- buttons[4].setOnClickListener(new View.OnClickListener() {
- public void onClick(View v) {
- pressMe(v);
- buttons[4].setText(Integer.toString(data[whatIsPressed(v)]));
- // TODO Auto-generated method stub
- }
- });
- buttons[5].setOnClickListener(new View.OnClickListener() {
- public void onClick(View v) {
- pressMe(v);
- buttons[5].setText(Integer.toString(data[whatIsPressed(v)]));
- // TODO Auto-generated method stub
- }
- });
- buttons[6].setOnClickListener(new View.OnClickListener() {
- public void onClick(View v) {
- pressMe(v);
- buttons[6].setText(Integer.toString(data[whatIsPressed(v)]));
- // TODO Auto-generated method stub
- }
- });
- buttons[7].setOnClickListener(new View.OnClickListener() {
- public void onClick(View v) {
- pressMe(v);
- buttons[7].setText(Integer.toString(data[whatIsPressed(v)]));
- // TODO Auto-generated method stub
- }
- });
- }
- private void compareNumbers (){
- Animation fadeAnim = AnimationUtils.loadAnimation(this, R.anim.animation);
- if(pressed1 == pressed2){
- buttons[index1].startAnimation(fadeAnim);
- buttons[index2].startAnimation(fadeAnim);
- buttons[index1].setVisibility(View.INVISIBLE);
- buttons[index2].setVisibility(View.INVISIBLE);
- }
- }
- private void pressMe(View v){
- if(press == 0){
- index1 = whatIsPressed(v);
- pressed1 = data[index1];
- press = 1;
- clearAll();
- }
- else if (press ==1){
- index2 = whatIsPressed(v);
- pressed2 = data[index2];
- compareNumbers();
- press = 0;
- }
- }
- private int whatIsPressed(View v) {
- int index = 0;
- for(int i=0; i<buttons.length;i++){
- if(buttons[i].getId()==((Button)v).getId()){
- index =i;
- break;
- }
- }
- return index;
- }
- private void clearAll(){
- for(int x=0;x<buttons.length-1;x++){
- buttons[x].setText("");
- }
- }
- }
- package com.android;
- import android.app.Activity;
- import android.content.Intent;
- import android.os.Bundle;
- import android.view.View;
- import android.view.View.OnClickListener;
- import android.widget.Button;
- public class Menu extends Activity {
- private Button Play;
- private Button Highscore;
- @Override
- public void onCreate(Bundle savedInstanceState) {
- super.onCreate(savedInstanceState);
- setContentView(R.layout.Menu);
- Play = (Button)findViewById(R.id.Play);
- Highscore = (Button)findViewById(R.id.Highscore);
- Play.setOnClickListener(new OnClickListener(){
- public void onClick(View view){
- Intent i = new Intent(getApplicationContext(), Game.class);
- startActivity(i);}
- });
- Highscore.setOnClickListener(new OnClickListener(){
- public void onClick(View view){
- Intent i = new Intent(getApplicationContext(), Highscore.class);
- startActivity(i);}
- });
- }
- }
- package com.android;
- public class PeopleUsers {
- private String username,password;
- public PeopleUsers(){
- }
- public String getUsername() {
- return username;
- }
- public void setUsername(String username) {
- this.username = username;
- }
- public String getPassword() {
- return password;
- }
- public void setPassword(String password) {
- this.password = password;
- }
- public PeopleUsers(String username, String password){
- this.username = username;
- this.password = password;
- }
- }
- package com.android;
- import android.app.Activity;
- import android.content.Intent;
- import android.os.Bundle;
- import android.view.View.OnClickListener;
- import android.widget.Button;
- import android.widget.EditText;
- import android.view.View;
- public class Registration extends Activity {
- /** Called when the activity is first created. */
- private EditText Username;
- private EditText Password;
- private EditText Name;
- private Button Registration;
- @Override
- public void onCreate(Bundle savedInstanceState) {
- super.onCreate(savedInstanceState);
- setContentView(R.layout.registration);
- Username = (EditText)findViewById(R.id.Username);
- Password = (EditText)findViewById(R.id.Password);
- Name = (EditText)findViewById(R.id.Name);
- Registration = (Button)findViewById(R.id.Registration);
- Registration.setOnClickListener(new OnClickListener(){
- public void onClick(View view){
- Intent i = new Intent(getApplicationContext(), Activities.class);
- startActivity(i);}
- });
- }}
- package com.android;
- import android.app.Activity;
- import android.content.Intent;
- import android.os.Bundle;
- import android.view.View.OnClickListener;
- import android.widget.Button;
- import android.widget.EditText;
- import android.view.View;
- public class Activities extends Activity {
- /** Called when the activity is first created. */
- private EditText Username;
- private EditText Password;
- private Button Login;
- private Button Register;
- @Override
- public void onCreate(Bundle savedInstanceState) {
- super.onCreate(savedInstanceState);
- setContentView(R.layout.main);
- Username = (EditText)findViewById(R.id.Uname);
- Password = (EditText)findViewById(R.id.Pwrd);
- Login = (Button)findViewById(R.id.Login);
- Register = (Button)findViewById(R.id.Register);
- Login.setOnClickListener(new OnClickListener(){
- public void onClick(View view){
- Intent i = new Intent(getApplicationContext(), Main_menu.class);
- startActivity(i);}
- });
- Register.setOnClickListener(new OnClickListener(){
- public void onClick(View view){
- Intent i = new Intent(getApplicationContext(), Register.class);
- startActivity(i);}
- });
- }
- }
- package com.android;
- import android.content.ContentValues;
- import android.content.Context;
- import android.database.Cursor;
- import android.database.sqlite.SQLiteDatabase;
- import android.database.sqlite.SQLiteDatabase.CursorFactory;
- import android.database.sqlite.SQLiteOpenHelper;
- public class DBHandler extends SQLiteOpenHelper{
- private static String database_name="Users";
- private static int version =1;
- public DBHandler(Context context, String name, CursorFactory factory,
- int version) {
- super(context, name, factory, version);
- // TODO Auto-generated constructor stub
- }
- public DBHandler(Context context){
- super(context,database_name,null,version);
- }
- @Override
- public void onCreate(SQLiteDatabase db) {
- // TODO Auto-generated method stub
- String sql="create table user(username varchar(15), password varchar(15), primary key(username))";
- db.execSQL(sql);
- }
- @Override
- public void onUpgrade(SQLiteDatabase db, int arg1, int arg2) {
- // TODO Auto-generated method stub
- db.execSQL("drop table if exist user");
- this.onCreate(db);
- }
- public void add(PeopleUsers us){
- SQLiteDatabase db = this.getWritableDatabase();
- ContentValues values = new ContentValues();
- values.put("username", us.getUsername());
- values.put("password",us.getPassword());
- db.insert("user", null, values);
- db.close();
- }
- public PeopleUsers search(String uname){
- PeopleUsers u=null;
- String where = "username ='"+uname+"'";
- SQLiteDatabase db = this.getReadableDatabase();
- Cursor cursor =db.query("user", null, where, null, null, null, null);
- if(cursor.moveToNext()){
- u = new PeopleUsers();
- u.setUsername(cursor.getString(0));
- u.setPassword(cursor.getString(1));
- }
- db.close();
- return u;
- }
- public void PeopleUsers(PeopleUsers s){
- SQLiteDatabase db = this.getWritableDatabase();
- String where = "username ='"+s.getUsername()+"'";
- ContentValues values = new ContentValues();
- values.put("username", s.getUsername());
- values.put("password",s.getPassword());
- db.update("user", values, where, null);
- db.close();
- }
- public void delete(String user){
- SQLiteDatabase db = this.getWritableDatabase();
- String where = "username ='"+user+"'";
- db.delete("user", where, null);
- db.close();
- }
- ;
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement