JSP Redirect 방법

Redirect시 모든 정보를 잃어버린다는 것을 명심!!

<%@ page language="java" contentType="text/html; charset=UTF-8" 
    pageEncoding="UTF-8"%> 
<!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd"> 
<html> 
<head> 
<meta http-equiv="Content-Type" content="text/html; charset=UTF-8"> 
<title>Insert title here</title> 
</head> 
<body> 
로드북 홈페이지로 이동 
<% 
response.sendRedirect("http://www.roadbook.co.kr"); 
%> 
</body> 
</html>

 

흔들리는 격전지

MainActivity.java

package kr.razberry.test; 
 
import android.content.Context; 
import android.support.v7.app.AppCompatActivity; 
import android.os.Bundle; 
import android.view.LayoutInflater; 
import android.view.View; 
import android.widget.AdapterView; 
import android.widget.EditText; 
import android.widget.LinearLayout; 
import android.widget.ListView; 
import android.widget.Toast; 
import java.util.Vector; 
 
 
public class MainActivity extends AppCompatActivity { 
    Vector cardVec = new Vector(); 
    LinearLayout listlayout = null; 
    EditText nameTxt; 
    EditText telTxt; 
    ListView cardlistView = null; 
    MyAdapter adapter; 
    Friend clickedFriend = null; 
    @Override 
    protected void onCreate(Bundle savedInstanceState) { 
        super.onCreate(savedInstanceState); 
        setContentView(R.layout.activity_main); 
        listlayout = (LinearLayout)findViewById(R.id.listlayout); 
        nameTxt = (EditText) findViewById(R.id.nameTxt); 
        telTxt = (EditText) findViewById(R.id.telTxt); 
        cardlistView = (ListView)findViewById(R.id.listview); 
        adapter = new MyAdapter(MainActivity.this, cardVec); 
 
        cardlistView.setAdapter(adapter); 
        cardlistView.setOnItemClickListener(new AdapterView.OnItemClickListener() { 
            @Override 
            public void onItemClick(AdapterView <?> parent, View v, int position, long id) { 
                Toast.makeText(getBaseContext(),""+position,Toast.LENGTH_LONG).show(); 
                nameTxt.setText(((EditText)(v.findViewById(R.id.nameTxt))).getText().toString()); 
                telTxt.setText(((EditText)(v.findViewById(R.id.telTxt))).getText().toString()); 
                clickedFriend = (Friend)v.getTag(); 
            } 
        }); 
    } 
 
    public void makeToast(View V) { 
        Toast.makeText(getBaseContext(),"btnClicked" ,Toast.LENGTH_SHORT).show(); 
    } 
    public void insertCard(View v) { 
        String name = nameTxt.getText().toString(); 
        String tel = telTxt.getText().toString(); 
        Friend friend = new Friend(name,tel); 
        cardVec.add(friend); 
 
        LayoutInflater inflater = (LayoutInflater) this.getSystemService(Context.LAYOUT_INFLATER_SERVICE); 
        LinearLayout cardLayout = (LinearLayout)inflater.inflate(R.layout.cardlayout, null, false); 
        ((EditText)cardLayout.findViewById(R.id.nameTxt)).setText(name); 
        ((EditText)cardLayout.findViewById(R.id.telTxt)).setText(tel); 
        listlayout.removeAllViews(); 
        listlayout.addView(cardLayout); 
        adapter.setData(cardVec); 
        adapter.notifyDataSetChanged(); 
    } 
    public void updateCard(View v) { 
        String name = nameTxt.getText().toString(); 
        String tel = telTxt.getText().toString(); 
        clickedFriend.setName(name); 
        clickedFriend.setTel(tel); 
        adapter.setData(cardVec); 
        adapter.notifyDataSetChanged(); 
    } 
 
