Code Monkey home page Code Monkey logo

abdulmunafali8's Projects

coding-challenge icon coding-challenge

:loudspeaker: React coding challenge based on Apollo, GraphQL, Prisma and Node.js

docs icon docs

The open-source repo for docs.github.com

landscape icon landscape

} public class GameView extends View{ private Paint myPaint; private int speed=1; private int time = 0; private int score = 0; private int myCarPosition = 0; private ArrayList<HashMap<String, Object>> otherCars = new ArrayList<>(); int viewWidth = 0; int viewHeight = 0; public GameView(Context context){ super(context); myPaint = new Paint(); } @Override protected void onDraw(Canvas canvas) { viewWidth = this.getMeasuredWidth(); viewHeight = this.getMeasuredHeight(); if (time%700 < 10 + speed){ HashMap<String, Object> map = new HashMap<>(); map.put("lane", getRandom(0,2)); map.put("startTime", time); otherCars.add(map); } time = time + 10 + speed; int carWidth = viewWidth/5; int carHeight = carWidth+10; myPaint.setStyle(android.graphics.Paint.Style.FILL); android.graphics.drawable.Drawable d = getResources().getDrawable(R.drawable.car_blue, null); d.setBounds((myCarPosition*viewWidth/3) + viewWidth/15 + 25, viewHeight - 2 -carHeight, (myCarPosition*viewWidth/3) + (viewWidth/15) + carWidth-25, viewHeight-2); d.draw(canvas); myPaint.setColor(Color.GREEN); for (int i = 0; i<otherCars.size(); i++){ int carX = ((int)otherCars.get(i).get("lane")*viewWidth/3) + viewWidth/15; int carY = time - (int)otherCars.get(i).get("startTime"); android.graphics.drawable.Drawable d2 = getResources().getDrawable(R.drawable.car_yellow, null); d2.setBounds(carX+25, carY-carHeight, carX + carWidth-25, carY); d2.draw(canvas); if ((int)otherCars.get(i).get("lane") == myCarPosition){ if (carY > viewHeight - 2 - carHeight && carY < viewHeight - 2){ sp.edit().putString("hs", String.valueOf((int)highscore)).commit(); sp.edit().putString("score", String.valueOf(score)).commit(); finish(); }} if (carY > viewHeight + carHeight){ otherCars.remove(i); score++; speed = 1 + Math.abs(score/8); if (score > highscore){ highscore = score; } } } myPaint.setColor(Color.WHITE); myPaint.setTextSize(40); canvas.drawText("Score: " + String.valueOf(score), 80f, 80f, myPaint); canvas.drawText("Speed: " + String.valueOf(speed), 380f, 80f, myPaint); invalidate(); } @Override public boolean onTouchEvent(MotionEvent event) { switch(event.getAction()) { case MotionEvent.ACTION_DOWN: float x1 = event.getX(); if ( x1<viewWidth/2){ if (myCarPosition>0){ myCarPosition--; } } if ( x1>viewWidth/2){ if (myCarPosition<2){ myCarPosition++; } } invalidate(); break; case MotionEvent.ACTION_UP: break; } return true; }

mobile-checker icon mobile-checker

The Mobile Checker is a tool for Web developers who want to make their Web page or Web app work better on mobile devices.

repository icon repository

<?xml version="1.0" encoding="UTF-8"?> <module external.linked.project.id="aSerendipity" external.linked.project.path="$MODULE_DIR$" external.root.project.path="$MODULE_DIR$" external.system.id="GRADLE" external.system.module.group="" external.system.module.version="unspecified" type="JAVA_MODULE" version="4"> <component name="FacetManager"> <facet type="java-gradle" name="Java-Gradle"> <configuration> <option name="BUILD_FOLDER_PATH" value="$MODULE_DIR$/build" /> <option name="BUILDABLE" value="false" /> </configuration> </facet> </component> <component name="NewModuleRootManager" LANGUAGE_LEVEL="JDK_1_7" inherit-compiler-output="true"> <exclude-output /> <content url="file://$MODULE_DIR$"> <excludeFolder url="file://$MODULE_DIR$/.gradle" /> </content> <orderEntry type="jdk" jdkName="Android API 23 Platform" jdkType="Android SDK" /> <orderEntry type="sourceFolder" forTests="false" /> </component> </module

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.