Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- package edu.upenn.cis350.hwk2;
- import android.content.Intent;
- import android.os.Bundle;
- import android.support.v7.app.AppCompatActivity;
- public class GameActivity extends AppCompatActivity{
- public String difficulty;
- @Override
- protected void onCreate(Bundle savedInstanceState) {
- super.onCreate(savedInstanceState);
- setContentView(R.layout.activity_game);
- difficulty = getIntent().getStringExtra("DIFFICULTY");
- GameView.setup(difficulty);
- }
- }
- package edu.upenn.cis350.hwk2;
- import android.content.Context;
- import android.graphics.Canvas;
- import android.graphics.Color;
- import android.graphics.Paint;
- import android.util.AttributeSet;
- import android.util.Log;
- import android.view.MotionEvent;
- import android.view.View;
- public class GameView extends View {
- //instance variables that hold the first tap
- private static String difficulty;
- private static int matchesRemaining;
- private String[] cards = {"Ace", "Two", "Three", "Four", "Five", "Six", "Seven", "Eight", "Nine", "Ten", "Jack", "Queen", "King"};
- private String[] suits = {"Hearts", "Clubs", "Diamonds", "Spades"};
- private static boolean[][] easyArray;
- private static boolean[][] mediumArray;
- private static boolean[][] hardArray;
- private static int moves;
- private static int totalMatches;
- public GameView(Context c) {
- super(c);
- }
- public GameView(Context c, AttributeSet a) {
- super(c, a);
- }
- public static void setup(String diff) {
- difficulty = diff;
- if (difficulty.equals("Easy")) {
- matchesRemaining = 3;
- }
- else if (difficulty.equals("Medium")) {
- matchesRemaining = 6;
- }
- else {
- matchesRemaining = 12;
- }
- reset();
- }
- public static void reset() {
- easyArray = new boolean[2][3];
- mediumArray = new boolean[2][3];
- hardArray = new boolean[2][3];
- moves = 0;
- }
- public void onDraw(Canvas canvas) {
- if(difficulty.equals("Easy")) {
- Paint s = new Paint();
- s.setColor(Color.BLACK);
- for(int i = 0; i < 2; i++) {
- for (int j = 0; j < 3; j++) {
- if(easyArray[i][j]) {
- }
- }
- }
- canvas.drawRect(100, 150, 400, 450, s);
- canvas.drawRect(100, 500, 400, 800, s);
- canvas.drawRect(700, 150, 1000, 450, s);
- canvas.drawRect(700, 500, 1000, 800, s);
- canvas.drawRect(1300, 150, 1600, 450, s);
- canvas.drawRect(1300, 500, 1600, 800, s);
- }
- else if (difficulty.equals("Medium")) {
- Paint s = new Paint();
- s.setColor(Color.BLACK);
- s.setStrokeWidth(20);
- canvas.drawRect(200, 200, 200, 200, s);
- }
- else {
- Paint s = new Paint();
- s.setColor(Color.BLACK);
- s.setStrokeWidth(20);
- canvas.drawRect(200, 200, 200, 200, s);
- }
- Paint p = new Paint();
- p.setColor(Color.BLACK);
- p.setTextSize(42);
- canvas.drawText("Moves: " + moves, 30, 70, p);
- canvas.drawText("Matches Remaining: " + matchesRemaining, 400, 70, p);
- canvas.drawText("Difficulty: " + difficulty, 1400, 70, p);
- //initialize to all false
- //takes in the array and draws according to that
- //invalidate();
- }
- public boolean onTouchEvent(MotionEvent e) {
- //determines if cards should be face up or face down
- int x = Math.round(e.getX());
- int y = Math.round(e.getY());
- return false;
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement