Notice
Recent Posts
Recent Comments
Link
일 | 월 | 화 | 수 | 목 | 금 | 토 |
---|---|---|---|---|---|---|
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 |
Tags
- SQL
- 비트코인
- phaser
- jQuery
- 알고리즘
- autowired
- 암호화
- 도커
- tiles.xml
- HTML
- 웹게임
- 배포
- express
- node.js
- 웹소켓
- docker
- EC2
- Spring
- Cookie
- JavaScript
- websocket
- JSP
- AWS
- 블록체인
- RDS
- CSS
- Ajax
- Servlet
- model1
- PL/SQL
Archives
- Today
- Total
記錄
Rob2) Animation, tic tac toc 본문
Animation fade되면서 사진 교체
public void changeSimson(View view){
ImageView bart = (ImageView) findViewById(R.id.bart);
ImageView homer = (ImageView) findViewById(R.id.homer);
bart.animate().alpha(0f).setDuration(2000);
homer.animate().alpha(1f).setDuration(2000);
// 여기서 0f, 1f를 해준 이유는 정확히 float값으로 인식하도록 하기 위해서
// 그냥 숫자만 쓰면 가끔 어떤 경우에는 원하는 수치가 정확히 인식이 안된다고 함
// 그냥 습관화 할 것
}
Animation 아래로 내려감
ImageView bart = (ImageView) findViewById(R.id.bart);
bart.animate().translationYBy(1000f).setDuration(2000);
tic tac toc
package com.example.bit.tik;
import android.support.v7.app.AppCompatActivity;
import android.os.Bundle;
import android.view.View;
import android.widget.GridLayout;
import android.widget.ImageView;
import android.widget.LinearLayout;
import android.widget.TextView;
public class MainActivity extends AppCompatActivity {
int activeplayer = 0;
int[] playState = {2, 2, 2, 2, 2, 2, 2, 2, 2};
int[][] winningPositions = {{0, 1, 2}, {3, 4, 5}, {6, 7, 8}, {0, 3, 6},
{1, 4, 7}, {2, 5, 8}, {0, 4, 8}, {2, 4, 6}};
boolean gameIsActive = true;
public void dropIn(View view) {
ImageView counter = (ImageView) view;
System.out.println(counter.getTag().toString());
int tappedCounter = Integer.parseInt(counter.getTag().toString());
if ((playState[tappedCounter] == 2) && (gameIsActive == true)) {
counter.setTranslationY(-1000f);
playState[tappedCounter] = activeplayer;
if (activeplayer == 0) {
counter.setImageResource(R.drawable.yellow);
activeplayer = 1;
} else {
counter.setImageResource(R.drawable.red);
activeplayer = 0;
}
counter.animate().translationYBy(1000f).setDuration(300);
for (int[] a : winningPositions) {
if ((playState[a[0]] == playState[a[1]]) &&
(playState[a[1]] == playState[a[2]]) && playState[a[0]] != 2) {
System.out.println(playState[a[0]]);
gameIsActive = false;
String winner = "Red";
if (playState[a[0]] == 0) winner = "Yellow";
TextView tv = (TextView) findViewById(R.id.winnertext);
tv.setText(winner + " Win!");
LinearLayout li = (LinearLayout) findViewById(R.id.Linearlay);
li.setVisibility(View.VISIBLE);
} else {
boolean gameisgoingon = true;
for (int i = 0; i < playState.length; i++) {
if (playState[i] == 2) gameisgoingon = false;
}
if (gameisgoingon) {
TextView tv = (TextView) findViewById(R.id.winnertext);
tv.setText("It's a draw");
LinearLayout li = (LinearLayout) findViewById(R.id.Linearlay);
li.setVisibility(View.VISIBLE);
}
}
}
}
} // end-dromIn
public void playagain(View view) {
gameIsActive = true;
LinearLayout li = (LinearLayout) findViewById(R.id.Linearlay);
li.setVisibility(View.INVISIBLE);
activeplayer = 0;
for (int i = 0; i < playState.length; i++) {
playState[i] = 2;
}
GridLayout gri = (GridLayout) findViewById(R.id.gridlay);
for (int i = 0; i < gri.getChildCount(); i++) {
((ImageView) gri.getChildAt(i)).setImageResource(0);
}
}
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);
}
}
<?xml version="1.0" encoding="utf-8"?>
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:app="http://schemas.android.com/apk/res-auto"
xmlns:tools="http://schemas.android.com/tools"
android:layout_width="match_parent"
android:layout_height="match_parent"
tools:context="com.example.bit.tik.MainActivity">
<GridLayout
android:id="@+id/gridlay"
android:layout_width="wrap_content"
android:layout_height="360dp"
android:columnCount="3"
android:rowCount="3"
android:background="@drawable/board"
android:layout_centerVertical="true"
android:layout_centerHorizontal="true"
>
<ImageView
android:onClick="dropIn"
android:layout_width="90dp"
android:layout_height="90dp"
android:layout_marginTop="10dp"
android:layout_marginBottom="10dp"
android:layout_marginLeft="10dp"
android:layout_marginRight="10dp"
android:layout_row="0"
android:layout_column="0"
android:tag="0"
/>
<ImageView
android:onClick="dropIn"
android:layout_width="90dp"
android:layout_height="90dp"
android:layout_marginTop="10dp"
android:layout_marginLeft="40dp"
android:layout_row="0"
android:layout_column="1"
android:tag="1"
/>
<ImageView
android:onClick="dropIn"
android:layout_width="90dp"
android:layout_height="90dp"
android:layout_marginTop="10dp"
android:layout_marginLeft="40dp"
android:layout_row="0"
android:layout_column="2"
android:tag="2"
/>
<ImageView
android:onClick="dropIn"
android:layout_width="90dp"
android:layout_height="90dp"
android:layout_marginTop="25dp"
android:layout_marginLeft="10dp"
android:layout_row="1"
android:layout_column="0"
android:tag="3"
/>
<ImageView
android:layout_width="90dp"
android:layout_height="90dp"
android:layout_column="1"
android:layout_marginLeft="40dp"
android:layout_marginTop="25dp"
android:layout_row="1"
android:onClick="dropIn"
android:tag="4"/>
<ImageView
android:onClick="dropIn"
android:layout_width="90dp"
android:layout_height="90dp"
android:layout_marginTop="25dp"
android:layout_marginLeft="40dp"
android:layout_row="1"
android:layout_column="2"
android:tag="5"
/>
<ImageView
android:onClick="dropIn"
android:layout_width="90dp"
android:layout_height="90dp"
android:layout_marginTop="30dp"
android:layout_marginLeft="10dp"
android:layout_row="2"
android:layout_column="0"
android:tag="6"
/>
<ImageView
android:onClick="dropIn"
android:layout_width="90dp"
android:layout_height="90dp"
android:layout_marginTop="30dp"
android:layout_marginLeft="40dp"
android:layout_row="2"
android:layout_column="1"
android:tag="7"
/>
<ImageView
android:onClick="dropIn"
android:layout_width="90dp"
android:layout_height="90dp"
android:layout_marginTop="30dp"
android:layout_marginLeft="40dp"
android:layout_row="2"
android:layout_column="2"
android:tag="8"
/>
</GridLayout>
<LinearLayout
android:id="@+id/Linearlay"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_centerVertical="true"
android:layout_centerHorizontal="true"
android:background="@color/colorPrimary"
android:orientation="vertical"
android:visibility="invisible">
<TextView
android:id="@+id/winnertext"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="You Win!!"
android:textSize="30dp"
android:textAlignment="center"/>
<Button
android:id="@+id/playAgainButton"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:onClick="playagain"
android:text="play again"
android:textSize="20dp" />
</LinearLayout>
</RelativeLayout>
'Mobile > Android' 카테고리의 다른 글
Rob1) Introduction to Android Studio (0) | 2018.01.23 |
---|---|
프로그레스 다이얼로그 (0) | 2018.01.23 |
사용자 알림 효과 -다이얼로그(토스트, 알림창, 목록 등) (0) | 2018.01.20 |
사용자 알림 효과 -진동울리기, 알림음 (0) | 2018.01.13 |
레이아웃을 활용한 다양한 뷰 배치 - TableLayout, GridLayout (0) | 2018.01.13 |
Comments