Skip to content

Commit

Permalink
Initial commit
Browse files Browse the repository at this point in the history
  • Loading branch information
Mikhail Reshetnikov committed Aug 10, 2020
0 parents commit 0c7cf10
Show file tree
Hide file tree
Showing 7 changed files with 539 additions and 0 deletions.
2 changes: 2 additions & 0 deletions .gitattributes
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
# Auto detect text files and perform LF normalization
* text=auto
21 changes: 21 additions & 0 deletions LICENSE
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
MIT License

Copyright (c) 2020 Mikhail Reshetnikov

Permission is hereby granted, free of charge, to any person obtaining a copy
of this software and associated documentation files (the "Software"), to deal
in the Software without restriction, including without limitation the rights
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
copies of the Software, and to permit persons to whom the Software is
furnished to do so, subject to the following conditions:

The above copyright notice and this permission notice shall be included in all
copies or substantial portions of the Software.

THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
SOFTWARE.
39 changes: 39 additions & 0 deletions sketch_6_coin/Button.pde
Original file line number Diff line number Diff line change
@@ -0,0 +1,39 @@
class Button
{
float x, y, w, h;
String text;

Button(float x, float y, float w, float h, String text)
{
this.x = x;
this.y = y;
this.w = w;
this.h = h;
fill(117, 22, 199);
this.text = text;
rect(x, y, w, h);
fill(255, 255, 0);
textSize(width/30);
text(this.text, x+x/15, y+h/2+(width/30)/3);
}

float getX()
{
return this.x;
}

float getY()
{
return this.y;
}

float getHeight()
{
return this.h;
}

float getWidth()
{
return this.w;
}
}
78 changes: 78 additions & 0 deletions sketch_6_coin/Coin.pde
Original file line number Diff line number Diff line change
@@ -0,0 +1,78 @@
public class Coin
{
float x;
float y;
float diameter;
float xdif;
float ydif;
float colorR = 250;
float colorG = 250;
float colorB = 250;
PImage img = loadImage("coin.png");


Coin(float d)
{
diameter = d;
}

void place(float x, float y)
{
this.x = x;
this.y = y;
imageMode(CENTER);
tint(colorR, colorG, colorB);
image(img, x, y, d, d);
}

void setColor(float colorR, float colorG, float colorB)
{
this.colorR = colorR;
this.colorG = colorG;
this.colorB = colorB;
}

float getX()
{
return x;
}

float getY()
{
return y;
}

boolean isClicked()
{
xdif = x - mouseX;
ydif = y - mouseY;
float tdif = sqrt(xdif*xdif + ydif*ydif);
if (tdif <= diameter/2)
{
return true;
} else
{
return false;
}
}

float getXDif()
{
return xdif;
}

float getYDif()
{
return ydif;
}
boolean hasCollisionWith(Coin coin)
{
if (dist(this.x, this.y, coin.getX(), coin.getY()) <= d + 5)
{
return true;
} else
{
return false;
}
}
}
41 changes: 41 additions & 0 deletions sketch_6_coin/Librarian.pde
Original file line number Diff line number Diff line change
@@ -0,0 +1,41 @@
class Librarian
{
File table;
PrintWriter out;

Librarian(String fileName)
{
table = new File(fileName + ".csv");
try {
//проверяем, что если файл не существует то создаем его
if (!table.exists()) {
table.createNewFile();
}
//PrintWriter обеспечит возможности записи в файл
out = new PrintWriter(table.getAbsoluteFile());
try {
//Записываем текст в файл
out.print("time, coin_id, x, y, state, moves_local, moves_global\n");
}
finally {
//После чего мы должны закрыть файл
//Иначе файл не запишется
out.flush();
}
}
catch(IOException e) {
throw new RuntimeException(e);
}
}

void write(String text)
{
out.print(text + "\n");
out.flush();
}

void close()
{
out.close();
}
}
Binary file added sketch_6_coin/data/coin.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading

0 comments on commit 0c7cf10

Please sign in to comment.