    public void deleteCard(View v) { 
        cardVec.remove(clickedFriend); 
        adapter.setData(cardVec); 
        adapter.notifyDataSetChanged(); 
    } 
    public void searchCard(View v) { 
        Vector searchVec = new Vector(); 
 
        for(Object obj : cardVec) { 
            if(((Friend)obj).contains(nameTxt.getText().toString(), telTxt.getText().toString())){ 
                searchVec.add(obj); 
                Toast.makeText(getApplicationContext(),((Friend)obj).getName(), Toast.LENGTH_LONG).show(); 
            } 
        } 
 
        adapter.setData(searchVec); 
        adapter.notifyDataSetChanged(); 
    } 
}

Friend.java

package kr.razberry.test; 
 
/** 
 * Created by taki on 2016-10-23. 
 */ 
 
public class Friend { 
    private String name = ""; 
    private String tel = ""; 
 
    public Friend(String name, String tel) { 
        this.name = name; 
        this.tel = tel; 
    } 
 
    public String getTel() { 
        return tel; 
    } 
 
    public void setTel(String tel) { 
        this.tel = tel; 
    } 
 
    public String getName() { 
        return name; 
    } 
 
    public void setName(String name) { 
        this.name = name; 
    } 
 
    public boolean contains(String name, String tel) { 
        if (!(name != null && name.length() > 0 && !this.name.contains(name))) 
            if (!(tel != null && tel.length() > 0 && !this.tel.contains(tel))) return true; 
        return false; 
    } 
 
    @Override 
    public String toString() { 
        return super.toString(); 
    } 
} 

MyAdapter.java

package kr.razberry.test; 
 
import android.app.Activity; 
import android.view.LayoutInflater; 
import android.view.View; 
import android.view.ViewGroup; 
import android.widget.ArrayAdapter; 
import android.widget.EditText; 
import java.util.Vector; 
 
public class MyAdapter extends ArrayAdapter<Friend> { 
  private final Activity context; 
  private Vector vec; 
  public MyAdapter(Activity context, Vector vec) { 
    super(context, R.layout.cardlayout, vec); 
 
    this.context = context; 
    this.vec = vec; 
  } 
 
  public void setData(Vector vec) { 
    this.vec = vec; 
  } 
 
  @Override 
  public int getCount() { 
    return vec.size(); 
  } 
 
  @Override 
  public View getView(int position, View convertView, ViewGroup parent) { 
    LayoutInflater inflater = context.getLayoutInflater(); 
    View cardView = inflater.inflate(R.layout.cardlayout, null, false); 
    Friend friend = (Friend)vec.get(position); 
    ((EditText)cardView.findViewById(R.id.nameTxt)).setText(friend.getName()); 
    ((EditText)cardView.findViewById(R.id.telTxt)).setText(friend.getTel()); 
    cardView.setTag(friend); 
    return cardView; 
  } 
}

다운로드

오브젝트 X축 옮기기

using UnityEngine; 
using System.Collections; 
 
public class csShoot : MonoBehaviour { 
    public int speed = 5; 
    public int rotSpeed = 120; 
    public int power = 500; 
    public GameObject ball; 
  // Use this for initialization 
  void Start () { 
        //ball.GetComponent<Rigidbody>().AddForce(new Vector3(0,1,1)*power); 
        //오브젝트 발사 
  } 
   
  // Update is called once per frame 
  void Update () { 
        float amtMove = speed * Time.deltaTime; //매 프레임의 이동 거리 
        float amtRot = rotSpeed * Time.deltaTime; 
        float ver = Input.GetAxis("Vertical"); // 앞뒤 이동 방향 
                                                
        //float hor = Input.GetAxis("Horizontal");                                     
        //좌우 이동 방향  
 
        float ang = Input.GetAxis("Horizontal"); 
        transform.Translate(Vector3.forward * ver * amtMove); 
        //전후진 
         
        //transform.Translate(Vector3.right * hor * amtMove); 
        //좌우 이동 
 
        transform.Rotate(Vector3.up * ang * amtRot); 
        //도리도리 
        if (Input.GetButtonDown("Fire1")) 
        { 
            ball.GetComponent<Rigidbody>().AddForce(Vector3.forward * power);  
            //오브젝트 발사 
        } 
  } 
} 

 

