Created
July 16, 2012 11:14
-
-
Save JavaDeveloper/3122179 to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| package com.android.filechooser.example; | |
| import android.app.Activity; | |
| import android.content.Intent; | |
| import android.os.Bundle; | |
| import android.util.Log; | |
| import com.iusenko.filechooser.FileChooserActivity; | |
| public class MainActivity extends Activity { | |
| private static final String TAG = MainActivity.class.getSimpleName(); | |
| @Override | |
| public void onCreate(Bundle savedInstanceState) { | |
| super.onCreate(savedInstanceState); | |
| setContentView(R.layout.activity_main); | |
| startActivityForResult(new Intent(this, FileChooserActivity.class), FileChooserActivity.PICK_UP_FILE_REQUEST); | |
| } | |
| @Override | |
| protected void onActivityResult(int requestCode, int resultCode, Intent data) { | |
| Log.d(TAG, "onActivityResult(" + requestCode + ", " + resultCode + ",...)"); | |
| if (FileChooserActivity.FILE_SELECTED_RESULT != resultCode) { | |
| return; | |
| } | |
| String path = data.getStringExtra(FileChooserActivity.SELECTED_FILE_KEY); | |
| Log.d(TAG, "Selected file: " + path); | |
| super.onActivityResult(requestCode, resultCode, data); | |
| } | |
| } |
<script src="https://gist.github.com/JavaDeveloper/3122179.js"></script>
<script src="https://gist.github.com/JavaDeveloper/3122179.js"></script>
<script src="https://gist.github.com/JavaDeveloper/3122179.js"></script>https://gist.github.com/JavaDeveloper/3122179.js
Clear the codes
// Simple Android Studio Snake Game (Java)
// MainActivity.java
package com.example.snakegame;
import android.graphics.Canvas;
import android.graphics.Color;
import android.graphics.Paint;
import android.os.Bundle;
import android.os.Handler;
import android.view.MotionEvent;
import android.view.SurfaceHolder;
import android.view.SurfaceView;
import androidx.appcompat.app.AppCompatActivity;
import java.util.ArrayList;
import java.util.Random;
public class MainActivity extends AppCompatActivity {
GameView gameView;
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
gameView = new GameView(this);
setContentView(gameView);
}
class GameView extends SurfaceView implements Runnable {
Thread thread;
boolean isPlaying = true;
int screenX = 20;
int screenY = 20;
int foodX, foodY;
ArrayList<int[]> snake = new ArrayList<>();
int direction = 1;
Paint paint = new Paint();
SurfaceHolder holder;
Handler handler = new Handler();
Runnable gameLoop = new Runnable() {
@Override
public void run() {
update();
draw();
handler.postDelayed(this, 200);
}
};
public GameView(MainActivity context) {
super(context);
holder = getHolder();
snake.add(new int[]{5, 5});
generateFood();
handler.post(gameLoop);
}
void generateFood() {
Random random = new Random();
foodX = random.nextInt(screenX);
foodY = random.nextInt(screenY);
}
void update() {
int[] head = snake.get(0);
int x = head[0];
int y = head[1];
switch (direction) {
case 0:
y--;
break;
case 1:
x++;
break;
case 2:
y++;
break;
case 3:
x--;
break;
}
if (x < 0) x = screenX - 1;
if (x >= screenX) x = 0;
if (y < 0) y = screenY - 1;
if (y >= screenY) y = 0;
snake.add(0, new int[]{x, y});
if (x == foodX && y == foodY) {
generateFood();
} else {
snake.remove(snake.size() - 1);
}
}
void draw() {
if (holder.getSurface().isValid()) {
Canvas canvas = holder.lockCanvas();
canvas.drawColor(Color.BLACK);
paint.setColor(Color.GREEN);
int blockSize = getWidth() / screenX;
for (int[] s : snake) {
canvas.drawRect(
s[0] * blockSize,
s[1] * blockSize,
(s[0] + 1) * blockSize,
(s[1] + 1) * blockSize,
paint
);
}
paint.setColor(Color.RED);
canvas.drawRect(
foodX * blockSize,
foodY * blockSize,
(foodX + 1) * blockSize,
(foodY + 1) * blockSize,
paint
);
holder.unlockCanvasAndPost(canvas);
}
}
@Override
public boolean onTouchEvent(MotionEvent event) {
if (event.getAction() == MotionEvent.ACTION_DOWN) {
float x = event.getX();
if (x < getWidth() / 2) {
direction--;
if (direction < 0) direction = 3;
} else {
direction++;
if (direction > 3) direction = 0;
}
}
return true;
}
@Override
public void run() {
}
}
}
My game code
Es code generate karo
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
import { useState } from 'react'
import { Button } from "/components/ui/button"
import { Card, CardContent, CardDescription, CardHeader, CardTitle } from "/components/ui/card"
import { Input } from "/components/ui/input"
import { Label } from "/components/ui/label"
import { Textarea } from "@/components/ui/textarea"
import { Select, SelectContent, SelectItem, SelectTrigger, SelectValue } from "@/components/ui/select"
import { Plus, Trash2, Upload, X, Eye } from 'lucide-react'
interface Coin {
id: string
code: string
name: string
country: string
year: number
continent: string
metal: string
value: number
observations: string
obverseImage?: string
reverseImage?: string
flagImage?: string
}
const continents = [
'Africa',
'Asia',
'Europe',
'North America',
'South America',
'Oceania',
'Antarctica'
]
const metals = [
'Gold',
'Silver',
'Copper',
'Bronze',
'Nickel',
'Aluminum',
'Zinc',
'Steel',
'Bi-metal',
'Other'
]
export default function CoinArchiver() {
const [coins, setCoins] = useState<Coin[]>([])
const [formData, setFormData] = useState({
code: '',
name: '',
country: '',
year: new Date().getFullYear(),
continent: '',
metal: '',
value: 0,
observations: ''
})
const [images, setImages] = useState({
obverse: '',
reverse: '',
flag: ''
})
const [selectedCoin, setSelectedCoin] = useState<Coin | null>(null)
const handleInputChange = (field: string, value: string | number) => {
setFormData(prev => ({ ...prev, [field]: value }))
}
const handleImageUpload = (type: 'obverse' | 'reverse' | 'flag', file: File) => {
const reader = new FileReader()
reader.onload = (e) => {
setImages(prev => ({ ...prev, [type]: e.target?.result as string }))
}
reader.readAsDataURL(file)
}
const addCoin = () => {
if (!formData.code || !formData.name || !formData.country || !formData.continent || !formData.metal) {
alert('Please fill in all required fields')
return
}
}
const removeCoin = (id: string) => {
setCoins(prev => prev.filter(coin => coin.id !== id))
if (selectedCoin?.id === id) {
setSelectedCoin(null)
}
}
const totalCoins = coins.length
const totalValue = coins.reduce((sum, coin) => sum + coin.value, 0)
return (
Coin Archiver
)
}
Share
Refresh