FiveChess via Processing

一共两个部分,分别是棋盘的控制现实和基本的接口

 1 import javax.swing.*;
 2
 3 int each=35;
 4 int side=35;
 5 int len=14*each;
 6
 7 void setup(){
 8   size(800,600);
 9   initChess();
10   chessTableMake();
11 }
12 void draw(){
13
14 }
15 void mousePressed(){
16   if(finished) return;
17   setChess(mouseX,mouseY);
18 }
19 void keyPressed(){
20   if(key==‘r‘||key==‘R‘){
21     setup();
22     loop();
23   }
24 }

init

 1 int chess[][]=new int[15][15];
 2 int flag=0;
 3 boolean finished=false;
 4 //flag=1 black chess flag=-1 white chess
 5 void initChess(){
 6   finished=false;
 7   for(int i=0;i<15;i++)
 8    for(int j=0;j<15;j++)
 9     chess[i][j]=0;
10   flag=1;
11 }
12 void chessTableMake(){
13   background(#5FFF4B);
14   //---------zi mu---------
15   pushStyle();
16   fill(#AF49F0);
17   textSize(20);
18   text(((flag==-1)?"White":"Black")+" Player Round",550,75);
19   popStyle();
20   pushMatrix();
21   translate(side,side);
22   fill(#AF49F0);
23   for(int i=0;i<15;i++){
24     line(0,each*i,len,each*i);
25     line(each*i,0,each*i,len);
26     text(i+1,-25,each*i);
27     text(char(i+‘A‘),each*i,-15);
28   }
29   strokeWeight(5);
30   point(each*3,each*3);
31   point(each*3,each*11);
32   point(each*11,each*3);
33   point(each*11,each*11);
34   point(each*7,each*7);
35   strokeWeight(1);
36   for(int y=0;y<15;y++)
37   for(int x=0;x<15;x++)
38   switch(chess[x][y]){
39     case -1:fill(255);ellipse(each*x,each*y,20,20);break;
40     case 1:fill(0);ellipse(each*x,each*y,20,20);break;
41   }
42   popMatrix();
43 }
44 void setChess(int x,int y){
45   if(x<side-5||x>side+len+5||y<side-5||y>side+len+5) return;
46   int tx=(x-side+5);
47   int ty=(y-side+5);
48   if(tx%each>=15||ty%each>=15)return;
49   tx/=each;ty/=each;
50   if(0!=chess[tx][ty])return;
51   chess[tx][ty]=flag;
52   flag*=-1;
53   chessTableMake();
54   testVictory(tx,ty);
55 }
56 void testVictory(int x,int y){
57   int tx=x,ty=y;
58   int count=0;
59   //na
60   tx=x;ty=y;
61   count=0;
62   for(int i=0;(tx+i>=0)&&(tx+i<=14)&&(ty+i>=0)&&(ty+i<=14)&&chess[tx+i][ty+i]==chess[x][y];i++,count++);
63   for(int i=0;(tx-i>=0)&&(tx-i<=14)&&(ty-i>=0)&&(ty-i<=14)&&chess[tx-i][ty-i]==chess[x][y];i++,count++);
64   if(count>5){victory(x,y);return;}
65   //pie
66   tx=x;ty=y;
67   count=0;
68   for(int i=0;(tx-i>=0)&&(tx-i<=14)&&(ty+i>=0)&&(ty+i<=14)&&chess[tx-i][ty+i]==chess[x][y];i++,count++);
69   for(int i=0;(tx+i>=0)&&(tx+i<=14)&&(ty-i>=0)&&(ty-i<=14)&&chess[tx+i][ty-i]==chess[x][y];i++,count++);
70   if(count>5){victory(x,y);return;}
71   //heng
72   tx=x;ty=y;
73   count=0;
74   for(int i=0;(tx-i>=0)&&(tx-i<=14)&&chess[tx-i][ty]==chess[x][y];i++,count++);
75   for(int i=0;(tx+i>=0)&&(tx+i<=14)&&chess[tx+i][ty]==chess[x][y];i++,count++);
76   if(count>5){victory(x,y);return;}
77   //shu
78   tx=x;ty=y;
79   count=0;
80   for(int i=0;(ty+i>=0)&&(ty+i<=14)&&chess[tx][ty+i]==chess[x][y];i++,count++);
81   for(int i=0;(ty-i>=0)&&(ty-i<=14)&&chess[tx][ty-i]==chess[x][y];i++,count++);
82   if(count>5){victory(x,y);return;}
83 }
84 void victory(int x,int y){
85   pushStyle();
86   fill(#5FFF4B);
87   noStroke();
88   rect(550,50,250,100);
89   String player=(chess[x][y]==-1)?"White":"Black";
90   JOptionPane.showMessageDialog(null, player+" player wins!\nPress R to restart", "Congratulation", JOptionPane.INFORMATION_MESSAGE);
91   finished=true;
92   fill(#AF49F0);
93   textSize(20);
94   text(player+" Player Wins",550,75);
95   popStyle();
96   noLoop();
97 }
时间: 2024-09-29 00:09:50

FiveChess via Processing的相关文章

Spring Cloud ZooKeeper集成Feign的坑2,服务调用了一次后第二次调用就变成了500,错误:Servlet.service() for servlet [dispatcherServlet] in context with path [] threw exception [Request processing failed; nested exception is com.n

错误如下: 2017-09-19 15:05:24.659 INFO 9986 --- [ main] s.c.a.AnnotationConfigApplicationContext : Refreshing org.spring[email protected]56528192: startup date [Tue Sep 19 15:05:24 CST 2017]; root of context hierarchy 2017-09-19 15:05:24.858 INFO 9986 --

Multithreading Batch Processing Framework

1 #!/usr/bin/env python 2 # -*- coding: utf-8 -*- 3 # Author: f0rsaken 4 5 import argparse 6 import importlib 7 import sys 8 import threadpool 9 import time 10 11 def main(): 12 parser = argparse.ArgumentParser(description="Multithreading Batch Proce

SNC processing failed_SAProuter_证书重新生成

文章为原创,转载请联系我,欢迎交流[email protected] 参照note 1178684 - No service connection: "SNC processing failed" 确认证书所在位置 Execute the following commands on your SAProuter machine: sapgenpse seclogin -l sapgenpse get_my_name -n validity 在cmd直接运行报错 利用everything

DirectX Video Processing AppWizard--CDxVideoGraphBase

http://www.ifp.illinois.edu/~chenyq/research/Utils/DxVideoAppWiz/DxVideoAppWiz.html 一个非常棒的DirectX Video Processing AppWizard,备忘.

转: rdlc报表An error occurred during local report processing错误

在开发环境的电脑上可生成报表,但是一到客户端就提示An error occurred during local report processing错误. 猜想是缺dll,补充上 Microsoft.ReportViewer.Common.dll Microsoft.ReportViewer.WinForms.dll 结果问题依旧,难道还缺? google后得知还缺一个 Microsoft.ReportViewer.ProcessingObjectModel.dll 这个可不好找,在C:\Wind

如何解决“Error detected while processing /root/.vimrc:”

使用crontab -e添加定时任务时,遇到如下错误"Error detected while processing /root/.vimrc:": [root@~]# crontab -e Error detected while processing /root/.vimrc: line 30: E518: Unknown option: fdm=syntax line 34: E518: Unknown option: autochdir 第一种方法: 直观地,根据提示,应该是不

解决方法:An error occurred on the server when processing the URL. Please contact the system administrator

在WINDOWS7或SERVER2008上安装了IIS7.5,调试ASP程序时出现以下错误: An error occurred on the server when processing the URL. Please contact the system administrator 解决方法如下:     设置方法一: 以管理员身份运行CMD,将目录定位到%windir%\system32\inetsrv\,然后执行appcmd set config -section:asp -script

【processing】小代码

今天无意间发现的processing 很有兴趣 实现很简洁 void setup(){ } void draw(){ background(255); if(mouseX < width/2 && mouseY > height/2) { fill(0); rect(0,height/2,width/2,height/2); } } 这个小小的代码可以实现 当鼠标位于画布左下方时显示一个黑色的框 -----------------------------------------

数据可视化之Processing【1】

说Processing之前得先说一下数据可视化 数据可视化--顾名思义,是关于数据之视觉表现形式的研究,将数据用其他方式表现出来,使之更直观, 更清晰,更容易分析和处理,常见的表达方式如word中使用广泛的直方图.树状图.折线图.饼状图等. 数据可视化技术的基本思想是将数据库中每一个数据项作为单个图元元素表示,大量的数据集构成数据 图像,同时将数据的各个属性值以多维数据的形式表示,可以从不同的维度观察数据,从而对数据进行 更深入的观察和分析. 我们知道,单纯的一连串数字摆在人们眼前很难分析其特点