무기마다 최대 탄약 다르게

using UnityEngine; 
using System.Collections; 
using UnityEngine.UI; 
 
public class GameManager : MonoBehaviour { 
    //manager 
    public static GameManager manager; 
 
    //player 
    public GameObject player; 
 
    //texts 
    public GameObject scoreText; 
    public GameObject welcome; 
    public GameObject ammotext; 
 
    //bullet 
    public GameObject bullet; 
 
    //ammo 
    public int bullets = 0; 
    public int maxbullets = 0; 
 
    //gun damage 
    public int damage = 0; 
 
    //score 
    public int score; 
 
    //can shoot or not 
    //public bool canShoot = false; 
 
    //is started? or Over? 
    public bool isStart = false; 
    public bool isOver = false; 
 
    //max score 
    public const int MAXSCORE = 100; 
 
    // Before Start()... 
    void OnEnable() 
    { 
        manager = this; 
    } 
 
  // Use this for initialization 
  void Start () { 
        bullets = 0; 
        maxbullets = 0; 
  } 
   
  // Update is called once per frame 
  void Update () { 
      if(!welcome.GetComponent<Text>().enabled && !isStart) 
        { 
            //welcome.GetComponent<Text>().text = "You Win!"; //미리 텍스트 변경 
            //Debug.Log("a"); 
            isStart = true; 
            scoreText.SetActive(true); //스코어 텍스트 켜기 
            ammotext.GetComponent<Text>().enabled = true; 
             
        } 
 
        if(score >= MAXSCORE && !isOver) 
        { 
            welcome.GetComponent<Text>().enabled = true; 
            scoreText.SetActive(false); 
            isOver = true; 
        } 
 
        if(Input.GetButtonDown("Fire1") && bullets > 0) 
        { 
            Debug.Log("Ammo " + bullets + " Max " + maxbullets); 
            Debug.Log("남은 총알" + (--bullets)); 
            ammotext.GetComponent<Text>().text = "ammo:" + bullets; 
            GameObject ins = Instantiate(bullet, player.transform.position, player.transform.rotation) as GameObject; 
            ins.GetComponent<Rigidbody>().AddForce(player.transform.forward * 5000f); 
        } 
  } 
 
} 

 

유니티 충돌시 폭파 펑

using UnityEngine; 
using System.Collections; 
 
public class TongEvent : MonoBehaviour { 
    /* 
        이전 스크립트 재사용 
                           */ 
 
    public GameObject Explosion; 
  // Use this for initialization 
  void Start () { 
   
  } 
   
  // Update is called once per frame 
  void Update () { 
   
  } 
 
    void OnCollisionEnter(Collision target) 
    { 
        if(target.gameObject.tag == "Bullet") //총알과 충돌시 
        { 
            //ShootZone.score += 10; //점수증가 
 
            Instantiate(Explosion, transform.position, transform.rotation); 
            //폭발!! 
            Destroy(gameObject, 0.5f); //우주선 삭제 
        } 
    } 
} 

 

특정 위치에 물체 생성 후 발사

발사 = 리지드바디에 addforce

using UnityEngine; 
using System.Collections; 
 
public class Shoot : MonoBehaviour { 
    /* 
        이전 스크립트 재사용 
                           */ 
    public GameObject bullet; 
    public float power = 1500f; 
 
  // Use this for initialization 
  void Start () { 
   
  } 
   
  // Update is called once per frame 
  void Update () { 
      if(Input.GetButtonDown("Fire1") && Controller.gun != -1) 
        { 
            GameObject ins = Instantiate(bullet, transform.position, transform.rotation) as GameObject; 
            ins.GetComponent<Rigidbody>().AddForce(transform.forward * power); 
        } 
  } 
} 

 

유니티 특정 시간 후 자기 자신 삭제

using UnityEngine; 
using System.Collections; 
 
public class BulletDestroy : MonoBehaviour { 
 
