简易版五子棋,我也来发一个。
aide吧
全部回复
仅看楼主
level 1
kyo_008 楼主
仅供参考,小于1920X1080分辨率会显示不全。XML代码请看楼下。
2018年12月15日 07点12分 1
level 1
kyo_008 楼主
<?xml version="1.0" encoding="utf-8"?>
<LinearLayout
xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:gravity="center_horizontal"
android:orientation="vertical"
android:background="#999999">
<TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="当前"
android:layout_marginTop="30dp"/>
<TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:textAppearance="?android:attr/textAppearanceLarge"
android:id="@+id/mainTextView1"/>
<LinearLayout
android:layout_height="1040px"
android:layout_width="1040px"
android:orientation="vertical"
android:id="@+id/mainLinearLayout1"/>
<Button
android:layout_height="wrap_content"
android:layout_width="wrap_content"
android:text="悔棋"
android:onClick="oc"/>
<Button
android:layout_height="wrap_content"
android:layout_width="wrap_content"
android:text="开始"
android:onClick="od"/>
</LinearLayout>
2018年12月15日 07点12分 2
level 1
kyo_008 楼主
java代码请看楼下↓
2018年12月15日 07点12分 3
level 1
kyo_008 楼主
import android.app.*;
import android.os.*;
import android.widget.*;
import android.view.*;
import java.util.*;
import android.graphics.*;
import android.view.View.*;
import android.content.*;
public class MainActivity extends Activity
{
LinearLayout lv;
View vv;
int n=0;
boolean h;
int[][]ss;
TextView tv;
int x,y,o,p;
@Override
protected void onCreate(Bundle savedInstanceState)
{
super.onCreate(savedInstanceState);
setContentView(R.layout.main);
lv=(LinearLayout)findViewById(R.id.mainLinearLayout1);
tv=(TextView)findViewById(R.id.mainTextView1);
x=0;
y=0;
ss=new int[15][15];
vv=new Myview(this);
lv.addView(vv);
lv.setOnTouchListener(new Tou());
}
class Myview extends View
{
Paint p;
public Myview(Context con)
{
super(con);
p=new Paint();
p.setStrokeWidth(2);
}
@Override
public void draw(Canvas canvas)
{
canvas.drawColor(0xff999999);
p.setColor(0xff000000);
for(int i=0;i<15;i++)
canvas.drawLine(30,30+i*70,1010,30+i*70,p);
for(int i=0;i<15;i++)
canvas.drawLine(30+i*70,30,30+70*i,1010,p);
p.setColor(0xff000000);
for(int i=0;i<15;i++)
for(int ii=0;ii<15;ii++)
{
if(ss[i][ii]==1)
{
p.setColor(0xff000000);
canvas.drawCircle(70*ii+30,70*i+30,30,p);
}
if(ss[i][ii]==2)
{
p.setColor(0xffffffff);
canvas.drawCircle(70*ii+30,70*i+30,30,p);
}
}
if(n%2==0)
tv.setText("黑方");
else
tv.setText("白方");
}}
class Tou implements OnTouchListener
{
@Override
public boolean onTouch(View p1, MotionEvent p2)
{
if(p2.getAction()==p2.ACTION_UP)
{
x=(int)p2.getX();
y=(int)p2.getY();
if((x-30)%70<35)
x=x-(x-30)%70;
else
x=x+(70-(x-30)%70);
if((y-30)%70<35)
y=y-(y-30)%70;
else
y=y+(70-(y-30)%70);
if(ss[(y-30)/70][(x-30)/70]==0)
{
h=true;
o=(y-30)/70;
p=(x-30)/70;
if(n%2==0)
ss[(y-30)/70][(x-30)/70]=1;
else
ss[(y-30)/70][(x-30)/70]=2;
n++;
vv.postInvalidate();
}
}
return true;
}
}
public void od(View v)
{
n=2;
ss=new int[15][15];
vv.postInvalidate();
}
public void oc(View v)
{
if(h)
{
ss[o][p]=0;
n++;
vv.postInvalidate();
h=false;
}
}
}
2018年12月15日 07点12分 4
level 13
没有图吗
2018年12月15日 11点12分 5
level 12
[真棒]
2018年12月15日 13点12分 6
level 12
我给你补个图[滑稽]
2018年12月15日 13点12分 7
level 9
真牛逼🐮
2018年12月16日 07点12分 8
level 8
为什么我复制代码后编译会出现这种情况?
2018年12月16日 14点12分 9
应该是你把第一行的包名删掉了,补上你的包名就行。粘贴的时候不要把第一行删掉。
2018年12月16日 15点12分
@kyo_008 确实,可以了
2018年12月16日 15点12分
level 14
求大佬加个五子相连的胜负判断和五子棋的ai[滑稽]
2018年12月17日 04点12分 10

2018年12月17日 09点12分
鉴于凡是比吧主长得帅的发贴都有很大几率被删帖,我就不在这里发了。已经被删两次了。
2018年12月17日 13点12分
level 2
。。。。。
2020年03月11日 13点03分 14
1