  // Use this for initialization 
  void Start () { 
   
  } 
 
    float time = 0.0f; 
   
  // Update is called once per frame 
  void Update () { 
        time += Time.deltaTime; 
 
        if(time >= 1) 
        { 
            Destroy(gameObject); 
            ++GameController.controller.removedGrenades; 
            Debug.Log("Destroyed"); 
        } 
  } 
} 

 

유니티 게임 컨트롤러

게임의 핵심부분을 담당함

using UnityEngine; 
using System.Collections; 
using UnityEngine.UI; 
 
public class GameController : MonoBehaviour { 
    public static GameController controller; //controller 
 
    public int grenades = 0; //current grenades 
    public GameObject grenade; 
    public int removedGrenades = 0; 
 
    public int remainCoins = 4; //remain coins 
    public GameObject remainCoinText; 
 
    public GameObject middle; //middle texts and images 
    public GameObject youwin; 
    public GameObject gameover; 
 
    public GameObject player; //player 
 
    public GameObject crossHair; //crosshair image 
 
    public GameObject target; //target 
 
    public bool canShoot = false; //determine able to shoot 
 
    public bool isOver = false; 
 
    public GameObject Explosion; 
 
    void OnEnable() 
    { 
        controller = this; 
    } 
  // Use this for initialization 
  void Start () { 
   
  } 
 
    // Update is called once per frame 
    private float time; 
    private int timeflag = 1; 
    private Vector3 v3; 
    void Update () { 
      if(canShoot && !isOver) 
        { 
            v3 = target.transform.position; 
            time += Time.deltaTime; 
            if(time >= 3) 
            { 
                timeflag *= -1; 
                time = 0; 
            } 
            v3.x +=  Time.deltaTime*timeflag; 
            target.transform.position = v3; 
            //target.GetComponent<Rigidbody>().AddForce(new Vector3(timeflag, 0)); 
            //bool debug = true; 
            if (Input.GetButtonDown("Fire1") && grenades > 0) 
            { 
                GameObject ins = Instantiate(grenade, player.transform.position, player.transform.rotation) as GameObject; 
                ins.GetComponent<Rigidbody>().AddForce(player.transform.forward * 5000f); 
                remainCoinText.GetComponent<Text>().text = "보유 수류탄: " + (--grenades) + "개"; 
            } 
        } 
        if (remainCoins == 0 && !isOver && grenades == 0 && removedGrenades >= 4) 
        { 
            gameOver(false); 
        } 
    } 
 
    public int getCoin() 
    { 
        remainCoinText.GetComponent<Text>().text = "보유 수류탄: " + (++grenades) + "개"; 
        return --remainCoins; 
    } 
 
    public void changeShootStatus(bool flag) 
    { 
        canShoot = flag; 
        crossHair.GetComponent<Image>().enabled = canShoot; 
    } 
 
    //true : youwin 
    //false : gameover 
    public void gameOver(bool flag) 
    { 
        if(flag) 
        { 
            youwin.SetActive(true); 
            isOver = true; 
        } 
        else 
        { 
            gameover.SetActive(true); 
            isOver = true; 
        } 
    } 
} 

 

유니티 아이템관련 스크립트

using UnityEngine; 
using System.Collections; 
using UnityEngine.UI; 
 
public class GunHandler : MonoBehaviour { 
    public float rotationSpeed = 100.0f; 
 
    void Start() 
    { 
         
    } 
 
  // Update is called once per frame 
  void Update () { 
        transform.Rotate(new Vector3(0, rotationSpeed * Time.deltaTime, 0)); 
  } 
 
    void OnTriggerEnter(Collider target) 
    { 
        if (target.tag == "Player") 
        { 
            GameController.controller.middle.GetComponent<Text>().enabled = true; 
            GameController.controller.middle.GetComponent<Text>().text = "수류탄 구매됨. 코인 " + GameController.controller.getCoin() + "개 남음"; 
            Destroy(gameObject); 
        } 
    } 
}